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

Hi all, 

 

I am trying to set up a code that will automatically find the average of certain rows at a time. For example, in the data set below I want to find the average weight each month:

data have;
input id $ weight month;
cards;
1 108 1
1 112 1 1 114 2 1 118 2 2 100 1 2 108 1 2 110 2
2 102 2
2 100 2 ; run;

 So ideally, the new data table I want will look like this:

data want;
input id $ avg_weight month;
cards;
1 110 1
1 116 2
2 104 1
2 104 2
;
run;

Thanks for any/all help!

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ
proc means data=have nway noprint;
 CLASS id month;
 VAR   weight;
 output out=want mean= / autoname;
run;

Koen

View solution in original post

1 REPLY 1
sbxkoenk
SAS Super FREQ
proc means data=have nway noprint;
 CLASS id month;
 VAR   weight;
 output out=want mean= / autoname;
run;

Koen

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 281 views
  • 0 likes
  • 2 in conversation