I have a large dataset with multiple observations per person. I am having trouble creating a separate dataset from this dataset where if a person has a given observation (fever = yes) that I can delete all of their observations, not just the observation with fever = yes. Is there a way to IF-THEN-DELETE a group?
Have:
ID Fever
1 N
1 N
1 N
1 N
1 N
1 N
1 N
2 Y
2 N
2 N
2 N
2 N
5 N
5 N
5 N
5 N
5 N
Want:
ID Fever
1 N
1 N
1 N
1 N
1 N
1 N
1 N
5 N
5 N
5 N
5 N
5 N
Thank you!
I find PROC SQL subqueries helpful in these circumstances:
data have;
input id fever $;
datalines;
1 N
1 N
1 N
1 N
1 N
1 N
1 N
2 Y
2 N
2 N
2 N
2 N
5 N
5 N
5 N
5 N
5 N
;
proc sql;
create table want as
select
*
from
have
where id not in (select
id
from
have
where
fever = "Y");
quit;
id fever 1 N 1 N 1 N 1 N 1 N 1 N 1 N 5 N 5 N 5 N 5 N 5 N
There may be some IF-THEN stuff that you can do, but I'm not quite sure what would be the most efficient way.
I find PROC SQL subqueries helpful in these circumstances:
data have;
input id fever $;
datalines;
1 N
1 N
1 N
1 N
1 N
1 N
1 N
2 Y
2 N
2 N
2 N
2 N
5 N
5 N
5 N
5 N
5 N
;
proc sql;
create table want as
select
*
from
have
where id not in (select
id
from
have
where
fever = "Y");
quit;
id fever 1 N 1 N 1 N 1 N 1 N 1 N 1 N 5 N 5 N 5 N 5 N 5 N
There may be some IF-THEN stuff that you can do, but I'm not quite sure what would be the most efficient way.
This worked! Thank you so much!!!! PROC SQL seemed really complicated to me before but this code will definitely help me use it more.
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.