Pyrite | Level 9

## Average Repeated Measures

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.

Note: Measurements are arbitrary.

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: Average Repeated Measures

``````/* 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
3 REPLIES 3
Diamond | Level 26

## Re: Average Repeated Measures

``````/* 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
Pyrite | Level 9

## Re: Average Repeated Measures

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!

Diamond | Level 26

## Re: Average Repeated Measures

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
Discussion stats
• 3 replies
• 924 views
• 1 like
• 2 in conversation