Skip to main content
v2026.11,858 entries · CC-BY 4.0

ANOVA in SAS: PROC ANOVA vs PROC GLM, Step by Step

How to run ANOVA in SAS: SAS’s own rule for choosing PROC ANOVA or PROC GLM, a documented CLASS/MODEL example and how to read the output.

Written and maintained by CASRAI Editorial Board

Last updated

To run an analysis of variance in SAS you choose between two procedures, PROC ANOVA and PROC GLM, and the choice matters more than the code. SAS’s own documentation recommends PROC ANOVA “only for balanced data” and describes PROC GLM as “the flagship tool for classical analysis of variance in SAS/STAT software”. This guide gives that decision rule first, then a step-by-step run, the output tables, and what to do when things go wrong.

What ANOVA in SAS is used for in research

Analysis of variance tests whether the means of an outcome differ across the levels of one or more categorical factors. In SAS/STAT, both PROC ANOVA and PROC GLM do this. PROC GLM “performs analysis of variance by using least squares regression to fit general linear models”, and the same procedure also handles regression, analysis of covariance and repeated-measures designs. For the statistics behind the test, see the related guides on Tukey’s HSD test and split-plot designs.

PROC ANOVA or PROC GLM?

Use PROC ANOVA when every combination of factor levels has the same number of observations (a balanced design). Use PROC GLM when the design may be unbalanced. This is SAS’s own guidance, not a convention of this site:

  • “In general, however, the ANOVA procedure is recommended only for balanced data.”
  • “If you use ANOVA to analyze a design that is not balanced, you must assume responsibility for the validity of the output.”
  • If you are not sure the design is balanced, you probably need the framework of general linear models in the GLM procedure.

The documentation names two exceptions where PROC ANOVA is still fine: all one-way models, “regardless of how unbalanced the cell counts are”, and Latin squares, which do not have data in all cells.

In practice this means that research data with dropouts, missing cells or unequal group sizes in a two-way or larger design should go to PROC GLM. When in doubt, run the model in PROC GLM.

Install or access (official source only)

PROC ANOVA and PROC GLM are part of SAS/STAT, so you need a SAS installation that includes it, for example through your institution. To learn without an institutional licence, SAS states that SAS OnDemand for Academics is “a free, cloud-based learning environment”. It runs SAS Studio in a web browser, independent learners can sign up, and registration is at welcome.oda.sas.com (checked 2026-10-29).

Step-by-step: run an ANOVA in SAS

The code below follows the structure of the SAS/STAT PROC ANOVA example (Example 29.1, a pain-relief experiment with a blocking factor and two treatment factors). The data set name PainRelief and the variable names come from that example.

  1. Put your data in a SAS data set with one row per observation: one column for the outcome and one column for each factor.
  2. Start the procedure and name the data set with the DATA= option. The statement form is PROC ANOVA <options>;. If you omit DATA=, SAS uses the most recently created data set, so name it explicitly.
  3. List every factor in a CLASS statement so SAS treats it as categorical.
  4. Write the model in a MODEL statement, outcome on the left and effects on the right.
  5. End with run; and submit the program.
proc anova data=PainRelief;
   class PainLevel Codeine Acupuncture;
   model Relief = PainLevel Codeine|Acupuncture;
run;

Here Codeine|Acupuncture asks for both main effects and their interaction. For a one-way design, one factor goes in CLASS and the MODEL statement reads outcome = factor.

For an unbalanced design, name the same data set in PROC GLM instead (the statement form is PROC GLM <options>; and it also takes DATA=). PROC GLM accepts the same style of CLASS and MODEL statements for a standard ANOVA.

Useful PROC ANOVA statement options

  • DATA= names the input data set.
  • ORDER=DATA | FORMATTED | FREQ | INTERNAL sets the order of class levels; the default is FORMATTED.
  • OUTSTAT= names an output data set holding sums of squares, degrees of freedom, F statistics and probability levels for each effect.
  • NOPRINT suppresses the normal results display.
  • PLOTS=NONE suppresses the default grouped box plot.
  • NAMELEN=n sets the length of effect names, from 20 to 200 characters; the default is 20.

Output and how to read it

The pain-relief example produces three tables:

  • Class Level Information lists each classification variable, its number of levels and its values, plus the number of observations read and used (32 each in the example). Check this first: it is the quickest way to catch a data-entry or DATA step error in the design structure.
  • ANOVA table shows the model, error and corrected total sources with degrees of freedom, sums of squares, mean squares and the overall F test, followed by R-Square, Coefficient of Variation, Root MSE and the mean of the outcome.
  • Tests of effects gives an F test for each term in the model, including the interaction. In the example the blocking effect and both main effects are significant, and the interaction is significant at the 90% level (p = 0.0923) but not at the 95% level.

Read the interaction row before the main effects: when an interaction is present, a main effect alone can be misleading. If the overall F test is significant and you need to know which groups differ, follow up with a post-hoc procedure such as Tukey’s HSD test.

Troubleshooting

  • Results look wrong on unequal group sizes. You probably used PROC ANOVA on an unbalanced design. SAS says you must then assume responsibility for the validity of the output; switch to PROC GLM.
  • Unexpected number of observations. Compare observations read with observations used in Class Level Information.
  • No plots appear. “ODS Graphics must be enabled before plots can be requested.” The PLOTS= option has no effect until it is.
  • Levels appear in an unexpected order. ORDER= defaults to FORMATTED; use ORDER=DATA, FREQ or INTERNAL to change it.
  • Long effect names are truncated. Raise NAMELEN= above its default of 20.

Free alternatives

Option What to know Guide
SAS OnDemand for Academics Free, cloud-based SAS learning environment; SAS Studio in the browser (per SAS) This guide
R Open-source statistical language Running ANOVA in R
Python (statsmodels) Open-source library ANOVA in Python with statsmodels

If your department uses other packages, CASRAI also has ANOVA guides for Minitab and SPSS.

FAQ

What is the difference between PROC ANOVA and PROC GLM?

PROC ANOVA is recommended only for balanced data. PROC GLM fits general linear models by least squares and is SAS’s flagship tool for classical analysis of variance, so it is the safer choice when cell counts differ.

Can I use PROC ANOVA for a one-way design with unequal group sizes?

Yes. SAS lists all one-way models as an exception, regardless of how unbalanced the cell counts are.

How do I run ANOVA in SAS for free?

SAS OnDemand for Academics is a free, cloud-based learning environment that runs SAS Studio in a browser.

Why do my plots not show?

ODS Graphics must be enabled before plots can be requested with the PLOTS= option.

Sources (official docs)

All sources are SAS documentation and were checked on 2026-10-29.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about ANOVA in SAS: PROC ANOVA vs PROC GLM, Step by Step

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →