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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ

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.

 

View solution in original post

2 REPLIES 2
maguiremq
SAS Super FREQ

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.

 

cmendoza87
Obsidian | Level 7

This worked! Thank you so much!!!! PROC SQL seemed really complicated to me before but this code will definitely help me use it more. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 708 views
  • 1 like
  • 2 in conversation