How would I use an array to extract ONLY observations/records that have the values '9351' '9359' (character values)? Below is my code (I made a new variable previously, but it would be better if I just extracted the records I wanted instead of identifying them with a new variable).
data cuthip;
set allrecords;
array procedure (3) $ prcode1-prcode3;
do x=1 to 3;
if procedure(x) in ('9351' '9359') then newvar=1;
end;
run;
if procedure(x) in ('9351' '9359') then output;
if procedure(x) in ('9351' '9359') then output;
It worked, but it's now creating records when the array finds an observation with both those values (i.e., the observation has 9359 and 9351). I can't use the OR statement in my code between '9359' and '9351' - how do I tell the array then to just search for one?
Something like this should work too, no arrays:
data cuthip;
set allrecords;
if index('9351', catx('-',of prcode1-prcode3)) or index('9359', catx('-',of prcode1-prcode3));
run;
Alternatively:
if procedure(x) in ('9351' '9359') then do;
output;
delete;
end;
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.