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;
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
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
proc sql;
create table want as
select *
from have a
where id in (select id from have where type in ('S70','E90'))
;
quit;
Untested, posted from my tablet.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.