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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 1000 views
  • 5 likes
  • 4 in conversation