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. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 435 views
  • 1 like
  • 2 in conversation