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!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 2531 views
  • 2 likes
  • 3 in conversation