BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have the following variables (id and score) and would like to know how to get the third variable maxscore:
id score maxscore
1 5 7
1 7 7
1 3 7
2 2 8
2 1 8
2 8 8

What is the code that I'll need to use to get maxscore to pick the largest value from the observations for each id?
Thank you for your help!
2 REPLIES 2
deleted_user
Not applicable
> I have the following variables (id and score) and
> would like to know how to get the third variable
> maxscore:
> id score maxscore
> 1 5 7
> 1 7 7
> 1 3 7
> 2 2 8
> 2 1 8
> 2 8 8
>
> What is the code that I'll need to use to get
> maxscore to pick the largest value from the
> observations for each id?
> Thank you for your help!


You can use either a Proc SQL step or a data step to find a solution. SQL may appear concise but it also preprocesses the data to arrive at the max score for each ID. I have presented only the SQL solution below:

data NOmaxscore ;
input id score ;
cards ;
1 5
1 7
1 3
2 2
2 1
2 8
run ;

proc sql ;
create table WITHmaxscore as
select * , max(score) as maxscore
from NOmaxscore
group by id ;
quit ;

options nocenter ;
proc print ;
run ;

And this yields:

Obs id score maxscore

1 1 5 7
2 1 3 7
3 1 7 7
4 2 8 8
5 2 1 8
6 2 2 8

Venky Chakravarthy
deleted_user
Not applicable
Thank you very much!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 2 replies
  • 2782 views
  • 0 likes
  • 1 in conversation