Hi,
this time i would like to calculate mean value from different variables (their highest value). Please, suggest a solution.
data have;
input ID age1 age2 age3 age4 age5 ;
cards;1 1 3 6 9 2
2 6 2 3 4 4
3 7 2 9 0 0;
run;
the mean should be calculated from 9, 6 and 9
Thank You
Use
max(of age:)
in a data step to create the max for each observation, then calculate the mean as usual with sql or proc means.
Use
max(of age:)
in a data step to create the max for each observation, then calculate the mean as usual with sql or proc means.
that was too easy 😉
thank you
data have;
input ID age1 age2 age3 age4 age5 ;
cards;
1 1 3 6 9 2
2 6 2 3 4 4
3 7 2 9 0 0
;
run;
data mean_of_max_age;
_n_= 0;
do until(z);
set have end=z;
max_age= max(of age1-age5);
_n_=sum(_n_,n(max_age));
_iorc_=sum( _iorc_ ,max_age);
end;
Mean= _iorc_/ _n_;
drop age1-age5 id;
run;
@Skillside wrote:
Hi,
this time i would like to calculate mean value from different variables (their highest value). Please, suggest a solution.
data have; input ID age1 age2 age3 age4 age5 ; cards;1 1 3 6 9 2 2 6 2 3 4 4 3 7 2 9 0 0; run;
the mean should be calculated from 9, 6 and 9
Thank You
A hint for future example data sets: If you are going to reference the required values it would be a better idea to have those values unique or explicitly state which value from which record. Max is relatively simple but a more complicated question with both 6 and 9 repeated in different records might be another story.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: