BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dennis_oz
Quartz | Level 8

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 ;  

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

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

  • doSubL() function, or
  • CALL EXECUTE routine

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;

 

View solution in original post

2 REPLIES 2
RichardDeVen
Barite | Level 11

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

  • doSubL() function, or
  • CALL EXECUTE routine

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;

 

ChrisNZ
Tourmaline | Level 20

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;  

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 783 views
  • 5 likes
  • 3 in conversation