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?
What SAS PROC are you using?
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;
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;
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.
If you switch to a procedure like PROC GENMOD to fit your model, you could use the DESCENDING option in the CLASS statement.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.