I'm trying to make a simple macro that checks whether a specific macro variable is either missing or does not exist. Normally, this would require two statements: a %symexist
, and if it does exist, additional logic to detect whether it's a null value. The below code combines all of that into one.
%macro isnull(macvar);
%sysevalf(%superq(%superq(macvar)) NE %str(), boolean);
%mend isnull;
Problem
I cannot use %isNull()
in a %if
statement, because the returned value always seems to be a character. This behavior differs if it's in open code or within a macro itself.
What I've tried
I've narrowed it down to the macro not resolving as a numeric value. I've tried everything from enclosing it with %sysfunc(putn())
to %cmpres()
to %sysfunc(compress())
. If it's in open code, it is numeric. If it's in another macro, it's character. You can see it with this code:
/* Miss2 resolves incorrectly as character */
%macro check;
%let miss1=%sysevalf(%superq(asdf) =, boolean);
%let miss2=%isNull(asdf);
%put Miss1: %datatyp(&miss1);
%put Miss2: %datatyp(&miss2);
%mend;
%check;
/* Miss2 resolves correctly as numeric */
%let miss1=%sysevalf(%superq(asdf) =, boolean);
%let miss2=%isNull(asdf);
%put Miss1: %datatyp(&miss1);
%put Miss2: %datatyp(&miss2);
Want
I want to be able to use this in a %if
statement to check whether a macro both exists and is not blank simultaneously.
%macro foo;
%if(%isNull(sysuserid) = 1) %then %put sysuserid exists;
%if(%isNull(asdffdsa) = 0) %then %put asdffdsa does not exist;
%if(%isNull(sysuserid) > 0) %then %put this should resolve;
%if(%isNull(asdffdsa) > 0) %then %put this should not resolve;
%mend;
%foo;