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

Is there a simple way to average the repeated measures for a given measurement type during a certain time period for a specific subject? I think the simplest thing to do is to create a second concentration column ("CONCEN_AVG"). However, I am not sure how to implement this idea. Is there a simpler way than making multiple subsets?

I would want the average of all the white blood cell counts during period 1 for subject 1, and so on. 

mariko5797_0-1628008903879.png mariko5797_1-1628009203485.png

 

Note: Measurements are arbitrary.

 

Thank you in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
/* UNTESTED CODE */
proc summary data=have nway;
    class id period type;
    var concen;
    output out=means mean=concen_avg;
run;

Then you can merge data set MEANS with data set HAVE, by ID PERIOD TYPE, to get the final table.

 

If you want to (as the next step, which you didn't say) subtract the mean from each value, the easier way is to use PROC STDIZE.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
/* UNTESTED CODE */
proc summary data=have nway;
    class id period type;
    var concen;
    output out=means mean=concen_avg;
run;

Then you can merge data set MEANS with data set HAVE, by ID PERIOD TYPE, to get the final table.

 

If you want to (as the next step, which you didn't say) subtract the mean from each value, the easier way is to use PROC STDIZE.

--
Paige Miller
mariko5797
Pyrite | Level 9

I ended up using

proc sql; 
 create table want as
 select a.*, avg(CONCEN) as CONCEN_AVG
 from have as a group by ID, PERIOD, TYPE;
quit;

I compared the results to the results from PROC SUMMARY method. Both are the same!

PaigeMiller
Diamond | Level 26

Yes, @mariko5797 , PROC SQL and PROC SUMMARY ought to give the same answers when using the AVG function in PROC SQL.

 

I point out that if you are ever in the situation where you want two (or more) slicing of the data, such as

 

group by ID, PERIOD, TYPE

and

 

group by ID, PERIOD

(which happens to me regularly) then PROC SUMMARY is less programming ... and only one pass through the data, while PROC SQL requires two queries and two passes through the data. If you have huge data sets this could save quite a bit of execution time (and of course, PROC SUMMARY saves you some programming effort)

 

--
Paige Miller

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1056 views
  • 1 like
  • 2 in conversation