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

 Hi 

 

Each ID has several instances, and each instance has a different value. I would like the final output to be the maximum value per ID and per year. So the initial dataset is:

 

ID   year  Value
 1   2012   100
 1   2013   7
 1   2013   65
 2   2015   12
 2   2015   97
 3   2011   82
 3   2012   54
3 2012 95

And the output will be :

 ID   year  Value
 1    2012   100
 1    2013   65
2 2015 97 3 2011 82
3 2012 95
I tried running proc means :
proc means data=H10 noprint;
class ID year ;
var value;
output out=want max(value)=;
run;

but it dosen't work.

thx u very much.
 
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

with proc means try

 

proc means data=have noprint;
by id year;
var value;
output out=max max=value;
run;
Thanks,
Jag

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

try proc sql

 

proc sql;
create table max as select id, year, max(value) as value from have group by id, year;
quit;
Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

with proc means try

 

proc means data=have noprint;
by id year;
var value;
output out=max max=value;
run;
Thanks,
Jag
ESSALAHBENNANI
Fluorite | Level 6
or
proc means data=sortedOutput noprint;
class id ; by year;
var value;
output out=want3 max(value)=;
run;

thx u
Reeza
Super User

Your original code was correct, you don't specify how it was wrong but I suspect it had too many points because it calculates ALL interactions between year and ID, so the max for each ID, the max for each year and then the max for each Year/ID which is the one you actually want. You can limit your results with the NWAY option.

I like to specify the variable name, but its not required.

 

proc means data=H10 noprint NWAY;
 class ID year ; 
 var value;
 output out=want max(value)=max_value;
run;

 

ESSALAHBENNANI
Fluorite | Level 6

exactly thx u verry much

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2628 views
  • 4 likes
  • 3 in conversation