Analysis of Variance with PROC GLM
Prerequisites: Linear regression with PROC REG
Analysis of variance (ANOVA) tests whether the mean of a numeric
outcome differs between groups. PROC GLM (general linear models) fits
ANOVA, regression, and mixtures of both, with categorical predictors in
a CLASS statement.
Do boys and girls in SASHELP.CLASS differ in average weight?
proc glm data=sashelp.class;
class sex;
model weight = sex;
means sex;
run;
quit;
Output (abridged):
The GLM Procedure
Dependent Variable: Weight
Sum of
Source DF Squares Mean Square F Value Pr > F
Model 1 1681.122953 1681.122953 3.73 0.0702
Error 17 7654.613889 450.271405
Corrected Total 18 9335.736842
R-Square Coeff Var Root MSE Weight Mean
0.180074 21.21402 21.21960 100.0263
Source DF Type III SS Mean Square F Value Pr > F
Sex 1 1681.122953 1681.122953 3.73 0.0702
Level of --------Weight--------
Sex N Mean Std Dev
F 9 90.111111 19.383914
M 10 108.950000 22.727186
How to read it:
- The boys are about 18.8 pounds heavier on average.
- Pr > F = 0.0702 — above the usual 0.05 threshold, so with only 19 students this difference isn't statistically significant.
- R-Square 0.18 — sex alone explains 18% of the variation in weight (compare 77% for height in the previous lesson).
- With one factor, the Type I and Type III tables (the full output shows both) are identical. With several factors and unequal group sizes they differ; Type III is usually the one to report.
For two groups, this F test is equivalent to a two-sample t test
(PROC TTEST): F equals t squared.
More factors and comparisons
proc glm data=sashelp.class;
class sex;
model weight = sex height / solution;
lsmeans sex / pdiff cl;
run;
quit;
model weight = sex heightmixes a factor and a numeric covariate (analysis of covariance) — the sex difference adjusted for height.a*bin aMODELadds an interaction.lsmeans ... / pdiffcompares adjusted group means; addadjust=tukeyfor many groups.solutionprints the parameter estimates.
Beyond GLM
PROC MIXEDandPROC GLIMMIX— random effects and repeated measures (common in clinical trials).PROC NPAR1WAY— non-parametric tests (Wilcoxon, Kruskal-Wallis).PROC ANOVA— older, for balanced designs only; prefer GLM.