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

Hello, I am new to SAS and am using SAS 9.4. I am trying to remove specific observations from a data set, in this case it is removing any rows that do not have 'inpatient' in the PAC variable. I have tried this code:

data final;
set draft1;
if PAC = 'inpatient' THEN OUTPUT;
if PAC ^= 'inpatient' THEN DELETE;
RUN;

But when I use this code no error shows up, and it goes through; However it just carries over all the data from draft1 without any changes. I would like to have any rows that do not have 'inpatient' in the PAC variable to be removed, what seems to be wrong with my code?

 

Below is the example data set:

 

DATA: Draft1


ID number          GENDER          PAC

12345                      M               inpatient

12345                      M              emergency

12345                      M              outpatient

24689                      F                inpatient

24689                      F                inpatient

24689                      F                emergency

56789                      M                inpatient

 

 

what I want is this:

 

DATA: Final

 

ID number          GENDER          PAC

12345                      M               inpatient

24689                      F                inpatient

24689                      F                inpatient

56789                      M               inpatient

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Try

 

if upcase(strip(PAC)) = 'INPATIENT' THEN OUTPUT;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

all you need is

 

data final;
set draft1;
if PAC = 'inpatient' THEN OUTPUT;
RUN;
Kbug
Obsidian | Level 7

I tried that and it still shows up as 0 observations. 
The notes say this:

NOTE: There were 2138 observations read from data set draft1.

NOTE: The data set final has 0 observations and 11 variables. 

 

so it is going through, but it isn't correct. 

novinosrin
Tourmaline | Level 20

Try

 

if upcase(strip(PAC)) = 'INPATIENT' THEN OUTPUT;
Kbug
Obsidian | Level 7
Thank you!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1392 views
  • 2 likes
  • 2 in conversation