BookmarkSubscribeRSS Feed
Melk
Lapis Lazuli | Level 10

As part of an if-then statement, I need to flag observations with certain codes in any of 25 variables dx1-dx25. What is the best way to do this?

 

y=0

if not missing(x) and...

 <something translating to 123 or 234 in any of dx1-dx25>

...then y=1

end;

run;

 

 

 

 

 

 

3 REPLIES 3
Reeza
Super User

Double arrays. One with the list of values you’re looking for and a second with the dx. 

 

Then loop through the smaller array and use WHICHC to search for the values. Use a LEAVE/BREAK to exit the loop once the flag is set. 

 

Another approach would be to make it a long data set than it’s a very easy WHERE filter on the query. 

Melk
Lapis Lazuli | Level 10

Can I use double arrays if this is one part of multiple ands in an if-then statement?

 

i.e.

 

y=0;

if not missing(x)

  and age>=18

  and died = 0

  and <array statement here??>

then do;

y=1;

end;

run;

 

 

Reeza
Super User

You can nest or add diff criteria just have to make sure the order is correct. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 934 views
  • 0 likes
  • 2 in conversation