Hi ,
Can someone suggest how to do the below.
have :
Table1;
Column1
AAAA
AAAE
AAAX
Want:
if 'AAAA' in Column1 then do %process1;
else if 'AAAE' in Column1 then do %process2;
else if 'AAAX' in Column1 then do %process3;
else %process4 ;
Presuming the DATA step is simply dispatching macros that perform other steps, and do not need to feedback to the running DATA step...
Use either
Example:
%NRSTR is used to stack all invocations until DATA step finishes.
data _null_;
set have;
select (Column1);
when ('AAAA') call execute ('%nrstr(%process1))'); /* or rc=dosubl('%process1'); */
when ('AAAE') call execute ('%nrstr(%process2))'); /* or rc=dosubl('%process2'); */
when ('AAAX') call execute ('%nrstr(%process3))'); /* or rc=dosubl('%process3'); */
otherwise call execute ('%nrstr(%process4))'); /* or rc=dosubl('%process4'); */
end;
run;
Presuming the DATA step is simply dispatching macros that perform other steps, and do not need to feedback to the running DATA step...
Use either
Example:
%NRSTR is used to stack all invocations until DATA step finishes.
data _null_;
set have;
select (Column1);
when ('AAAA') call execute ('%nrstr(%process1))'); /* or rc=dosubl('%process1'); */
when ('AAAE') call execute ('%nrstr(%process2))'); /* or rc=dosubl('%process2'); */
when ('AAAX') call execute ('%nrstr(%process3))'); /* or rc=dosubl('%process3'); */
otherwise call execute ('%nrstr(%process4))'); /* or rc=dosubl('%process4'); */
end;
run;
If the macros contain data step statements, then this is a possible syntax:
if COLUMN1='AAAA' then do; %process1; end;
else if COLUMN1='AAAE' then do; %process2; end;
else if COLUMN1='AAAX' then do; %process3; end;
else do; %process4; end;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.