Hello
I have a data set that has variables time (1 to 46); group (3 different groups) and alc (a numeric variable)
If I run
proc means data = ken.lsdalclong;
class time group;
var alc;
output out = ken.days mean = mean uclm = upper lclm = lower;
run;
then I get the mean, lcl and ucl of alc by time and group. So far so good.
How can I get the differences between the means of the three groups by time?
That is, I want 46 values of (mean group 1 – mean group2) and 46 values of (mean group 1 – mean group3)?
Thanks
Peter
If you examine the output data set, you will see that you have the pieces that you need. It is just a matter of extracting the right pieces and re-assembling them properly. Here is a starting point:
proc transpose data=ken.days prefix=mean_group out=want;
id group;
var mean;
by time;
where _type_=3;
run;
Take a look first at KEN.DAYS to understand that the WHERE statement in PROC TRANSPOSE is selecting the proper observations.
Then take a look at the output data set WANT which will need a few more calculations, but has the data assembled in an easy-to-calculate form.
If you examine the output data set, you will see that you have the pieces that you need. It is just a matter of extracting the right pieces and re-assembling them properly. Here is a starting point:
proc transpose data=ken.days prefix=mean_group out=want;
id group;
var mean;
by time;
where _type_=3;
run;
Take a look first at KEN.DAYS to understand that the WHERE statement in PROC TRANSPOSE is selecting the proper observations.
Then take a look at the output data set WANT which will need a few more calculations, but has the data assembled in an easy-to-calculate form.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.