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.
Thank you in advance!
/* 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.
/* 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.
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!
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)
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.