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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: