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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.