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
all you need is
data final;
set draft1;
if PAC = 'inpatient' THEN OUTPUT;
RUN;
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.
Try
if upcase(strip(PAC)) = 'INPATIENT' THEN OUTPUT;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.