SAS Library
PROC ANOVA and PROC GLM Summary (for Analysis of Variance)


This page was adapted from a page of the same name created by Professor Michael Friendly of York University .  We thank Professor Friendly for permission to adapt and distribute this page via our web site.


This is meant to be a brief summary of the syntax of the most widely used statements with PROC ANOVA and PROC GLM. There are actually more statements and options that can be used with proc ANOVA and GLM -- you can find out by typing HELP GLM in the command area on the main SAS Display Manager Window.

In the statements below, uppercase is used for keywords, lowercase for things you fill in. Variable names are no more than 8 chars. in length.

PROC ANOVA

PROC ANOVA handles only balanced ANOVA designs.

PROC ANOVA DATA=datasetname;
     CLASS factorvars;
     MODEL responsevar = factorvars;   /* See below                  */
     MEANS factorvars  / BON           /* Bonferroni t-tests,
                                                         g=r(r-1)/2  */
                         T or LSD      /* Unprotected t-tests        */
                         TUKEY         /* Tukey studentized range    */
                         SCHEFFE       /* Scheffe contrasts          */
                         ALPHA=pvalue  /* default: 5%                */
                         CLDIFF        /* Confidence limits          */
                         LINES         /* Non-significant subsets    */
                         ;     /* use LINES or CLDIFF                */

PROC GLM

PROC GLM handles any ANOVA/regression/ANCOVA design.

PROC GLM   DATA=datasetname;
     CLASS factorvars;
e.g. CLASS A B SEX;

     MODEL responsevar = factorvars
                       / options   ;   /* Not needed yet             */
     RANDOM factorvars  / TEST;        /* If any random factors, list
                                          then here (after MODEL)    */
     TEST H=effects E=effect;          /* To specify an error term other
                                          than the residual MS       */
eg,  TEST H=A B  E=AB;                 /* 2-way design with A,B random */

     MEANS factorvars  / options   ;   /* same as for ANOVA          */
     LSMEANS factorvars                /* Least squares & adjusted
                                           means for ANCOVA          */
                 / STDERR              /*  .. and std errors         */
                   PDIFF ;             /*  ... and p-values for diff */

     CONTRAST 'label' factor  weights ;
eg,  CONTRAST 'Linear' SUGAR  -3  -1   1  3 ;
     CONTRAST 'Quad  ' SUGAR   1  -1  -1  1 ;

     ESTIMATE 'name' effect values... / options;    /* Only with GLM */
     The ESTIMATE statement constructs and tests linear combinations
     (predicted values and contrasts) of the parameters.

eg,  ESTIMATE 'A1 vs A2'   A    1  -1  0  0 / divisor=2;
     ESTIMATE 'A2 vs A3,4' A    0   2 -1 -1 / divisor=2;

     OUTPUT OUT=datasetname  P=fitvar       /* Predicted values      */
                             R=residvar ;   /* Residuals             */
     REPEATED  factorname levels(levelvalue) contrast;

Models

These illustrate types of MODEL statements that ANOVA and GLM can handle. (Assume A, B, C are class variables; X1, X2, X3 are quantitative, regression variables)

     MODEL Y = X1;                     /* Simple linear regression   */

     MODEL Y = X1 X2 X3;               /* Multiple regression        */

     MODEL Y = X1 X1*X1 X1*X1*X1;      /* Polynomial regression      */

     MODEL Y = A;                      /* One way anova              */

     MODEL Y = A B;                    /* Two-way, main effects only */

     MODEL Y = A B A*B;                /* Two-way, factorial with
                                          interaction                */

     MODEL Y = A | B;                  /* Two-way, same as above     */

     MODEL Y = A B C A*B A*C           /* Three-way, complete        */
               B*C A*B*C;              /* factorial                  */

     MODEL Y = A | B | C;              /* The same, using "|" notation */

Contrasts

The following table gives coefficients for contrasts to represent linear, quadratic, etc. trend of a quantitative factor on a CONTRAST statement. E.g., for a 3-level factor, use

    CONTRAST 'linear'  DELAY  -1  0  1;
    CONTRAST 'quad'    DELAY   1 -2  1;

Contrast coefficients for Trend Analysis

(Valid when X levels are equally spaced & N's are equal)

                 Coefficients, c(i)

  r    Trend   X=1   2   3   4   5   6   7       sum c(i)**2
  ---------------------------------------------------------
  3    Linear   -1   0   1                              2
       Quad      1  -2   1                              6
       --------------------------------------------------
  4    Linear   -3  -1   1   3                         20
       Quad      1  -1  -1   1                          4
       Cubic    -1   3  -3   1                         20
       --------------------------------------------------
  5    Linear   -2  -1   0   1   2                     10
       Quad      2  -1  -2  -1   2                     14
       Cubic    -1   2   0  -2   1                     10
       Quartic   1  -4   6  -4   1                     70
       --------------------------------------------------
  6    Linear   -5  -3  -1   1   3   5                 70
       Quad      5  -1  -4  -4  -1   5                 84
       Cubic    -5   7   4  -4  -7   5                180
       Quartic   1  -3   2   2  -3   1                 28
       --------------------------------------------------
  7    Linear   -3  -2  -1   0   1   2   3             28
       Quad      5   0  -3  -4  -3   0   5             84
       Cubic    -1   1   1   0  -1  -1   1              6
       Quartic   3  -7   1   6   1  -7   3            154
       --------------------------------------------------
  8    Linear   -7  -5  -3  -1   1   3   5  7         168
       Quad      7   1  -3  -5  -5  -3   1  7         168
       Cubic    -7   5   7   3  -3  -7  -5  7         264
       Quartic   7 -13  -3   9   9  -3 -13  7         616
       --------------------------------------------------
  9    Linear   -4  -3  -2  -1   0   1   2   3   4     60
       Quad     28   7  -8 -17 -20 -17  -8   7  28   2772
       Cubic   -14   7  13   9   0  -9 -13  -7  14    990
       Quartic  14 -21 -11   9  18   9 -11 -21  14   2002
       --------------------------------------------------

This page was adapted from a page of the same name created by Professor Michael Friendly of York University .  We thank Professor Friendly for permission to adapt and distribute this page via our web site.

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.