I tried below code.
%macro isblank(var);
%if %symexist(&var) %then 1; %*not exist*;
%else %if %sysevalf(%superq(&var)=,boolean) %then 1; %*blank*;
%else 0;
%mend isblank;
%let dir =A;
%let Non_segment=y;
proc print data=new;
%if %isblank(Non_segment) %then %do; obs=1;
id direction segment;
var acct;
%end;
%else %do;
proc print data =new;
id direction segment;
var acct;%end;
run;
Getting below error
This error is happening because you are not picturing what the SAS program needs to look like. Your macro code has the capability of generating this SAS program:
proc print data=new;
obs=1;
Now clearly that would generate an error. You can't stick "obs=1;" in the middle of a PROC PRINT. What you can do within PROC PRINT is:
proc print data=new (obs=1);
To do that, this is the macro code that would be most similar to your program:
proc print data=one %if %isblank(Non_segment) %then (obs=1);
;
The rest of it doesn't need to be part of the macro condition since it is the same whether the %ISBLANK condition is true or false:
id direction segment;
var acct;
run;
I tried running below code
%let dir =A;
%let Non_segment=y;
%let linear=1;
%if &linear %then %do;
ods excel options(sheet_name="vol");
proc print data=new %if %isblank(Non_segment) %then (obs=1);
;
id direction segment;
var acct;
run;
%end;
%else %do;
ods excel options(sheet_name="vol");
proc print data=new;
var direction segment acct;
run;
%end;
You need to semi-colon because there are two statements. One macro statement and one SAS statement. Each one needs a semi-colon.
You cannot use nested %IF statements in open code. And you cannot use %IF without %DO in open code.
If you really want to do that in OPEN code that put the optional part into a macro variable and use the %IF blocks to decide what is in the macro variable. Otherwise create a macro and call the macro.
%let obs= ;
%if &linear %then %do;
%let obs= obs=1 ;
%end;
ods excel options(sheet_name="vol");
proc print data=new ( &obs );
%if &linear %then %do;
id direction segment;
var acct;
%end;
%else %do;
var direction segment acct;
%end;
run;
I think my logic is different, number of observation is based on Non-segment value
I tried running for Non segment and without non segment. Both are showing same results.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.