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

Hello, 

 

I have the code below and it works, but I would like to add options to "where" and "if" statements below and I keep getting errors.

 

Note: I already have a lowcase table. 

 

I would also like to the add "emergency_patients" to "where" statement.

/*Identify Patient_Type_ID for in_patients and emergency_patients*/

title 'Proc Print  patientid for in)patients';

proc print data=lib.hf_d_patient_type;

where patient_type CONTAINS 'in_patient';  

run;

 

I would like to add another patient_id,  "105" to the "if" statement.

/*Restrict Encounters to Inpatients Aged 18 Years or Above*/

data lib.dataB;

set mylib.dataA;

if patient_id=50;

run;

 

Thanks,

Schtroumfette! 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Depends on exactly what you're doing. 

 

In this case (and the next) you can chain your conditions together with an OR

proc print data=lib.hf_d_patient_type;
where patient_type CONTAINS 'in_patient' 
          or patient_type contains 'emergency_patient';  
run;

There's also an IN operator, if you're looking for exact matches, which is why this approach does not work for the first WHERE statement.

data lib.dataB;

set mylib.dataA;

if patient_id in (50, 105) ;

run;

@Schtroumpfette wrote:

Hello, 

 

I have the code below and it works, but I would like to add options to "where" and "if" statements below and I keep getting errors.

 

Note: I already have a lowcase table. 

 

I would also like to the add "emergency_patients" to "where" statement.

/*Identify Patient_Type_ID for in_patients and emergency_patients*/

title 'Proc Print  patientid for in)patients';

proc print data=lib.hf_d_patient_type;

where patient_type CONTAINS 'in_patient';  

run;

 

I would like to add another patient_id,  "105" to the "if" statement.

/*Restrict Encounters to Inpatients Aged 18 Years or Above*/

data lib.dataB;

set mylib.dataA;

if patient_id=50;

run;

 

Thanks,

Schtroumfette! 




View solution in original post

2 REPLIES 2
Reeza
Super User

Depends on exactly what you're doing. 

 

In this case (and the next) you can chain your conditions together with an OR

proc print data=lib.hf_d_patient_type;
where patient_type CONTAINS 'in_patient' 
          or patient_type contains 'emergency_patient';  
run;

There's also an IN operator, if you're looking for exact matches, which is why this approach does not work for the first WHERE statement.

data lib.dataB;

set mylib.dataA;

if patient_id in (50, 105) ;

run;

@Schtroumpfette wrote:

Hello, 

 

I have the code below and it works, but I would like to add options to "where" and "if" statements below and I keep getting errors.

 

Note: I already have a lowcase table. 

 

I would also like to the add "emergency_patients" to "where" statement.

/*Identify Patient_Type_ID for in_patients and emergency_patients*/

title 'Proc Print  patientid for in)patients';

proc print data=lib.hf_d_patient_type;

where patient_type CONTAINS 'in_patient';  

run;

 

I would like to add another patient_id,  "105" to the "if" statement.

/*Restrict Encounters to Inpatients Aged 18 Years or Above*/

data lib.dataB;

set mylib.dataA;

if patient_id=50;

run;

 

Thanks,

Schtroumfette! 




Schtroumpfette
Obsidian | Level 7
Thank you Reeza,

The if statement worked, thanks.

The where statement did not work but that is fine. I run them separately and it worked and it was for a quality check.

Very helpful,
Thank you again,
Nisrine

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 633 views
  • 0 likes
  • 2 in conversation