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 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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