Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 2

/*Two-way ANOVA SAS Code*/

proc glm data=rawdata;


class a b;
model y = a b a*b;
run;
/* IF the interaction effect is significant */
proc glm data=rawdata;
class a b;
model y = a b a*b;
lsmeans a*b / stderr pdiff adjust=tukey;
run;
/* IF there is no significant interaction effect */
proc glm data=rawdata;
class a b;
model y = a b a*b;
lsmeans a / stderr pdiff adjust=tukey;
lsmeans b / stderr pdiff adjust=tukey;
run;
/*Interaction Plot*/
/* Method 1.*/
proc sort data=rawdata;
by a b;
run;

proc means data=rawdata noprint;
by a b;
var y;
output out=means mean=meany; /*Cell means*/
run;
proc plot data=means;
plot meany*a=b;
run;
/* Method 2.*/
proc glm data=rawdata;
class a b;
model y = a b;
lsmeans a*b / out=lsm;
output out=diag p=py r=ry; /* p=predicted value! r=residual */
run;
proc plot data=lsm; /* Interaction "lot */
plot lsmean*a=b; /* cell mean v# a by b */
plot lsmean*b=a; /* cell mean v# b by a */
run;

proc plot data=diag; /* $iagnostic "lots */
plot y*py py*py=%*% / overlay; /* observed v# predicted */
plot ry*py;
run;

You might also like