A repeated measures ANOVA is used to determine whether or not there is a statistically significant difference between the means of three or more groups in which the same subjects show up in each group.
This tutorial provides a step-by-step example of how to perform a repeated measures ANOVA in SAS.
Step 1: Create the Data
Suppose a researcher want to know if four different drugs lead to different reaction times. To test this, he measures the reaction time of five patients on the four different drugs.
The reaction times are shown below:

We can use the following code to create this dataset in SAS:
/*create dataset*/
data my_data;
input Subject Drug Value;
datalines;
1 1 30
1 2 28
1 3 16
1 4 34
2 1 14
2 2 18
2 3 10
2 4 22
3 1 24
3 2 20
3 3 18
3 4 30
4 1 38
4 2 34
4 3 20
4 4 44
5 1 26
5 2 28
5 3 14
5 4 30
;
run;
Step 2: Perform the Repeated Measures ANOVA
Next, we’ll use proc glm to perform the repeated measures ANOVA:
/*perform repeated measures ANOVA*/
proc glm data=my_data;
class Subject Drug;
model Value = Subject Drug;
run;
Step 3: Interpret the Results
We can analyze the ANOVA table in the output:

The only value we’re interested in is the F value and corresponding p-value for Drug since we want to know if the four different drugs lead to different reaction times.
From the output we can see:
- The F Value for Drug: 24.76
- The p-value for Drug: <.0001
Recall that a repeated measures ANOVA uses the following null and alternative hypotheses:
- H0: All group means are equal.
- HA: At least one group mean is different from the rest.
Since the p-value for Drug (<.0001) is less than α = .05, we reject the null hypothesis.
This means we have sufficient evidence to say that the mean response time is not equal among the four different drugs.
Additional Resources
The following tutorials provide additional information about repeated measures ANOVAs:
Introduction to the Repeated Measures ANOVA
How to Perform a Repeated Measures ANOVA By Hand
One-Way ANOVA vs. Repeated Measures ANOVA: The Difference
Hi, I would like to fit an ANOVA with repeated measurement. I have data that measure motivation at three timepoints (after three different treatments), but I have also a control group. What would my model look like then?
Hi Veerle…To perform a repeated measures ANOVA in SAS with your data, you need to account for both the within-subjects factor (timepoints or treatments) and the between-subjects factor (control vs. treatment group). Here’s how you can set up your model:
### 1. **Data Structure**
Your dataset should be in a “long format” where each row corresponds to one measurement for a subject. Example:
| Subject | Group | Timepoint | Motivation |
|———|——–|———–|————|
| 1 | Control| 1 | 8 |
| 1 | Control| 2 | 7 |
| 1 | Control| 3 | 6 |
| 2 | Treatment| 1 | 10 |
| 2 | Treatment| 2 | 11 |
| 2 | Treatment| 3 | 12 |
– `Subject`: Identifies each participant.
– `Group`: Indicates the control or treatment group.
– `Timepoint`: Represents the repeated measures (1, 2, 3).
– `Motivation`: Outcome variable.
### 2. **Model Specification**
The model will include:
– A **within-subject factor** for `Timepoint` (repeated measures).
– A **between-subject factor** for `Group` (control vs. treatment).
– Interaction effects between `Timepoint` and `Group` to examine if the motivation changes over time differ between the groups.
### 3. **SAS Code**
You can use the `PROC MIXED` procedure for a repeated measures ANOVA:
“`sas
proc mixed data=your_data method=REML;
class Subject Group Timepoint;
model Motivation = Group Timepoint Group*Timepoint / ddfm=kr;
repeated Timepoint / subject=Subject type=cs;
lsmeans Group*Timepoint / pdiff=all cl;
run;
“`
### Explanation of the Code
1. **`CLASS` Statement**: Specifies the categorical variables (`Subject`, `Group`, `Timepoint`).
2. **`MODEL` Statement**: Includes main effects (`Group`, `Timepoint`), and their interaction (`Group*Timepoint`).
3. **`REPEATED` Statement**: Defines the repeated measures structure:
– `Timepoint`: Within-subject factor.
– `Subject=Subject`: Identifies the unit of repeated measurement.
– `type=cs`: Specifies a compound symmetry (CS) covariance structure. Alternatives include `AR(1)` or `UN` depending on your data’s characteristics.
4. **`LSMEANS` Statement**: Computes least-squares means for the interaction of `Group` and `Timepoint`, with pairwise comparisons (`pdiff=all`).
### 4. **Choosing the Covariance Structure**
– **Compound Symmetry (`cs`)**: Assumes equal correlations between all timepoints.
– **Autoregressive (`AR(1)`)**: Assumes correlations diminish over time.
– **Unstructured (`UN`)**: Makes no assumptions about correlation but may require more data.
You can compare models with different covariance structures using the Akaike Information Criterion (AIC) or Bayesian Information Criterion (BIC) in the output.
### 5. **Output Interpretation**
– **Fixed Effects**: Look for significant main effects of `Timepoint`, `Group`, and their interaction.
– **Random Effects**: Ensure the repeated measures structure fits well (via covariance parameters).
– **LSMEANS**: Interpret group differences at each timepoint or overall trends.
### Example Dataset for Testing
If you have sample data ready, you can test this and adjust based on specific model needs.