Hi all!
I have a dataset at hand that looks like the following:
ID MED1 MED2 MED3 MED4
1 892 384 . 454 345
2 802 394 . 434 233
3 852 384 . 334 599
I want to subset the dataset so that only patients with meds in {892, 334, 599, 384} remains. I don't want to repeat the list of 4 codes in all 4 variables in the data step. Can anyone show me how to do it? Thanks.
There are two approaches that work, there may be an easier one but IN didn't seem to work for me for two lists.
1. Create two arrays, loop through searching for a value, if found, output and exit the loop.
The second approach transposes the data to a long format - much easier to use/query in the long run 🙂
Then you can either keep it long or you could use that list to generate back the same answer as the first method.
Please don't post the same question multiple times.
Are all your values numeric as in your example or are they character values?
all numeric
There are two approaches that work, there may be an easier one but IN didn't seem to work for me for two lists.
1. Create two arrays, loop through searching for a value, if found, output and exit the loop.
The second approach transposes the data to a long format - much easier to use/query in the long run 🙂
Then you can either keep it long or you could use that list to generate back the same answer as the first method.
Thank you so much! That's an nice answer.
@Viveme789 Requesting you to please mark the question as answered and close the thread. Thank you!
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.
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.