Hi ,
my question is how I can only keep the IDs with the highest value of A
data have;
input id A B C;
cards;
1 2 3 4
1 4 2 5
1 5 3 12
1 7 34 3
2 5 5 5
2 6 12 0
2 9 3 2
2 11 3 1
3 7 6 5
3 23 3 2
3 12 12 44
4 4 23 33
4 9 6 1
5 5 7 2
6 7 8 1
run;
data want;
input id A B C;
cards;
1 7 34 3
2 11 3 1
3 23 3 2
4 9 6 1
5 5 7 2
6 7 8 1
run;
Thanks
Please try
proc sort data=have;
by id a;
run;
data want;
set have;
by id a;
if last.id;
run;
Please try
proc sort data=have;
by id a;
run;
data want;
set have;
by id a;
if last.id;
run;
by proc sql
proc sql;
create table want as select a.* from have as a
inner join
(select id, max(a) as maxa from have group by id) as b on a.id=b.id and a.a=b.maxa;
quit;
Hi @ali_far,
Another option is PROC SUMMARY:
proc summary data=have;
by id;
var a;
output out=want(drop=_:) max= maxid(a(b c))=;
run;
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 save with the early bird rate—just $795!
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.