Hi Team,
I am working on a sas code which I have created a macro variable to invoke with one conditiona and there sometimes the macro variable will be empty and that time it shows error in my log and stoping the job .I need to run the job also if the macro variable is empty and should create the dataset even though if the record is zero. How it is possible to invoke the macro if the macro variable is empty .
Thanks
Manesh Kp
Hello,
You can do something like this:
%macro isBlank(param);
%sysevalf(%superq(param)=,boolean)
%mend isBlank;
%macro runStuff;
%if %isblank(&clm.) = 1 %then %do;
...... NOT Empty code.......
%end;
%else %do;
......Empty code.......
%end;
%mend runStuff;
%runStuff;
Best regards
Attach your code please (simplified if possible).
Hello,
I think this have been answered in the past, check the links bellow:
https://communities.sas.com/t5/Base-SAS-Programming/check-if-macro-variable-is-null/td-p/114506
from stackOverflow:
http://stackoverflow.com/questions/24496087/skip-block-of-codes-if-macro-variable-is-empty
also this nice paper about the subject:
http://support.sas.com/resources/papers/proceedings09/022-2009.pdf
Best regards,
Create a template, then insert or append records to it. Table always exists then:
proc sql; create table RESULT (VAR1 char(200),VAR2 num); insert into RESULT select * from ADATASET;
/* Or */
insert into RESULT select * from ADATASET where <condition>; quit;
Please show a small example of your problem (code). Without seeing the macro code and data step code, it's hard to guess. Please post the error from your log as well.
I have created one macro variable and trying to extract from one databse giving condition as
where clm_id in ( &clm. ) since the &clm macro var is empty getting a warning message apparent symbolic reference clm not resolved
Hello,
You can do something like this:
%macro isBlank(param);
%sysevalf(%superq(param)=,boolean)
%mend isBlank;
%macro runStuff;
%if %isblank(&clm.) = 1 %then %do;
...... NOT Empty code.......
%end;
%else %do;
......Empty code.......
%end;
%mend runStuff;
%runStuff;
Best regards
It should be noted that the WHERE condition
clm_id in ( &clm. )
fails also if macro variable CLM has been defined, but contains a null or blank string.
In this case, however, %isblank(&clm.) resolves to 1, so that macro runStuff would incorrectly execute the "NOT Empty code" (presumably including the above WHERE condition).
To avoid this, one could initialize macro variable CLM (e.g., with a %LET, %LOCAL or %GLOBAL statement, as appropriate) and then use macro ISBLANK as has been suggested, but execute the "Empty code" if it returns 1 and the "NOT Empty code" if it returns 0. This would also avoid the warning message about an unresolved apparent symbolic reference.
Hi,
I have a related question. I involving the macro as below.
But seems SAS keep checking validation of the null macro variable in STRIP function, ignoring any condition rules like IF...THEN. How can I skip errors like that?
data work._tst1;
input sex $ ;
datalines;
0
1
;
run;
%let sex = sex ;
%let sexOrienta = ;
%macro isBlank(param);
%sysevalf(%superq(param)=,boolean)
%mend isBlank;
data work._tst2;
set work._tst1;
has_sexOrienta = %isblank(&sexOrienta); *<--this works fine;
if %isblank(&sexOrienta)=1 then sexOrienta = 'empty'; *<--this works fine if omit the below line;
else sexOrienta=strip(&sexOrienta) ; *<--this line keep causing errors due to strip(null) problem, even condition is not met;
run;
Had been searching different key words for solutions, but couldn't find any. Thx a lot.
Hello,
I have no SAS to test but I think your problem is that you are mixing datastep if with the macro.
Remember macro will be solved first and datastep if only will use the resolved result of the macro variable.
After macro resolve will be something like below:
data work._tst2;
set work._tst1;
has_sexOrienta = 1;
if 1=1 then sexOrienta = 'empty';
else sexOrienta=strip() ;
run;
and as you see strip() will give the error.
Best regards,
Please dont re-open an old post which has been solved. Post a new question. Also, don't use macro when it is not needed, there is a base SAS function called missing() which will test this for you:
data want; set have; sexorienta=ifc(missing(sex),"empty",""); run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.