SAS Studio

Write and run SAS programs in your web browser
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chinli72
Obsidian | Level 7

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. */

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26

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 */

--
Paige Miller
chinli72
Obsidian | Level 7

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
Diamond | Level 26

@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 */

 

--
Paige Miller
Astounding
PROC Star

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.

chinli72
Obsidian | Level 7
Astounding, You are absolutely correct. By removing the ";" in isBlank macro, the code worked. Truly astounded. Thank you very much.
chinli72
Obsidian | Level 7

Are macro's always invoked without a ";" at the end?

Astounding
PROC Star

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.

chinli72
Obsidian | Level 7

I will keep an eye on these ";". Your suggestion has really made my day. Thanks again.

chinli72
Obsidian | Level 7

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.

Ksharp
Super User

This macro is written by John King a.k.a  @data_null__ .

I mentioned him here to let him notice this question .

chinli72
Obsidian | Level 7
Got it. Thank you.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 4157 views
  • 1 like
  • 4 in conversation