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.
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!
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.