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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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