Hi Everyone,
I've been spending a lot of time on this macro routine and could not figure out what is going on. In this link, Chung and King presented a macro, isBlank, to test if a macro's argument is blank. In this discussion, Ballardw illustrated a usage of isBlank. However, when I used isBlank in my test macro below, the IF condition is never true. Somehow the 1 returned by %isBlank looks like a 1 but is not really a 1. Would someone help to demystify this please. Thank you very much.
-Chin
%macro isBlank(param);
%sysevalf(%superq(param)=,boolean);
%mend isBlank;
%put %isBlank(); /* Returns 1. */
%put %isBlank(a); /* Returns 0. */
%macro test(arg);
%if %isBlank(&arg) = 1 %then %put Blank; /* This IF is never true. Is %isBlank(&arg) returning a numerical 1? */
%else %put Notblank; run;
%mend;
%test(); /* Returns: Notblank */
%test(a); /* Returns: Notblank ALSO. */
I can't test this right now, but to my eyes, your macro definition is incorrect. You have an extra semicolon on this line:
%sysevalf(%superq(param)=,boolean);
"Extra" here means that you have one, but there shouldn't be any.
The %isblank macro works on macro variables. If you feed it text or a null argument, I have no idea what it will do, but it wasn't designed for that.
So
%let a=XXX;
%put %isblank(&a); /* Should return a 1 */
%let a=;
%put %isblank(&a); /* Should return a 0 */
PaigeMiller, Thank you for your reply. While I was trying out your suggestion, Astounding replied another solution, which I quickly tested and confirmed that is where my problem is. Thank you for your help. -Chin
@PaigeMiller wrote:
The %isblank macro works on macro variables. If you feed it text or a null argument, I have no idea what it will do, but it wasn't designed for that.
So
%let a=XXX;
%put %isblank(&a); /* Should return a 1 */
%let a=;
%put %isblank(&a); /* Should return a 0 */
Correcting my reply
%let a=XXX;
%put %isblank(&a); /* Should return a 0 */
%let a=;
%put %isblank(&a); /* Should return a 1 */
I can't test this right now, but to my eyes, your macro definition is incorrect. You have an extra semicolon on this line:
%sysevalf(%superq(param)=,boolean);
"Extra" here means that you have one, but there shouldn't be any.
Are macro's always invoked without a ";" at the end?
No, ";" is never needed at the end of a macro invocation. As a result, if you add one, it adds ";" to the program at that point Much of the time an extra semicolon in the middle of a program doesn't hurt anything. But in this case, it would.
I will keep an eye on these ";". Your suggestion has really made my day. Thanks again.
Calling @data_null__
Hi Ksharp,
Are you suggesting that on the 2nd line, the added ";"
%macro isBlank(param) /store source;
%sysevalf(%superq(param)=,boolean);
%mend isBlank;
has the effect as
%macro isBlank(param) /store source;
@Data_null_
%mend isBlank;
calling @data_null__?
Thank you.
This macro is written by John King a.k.a @data_null__ .
I mentioned him here to let him notice this question .
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.