Help using Base SAS procedures

max value

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

max value

 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.
 

Accepted Solutions
Solution
‎08-27-2016 01:14 PM
Trusted Advisor
Posts: 1,131

Re: max value

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


All Replies
Trusted Advisor
Posts: 1,131

Re: max value

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
Solution
‎08-27-2016 01:14 PM
Trusted Advisor
Posts: 1,131

Re: max value

with proc means try

 

proc means data=have noprint;
by id year;
var value;
output out=max max=value;
run;
Thanks,
Jag
Occasional Contributor
Posts: 8

Re: max value

or
proc means data=sortedOutput noprint;
class id ; by year;
var value;
output out=want3 max(value)=;
run;

thx u
Super User
Posts: 17,868

Re: max value

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;

 

Occasional Contributor
Posts: 8

Re: max value

exactly thx u verry much

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 384 views
  • 4 likes
  • 3 in conversation