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

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

 

1 ACCEPTED SOLUTION
4 REPLIES 4
Skillside
Calcite | Level 5

that was too easy 😉

thank you

novinosrin
Tourmaline | Level 20
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;
ballardw
Super User

@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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1601 views
  • 0 likes
  • 4 in conversation