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

Hi,

Example input data:

Pat_ID     Pay_code

A1              1001

A2              1002

A3              1003

A3              4549

A4              5567

A5              1001

A6             

A7              XXXX

I need to only keep the entries say with pay_code being 1001, 1002, 1003 and 5567.  I tried to use this but it doesn't seem to work.

data pat_pay;

set pay_info;

if pay_code EQ '1001' or '1002' or '1003' or '5567';
run;

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Replace the if with a Where, or use a then output:

data pat_pay;

     set pay_info;

     where pay_code in ('1001','1002');

run;

You can also put it on the set statement for some performance gain:

data pat_pay;

     set pay_info (where=(pay_code in ('1001','1002')));

run;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Replace the if with a Where, or use a then output:

data pat_pay;

     set pay_info;

     where pay_code in ('1001','1002');

run;

You can also put it on the set statement for some performance gain:

data pat_pay;

     set pay_info (where=(pay_code in ('1001','1002')));

run;

pinkyc
Calcite | Level 5

Hi,

Thanks!  I was wondernig how to output the observations with the rate codes wanted to one dataset and the remaining to another one using where in?

PoornimaRavishankar
Quartz | Level 8

The EQ operator can compare a value with a single value. The IN operator checks the current variable for a list of values, please use RW9 's solution.

CTorres
Quartz | Level 8

I agree with RW9: using where instead of If when possible is better.


Anyway, the correct syntax of the if statement would be:


if pay_code EQ '1001' or pay_code EQ '1002' or pay_code EQ '1003' or pay_code EQ '5567';


CTorres

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1341 views
  • 5 likes
  • 4 in conversation