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;  

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 879 views
  • 5 likes
  • 3 in conversation