DATA Step, Macro, Functions and more

How do I get differences between groups over time from PROC MEANS with CLASS statement

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 147
Accepted Solution

How do I get differences between groups over time from PROC MEANS with CLASS statement

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


Accepted Solutions
Solution
‎02-18-2018 12:42 PM
Super User
Posts: 6,543

Re: How do I get differences between groups over time from PROC MEANS with CLASS statement

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.

View solution in original post


All Replies
Solution
‎02-18-2018 12:42 PM
Super User
Posts: 6,543

Re: How do I get differences between groups over time from PROC MEANS with CLASS statement

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 118 views
  • 0 likes
  • 2 in conversation