PING  0.9
Statistical data handling and processing in production environment
macro_isblank

Check whether a macro variable is empty or not.

%let res=%macro_isblank(var, verb=no);

Arguments

var : name of a variable to evaluate the content of; verb : (option) see %error_handle arguments; default: no.

Returns

res : evaluated boolean condition, either true (1) when the variable is blank/not set (i.e. when var is for instance '', or "", or (), but also " ", or ' ', ...), or false (0) otherwise.

Examples

%let var = 0;
%let res=%macro_isblank(var);

returns res=0, while running:

%let var = ;
%let res=%macro_isblank(var);

returns res=1. Ibid for the following example:

%let parameter = ' ';
%let res=%macro_isblank(parameter);

which returns res=1.

Run macro %_example_macro_isblank for more examples.

Note

  1. When using the macro macro_isblank, keep in mind the following (arbitrarily chosen) outputs:
    • variables " ", ' ' and ( ) are considered as empty/blank variables, whatever the number of 'blanks' inside the string, e.g. " " is also considered as empty/blank;
    • on the contrary, single quotes (i.e., set to %str(%") and %str(') respectively) are considered as NON empty/blank variables.
  2. Let us further note that:
%let ans=%macro_isblank();

will return ans=1.

Note

In the reference below, the authors recommend the use of:

%macro isBlank(param);
%sysevalf(%superq(param)=,boolean)
%mend isBlank;

while they also evaluate:

%if &param eq %then ...
%if %bquote(&param)= %then ...
%if %nrbquote(&param)= %then ...
%if %superq(param)= %then ...
%if "&param" = "" %then ...
%if %length(&param) = 0 %then ...
%if %length(%qleft(%qtrim(&param))) = 0 %then ...

References

  1. Carpenter, A.L. (1997): "Resolving and using &&var&i macro variables".
  2. Carpenter, A.L. (2005): "Five ways to create macro variables: A short introduction to the macro language".
  3. Philp, P. (2008): "SAS MACRO: Beyond the basics".
  4. Chang et al.(2009): "Is this macro parameter blank?".
  5. Wilson, S.A. (2011): "The validator: A macro to validate parameters".
  6. Weston, K. (2011): "Ways of creating macro variables".

See also

%error_handle, SUPERQ.