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