BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ali_far
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try

 

proc sort data=have;
by id a;
run;

data want;
set have;
by id a;
if last.id;
run;
Thanks,
Jag

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

Please try

 

proc sort data=have;
by id a;
run;

data want;
set have;
by id a;
if last.id;
run;
Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
ali_far
Obsidian | Level 7
Thanks Jag,
both codes work well!
appreciate your time
FreelanceReinh
Jade | Level 19

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;

 

ali_far
Obsidian | Level 7
Thanks a lot.
Your code also works well and it is so cool...

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1577 views
  • 0 likes
  • 3 in conversation