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

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

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