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
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
  • 774 views
  • 4 likes
  • 3 in conversation