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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20
4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

if procedure(x) in ('9351' '9359') then output;

Angmar
Obsidian | Level 7

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?

ChrisNZ
Tourmaline | Level 20

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;

Astounding
PROC Star

Alternatively:

 

if procedure(x) in ('9351' '9359') then do;

   output;

   delete;

end;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 798 views
  • 0 likes
  • 3 in conversation