DATA Step, Macro, Functions and more

simple array question II

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

simple array question II

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;


Accepted Solutions
Solution
‎03-07-2018 10:15 PM
PROC Star
Posts: 2,231

Re: simple array question II

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

View solution in original post


All Replies
Solution
‎03-07-2018 10:15 PM
PROC Star
Posts: 2,231

Re: simple array question II

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

Occasional Contributor
Posts: 10

Re: simple array question II

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?

PROC Star
Posts: 2,231

Re: simple array question II

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;

Super User
Posts: 6,543

Re: simple array question II

Alternatively:

 

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

   output;

   delete;

end;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 118 views
  • 0 likes
  • 3 in conversation