# Repeated measures with SAS: Common mistakes in PROC GLM

When I teach students how to use SAS to do a repeated measures Analysis of Variance, it almost seems like those crazy foreign language majors I knew in college who were learning Portuguese and Italian at the same time.

I teach how to do a repeated measures ANOVA using both PROC GLM and PROC MIXED. It seems very likely in their careers my students will run into both general linear models and mixed models. The problem is that they confuse the two and the result is buggy code.

Let’s start with mistakes in PROC GLM today. Next time we can discuss mistakes in PROC MIXED.

Let’s say I have the simplest possible analysis – I’ve given the same students a pre- and a post-test and want to see if there has been a significant increase from time one to time two.

This will work just fine:

**proc glm data =mydata.fl_pre_post ; model pretest posttest = /nouni ; repeated time 2 ;**

Coding the repeated statement like this will also work

**repeated time 2 (1 2) ;**

So will

**repeated time ;**

It almost seems as if anything or nothing after the variable name will work. That’s not true. First of all,

**repeated time 2 (a b) ; IS WRONG **

… and will give you an error – *Syntax error, expecting one of the following: a numeric constant, a datetime constant. *

“Levels gives the number of levels associated with the factor being defined. When there is only one within-subject factor, the number of levels is equal to the number of dependent variables. In this case,

SAS 9.2 Users Guidelevelsis optional. When more than one within-subject factor is defined, however,levelsis required,”

So, this explains why you can be happily using your repeated statement without bothering to specify the number of levels for a factor and then one day it doesn’t work. WHY? Because now you have two within-subject factors and you need to specify the number of levels but you don’t know that. This is why, when teaching I always include the number of levels. It will never cause your program to fail, even if it is unnecessary sometimes.

One more cool thing about the repeated statement for PROC GLM, you can do a planned contrast super easy. Let’s say I have done 3 tests, a pretest, a post-test and a follow-up. I want to compare the posttest and followup to the pretest.

**proc glm data =mydata.fl_tests ; model pretest posttest follow = /nouni ;repeated test_time 3 contrast (1) /summary ;**

What this will do is compare each of the other time points to the first one. A common mistake students make is to use a CONTRAST statement here with test_time. This will NOT work, although it will work with PROC MIXED, but that is a story for another day.