DATA Step, Macro, Functions and more

Macro variable is empty

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

Macro variable is empty

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


Accepted Solutions
Solution
‎05-03-2016 09:19 AM
Contributor
Posts: 50

Re: Macro variable is empty

[ Edited ]

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

View solution in original post


All Replies
Super User
Posts: 5,256

Re: Macro variable is empty

Attach your code please (simplified if possible).

Data never sleeps
Contributor
Posts: 50
Super User
Super User
Posts: 7,401

Re: Macro variable is empty

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;
PROC Star
Posts: 1,231

Re: Macro variable is empty

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.

 

 

Contributor
Posts: 60

Re: Macro variable is empty

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

Solution
‎05-03-2016 09:19 AM
Contributor
Posts: 50

Re: Macro variable is empty

[ Edited ]

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

Trusted Advisor
Posts: 1,115

Re: Macro variable is empty

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 996 views
  • 0 likes
  • 6 in conversation