BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hello_there
Lapis Lazuli | Level 10

Hi, 

 

I'm running a model in proc GLM. 

That looks something like this: 

PROC GLM data=a;
  by subject;
class activity;
model cont_var=activity;
lSMEANS activity / adjust = Tukey out=b;
run; quit;

The activities are a. (reference), b., c., d.

 

The current code only outputs cont_var LSMEANS and the p values for the difference from a.

 

How would I be able to output the LSMEANS difference from a?

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello,

 

Is this what you are after?

*ods trace on;
*ods output Diff=work.Difference_Matrix;
ods output  LSMeans=work.LSMeans;

PROC GLM data=sashelp.class;
*by subject;
class age;
model height=age;
LSMEANS age / adjust = Tukey out=b;
run; 
quit;

data work.LSMeans_DIFF;
 set work.LSMeans;
 retain ref .;
 if _N_=1 then do; ref=LSMean; end;
 Diff = LSMean - ref;
run;
/* end of program */

 

Koen

View solution in original post

4 REPLIES 4
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
This sounds like a job for the ODS tables, which allow you to export certain statistics from PROC GLM to an output data set.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_glm_details70.htm

E.g., you might be looking to add a line like this to your code:
ods output LSMeans=LSMEANS_diffs;
Hello_there
Lapis Lazuli | Level 10
Thank you for giving me this link, it was helpful!
sbxkoenk
SAS Super FREQ

Hello,

 

Is this what you are after?

*ods trace on;
*ods output Diff=work.Difference_Matrix;
ods output  LSMeans=work.LSMeans;

PROC GLM data=sashelp.class;
*by subject;
class age;
model height=age;
LSMEANS age / adjust = Tukey out=b;
run; 
quit;

data work.LSMeans_DIFF;
 set work.LSMeans;
 retain ref .;
 if _N_=1 then do; ref=LSMean; end;
 Diff = LSMean - ref;
run;
/* end of program */

 

Koen

Hello_there
Lapis Lazuli | Level 10
Thanks, this worked!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2369 views
  • 2 likes
  • 3 in conversation