options formdlim = '-' nodate; data food2; infile 'food2.txt'; input trt sex $ type $ pref; /* compute overall ANOVA table and nothing more */ proc glm; class sex type; model pref = sex type sex*type; /* the following proc has almost everything you might need */ /* in a data analysis */ proc glm; class sex type; model pref = sex type sex*type; /* compute overall ANOVA table */ lsmeans sex type /stderr; lsmeans sex*type / stderr pdiff adjust = tukey; /* marginal means for each sex and type, and cell means */ /* with all pairwise differences with Tukey adj. for mcp */ estimate 'sex diff.' sex 1 -1; contrast 'sex diff' sex 1 -1; /* estimates and contrasts between marginal means for sex */ estimate 'sex diff w/2s' sex 2 -2; contrast 'sex diff' sex 2 -2; estimate 'L-S' type 0 1 -1; estimate 'C-l/s' type 1 -0.5 -0.5; /* or for type of product */ contrast 'L-S and C-l/s' type 0 1 -1, type 1 -0.5 -0.5; contrast 'L-S and C-S' type 0 1 -1, type 1 0 -1; contrast 'L-S, C-S, and C-L' type 0 1 -1, type 1 0 -1, type 1 -1 0; lsmeans sex*type /slice = sex ; /* tests of equality between types in males */ /* lsmeans sex*type /slice = type; /* tests of equality between sexes for each type */ output out = resids r = resid p = yhat; run; proc plot; plot resid*yhat; run; /* the following illustrates how to use 1-way ANOVA and contrasts */ /* to get almost everything done in the first proc glm */ proc glm data = food2; class trt; model pref = trt; estimate 'sex effect' trt 1 1 1 -1 -1 -1 /divisor = 3; estimate 'L-S' trt 0 1 -1 0 1 -1 /divisor = 2; estimate 'C-l/s' trt 0.5 -0.25 -0.25 0.5 -0.25 -0.25; contrast 'sex SS' trt 1 1 1 -1 -1 -1; contrast 'type SS' trt 0 1 -1 0 1 -1, trt 2 -1 -1 2 -1 -1; contrast 'sex*type SS' trt 0 1 -1 0 -1 1, trt 2 -1 -1 -2 1 1; estimate 'L-S in males' trt 0 0 0 0 1 -1; /* estimate of simple effect: L-S in males */ estimate 'm-f difference for control' trt -1 0 0 1 0 0; /* simple effect of sex in control type */ contrast 'm-f in control' trt -1 0 0 1 0 0; contrast 'm-f in liquid' trt 0 -1 0 0 1 0; contrast 'm-f in solid' trt 0 0 -1 0 0 1; contrast 'type in f' trt 2 -1 -1 0 0 0, trt 0 1 -1 0 0 0; contrast 'type in m' trt 0 0 0 2 -1 -1, trt 0 0 0 0 1 -1; run; /* another way to get the 1-way ANOVA without creating a trt number */ proc glm; class sex type; model pref = sex*type; lsmeans sex*type; /* so you get the order */ estimate 'L-S in males' sex*type 0 0 0 0 1 -1; run; /* comparison of long and short approaches to estimates */ proc glm; class sex type; model pref = sex type sex*type; estimate 'short form' sex 1 -1; estimate 'long form' sex 3 -3 sex*type 1 1 1 -1 -1 -1 /divisor = 3; run;