I am designing a generic macro to do update a table using a macro variable (say X) which is used as a column name. The problem I have is that there are ocassions where this variable X (which is used as a column name in the where clause) is null. Can someone help please
2 Answers
If &x is guaranteed to be defined but may be blank, then DWal's solution is the way to go. This is useful basically when the macro variable is a parameter, and will be defined every time the macro is run.
If it may not be defined at all, then you need to use %symexist() to check whether the macro variable is defined at all, possibly in addition to the %length check.
%macro test;
%if %symexist(X) %then %if %length(&x)>0 %then %do;
%put &=x;
%end;
%mend test;
%symdel x; *deletes x if it exists;
%test;
%let x=;
%test;
%let x=XValue;
%test;
I nest the %if to avoid an unintialized note.