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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.