BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Chris_LK_87
Quartz | Level 8

Hello, 

 

I have a dataset and I want to select every indivdual  that meets a certain criteria; "S70" or "E90" 

 

data have;
length id $10 Type $10;
input id$ Type$;
datalines;
1 S70
1 P70
1 A00
2 F00
2 S70
3 T34
4 E90
4 Q12
5 H12
6 J54

6 J19
run;

 

Data want; 

length id $10 Type $10;
input id$ Type$;
datalines;
1 S70
1 P70
1 A00
2 F00
2 S70
4 E90
4 Q12

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data have;
length id $10 Type $10;
input id$ Type$;
datalines;
1 S70
1 P70
1 A00
2 F00
2 S70
3 T34
4 E90
4 Q12
5 H12
6 J54
6 J19
;

proc sql;
   create table want as
   select * from have
   group by id
   having sum(Type in ('S70', 'E90')) > 0
   ;
quit;

 

Result:

 

id Type
1  S70
1  A00
1  P70
2  S70
2  F00
4  E90
4  Q12

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
data have;
length id $10 Type $10;
input id$ Type$;
datalines;
1 S70
1 P70
1 A00
2 F00
2 S70
3 T34
4 E90
4 Q12
5 H12
6 J54
6 J19
;

proc sql;
   create table want as
   select * from have
   group by id
   having sum(Type in ('S70', 'E90')) > 0
   ;
quit;

 

Result:

 

id Type
1  S70
1  A00
1  P70
2  S70
2  F00
4  E90
4  Q12

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 278 views
  • 4 likes
  • 3 in conversation