[The technical details are largely a restatement of the Technical Appendix of Littell RC, Henry PR, and Ammerman CB (1998), "Statistical Analysis of Repeated Measures Data Using SAS Procedures", Journal of Animal Science, 76, 1216-1231.]
The random and repeated statements of SAS's PROC MIXED have different roles. The random statement identifies random effects. The repeated statement specifies the structure of the within subject errors. They are not interchangeable. However, there are overspecified models that can be specified by using a random or repeated statement alone. Unfortunately, one such model is the commonly encounterd repeated measures with compound symmetry. This has the potential of leading to confusion over the proper use of the two types of statements.
The simple answer to why SAS's PROC MIXED can seem so confusing is that it's so powerful, but there's more to it than that. Early on, many guides to PROC MIXED present an example of fitting a compound symmetry model to a repeated measures study in which subjects (ID) are randomized to one of many treatments (TREAT) and then measured at multiple time points (PERIOD). The command language to analyze these data can be written
proc mixed; class id treat period; model y=treat period treat*period; repeat period/sub=id(treat) type=cs;or
proc mixed; class id treat period; model y=treat period treat*period; random id(treat);
Because both sets of command language produce the correct analysis, this immediately raises confusion over the roles of the repeated and random statements, In order to sort this out, the underlying mathematics must be reviewed. Once the reason for the equivalence is understood, the purposes of the repeated and random statements will be clear.
PROC MIXED is used to fit models of the form
For the repeated measures example,
The variance of yijk is
The covariance between any two observations is
Under the assumption of compound symmetry, cov(eijk,eijn) is σe2+σ, for k=n, and σe2, otherwise. It therefore follows that
The model is redundant because σu2 and σe2 occur only in the sum σu2 + σe2, so the sum σu2 + σe2 can be estimated, but σu2 and σe2 cannot be estimated individually. The command language file with the random statement resolves the redundancy by introducing the u-s into the model and treating the repeated measures as independent. The command language file with the repeated statement resolves the redundancy by removing the u-s from the model.
Littel et al. point out that a similar redundancy exists for the unstructured covariance matrix (TYPE=UN), but there is no reduncancy for an auto-regressive covariance structure (TYPE=AR1). In the latter case, both random and repeated statements should be used. See their article for additional details.