BookmarkSubscribeRSS Feed
blueskyxyz
Lapis Lazuli | Level 10
  TRTA TRTB
LS Mean (SE) 6.5(1.70) 5.0(2.50)
Difference (SE)   -1.0(2.00)
    TRTB-TRTA

 

take an example, I want to get the value  -1.0(2.00)  <trtb-trta>    instead of 1.0(2.00) <trta-trtb>, how to change my code in anova analysis?

6 REPLIES 6
PaigeMiller
Diamond | Level 26

What SAS PROC are you using?

--
Paige Miller
blueskyxyz
Lapis Lazuli | Level 10
Hi Miller, I use proc glm since the result needs to output LS Means (SE) & Diff LS Means (SE) with ANCOVA Analysis.
StatDave
SAS Super FREQ

You should be able to reverse the difference by using an option for the variable in the CLASS statement - such as DESCENDING or ORDER=. For example, for variable B:  class a b(desc) c;

blueskyxyz
Lapis Lazuli | Level 10

捕获.JPG

hi Dave, two options don't work in proc glm.

 

You can take a look at my code as below:

 

*******************************
date and time: Tuesday, November 05, 2019 17:09:46
stat user's guide
http://documentation.sas.com/?docsetId=statug&docsetTarget=statug_glm_syntax10.htm&docsetVersion=15.1&locale=zh-CN
*dependent variable: height
*fixed factors(class/group var): sex 
*covariate:weight 

ANCOVA Analysis		
ABC material			               trt1			    trt2
LS Means (SE)	                  xx.x (xx.xx)	       xx.x (xx.xx)
95% CI	                                (xx.xx, xx.xx)	      (xx.xx, xx.xx)

Diff LS Means (SE)	C	            xx.x (xx.xx)
95% C.I.		                         (xx.xx, xx.xx)

*******************************;

ods output  OverallANOVA=Overall  ModelANOVA=stat LSMeans=LSMeans 
LSMeanCL=LSMeanCL  LSMeanDiffCL=LSMeanDiffCL  FitStatistics=FitStatistics diff=adiff Estimates=estdiffs    
;

;
proc glm data=sashelp.class;
	class sex;
	model height=weight sex;
	lsmeans sex/pdiff cl stderr;
	estimate 'male vs female' sex  1 -1 ;
run;
quit;


/*LS Means (SE) 95% CI*/
data lsm;
    length mean_se cl $200;
	merge LSMeans LSMeanCL ;
	by sex;
	mean_se= strip(put(LSMean,18.2-L))||" ("||strip(put(stderr,18.2-L))||")";
	cl="("||strip(put(lowercl,18.2-L))||","||strip(put(uppercl,18.2-L))||")";
run;

proc transpose data=lsm out=lsm1(rename=(f=col1 m=col2));
	id sex;
	var mean_se cl;
run;

/*Diff LS Means (SE)2*/
data dlsm;
    length dmean_se dcl $200;
	merge LSMeanDiffCL estdiffs ;
	by dependent;
	dmean_se= strip(put(difference,18.2-L))||" ("||strip(put(stderr,18.2-L))||")";
	dcl="("||strip(put(lowercl,18.2-L))||","||strip(put(uppercl,18.2-L))||")";
run;

proc transpose data=dlsm out=dlsm1(rename=(col1=col2));
	var dmean_se dcl;
run;

data trans;
	set lsm1 dlsm1;
run;

捕获.JPG

PaigeMiller
Diamond | Level 26

If you are creating this table via DATA steps, then simply multiplying the value by –1 takes care of the issue.

 

In this simple example, you can also do this in PROC GLM via

 

estimate 'male vs female' sex  -1 1 ;

This should work because this is a very simple model, but in more complicated cases, ESTIMATE does not produce LS Means unless you specifically construct an estimate statement to have the coefficients for the LS Mean (which is explained here, and which you can determine via the E3 option in the model statement). In these more complicated cases, I wouldn't bother myself in trying to construct and type in the proper ESTIMATE statement, I would rather multiply the result by –1, which I can do in my head a lot faster than I can type in the proper ESTIMATE statement.

--
Paige Miller
StatDave
SAS Super FREQ

If you switch to a procedure like PROC GENMOD to fit your model, you could use the DESCENDING option in the CLASS statement.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 6 replies
  • 806 views
  • 3 likes
  • 3 in conversation