data one;
input avalc $ aval;
datalines;
r1 1
r2 2
r3 3
r4 4
;
proc sql ;
select count(distinct avalc) into: cntt trimmed from one;
select distinct avalc into :param1 -:param&cntt.
from one;
quit;
%put ¶m1;
%put ¶m2;
%put ¶m3;
%put ¶m4;
data two three four six;
set one;
if avalc='r1' then output two;
if avalc='r2' then output three;
if avalc='r3' then output four;
if avalc='r4' then output six;
run;
%macro want;
data final;
set two three %if %symexist (param3) %then %do; four;%end; %if %symexist (param4) %then %do; six; %end;;
run;
%mend;
options mprint mlogic symbolgen;
%want;
Dear
when I run macro(%want) at the bottom of my pgm i am getting error. Please suggest Thank you
output expected from macro %want
data final;
set two three four six;
run;
If you wanted that code then why did you insert those two extra semi-colons?
Plus the %do/%end blocks seem like overkill.
%macro want;
data final;
set two three
%if %symexist (param3) %then four ;
%if %symexist (param4) %then six ;
;
run;
%mend;
If you wanted that code then why did you insert those two extra semi-colons?
Plus the %do/%end blocks seem like overkill.
%macro want;
data final;
set two three
%if %symexist (param3) %then four ;
%if %symexist (param4) %then six ;
;
run;
%mend;
Since version 9.4M5, you do not need a macro definition, %if %then %do %end can be used in open code:
data final;
set
two
three
%if %symexist (param3) %then %do;
four
%end;
%if %symexist (param4) %then %do;
six
%end;
;
run;
%mend;
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.