Introduction
Clinical trials frequently collect the same outcome repeatedly from each participant.
For example, a clinical trial may measure a patient's blood pressure, symptom score, biomarker concentration, pulmonary function, or disease activity at baseline and at Weeks 2, 4, 8, 12, and 24.
These observations are not independent.
Measurements from the same patient tend to be correlated because they come from the same underlying individual.
This correlation is the defining statistical feature of repeated-measures data.
Why Ordinary ANOVA Is Not Enough
Suppose 100 patients are randomized to two treatment groups and measured at five post-baseline visits.
The resulting dataset contains approximately:
post-baseline observations.
It would be tempting to treat these 500 observations as independent.
That would generally be inappropriate.
The five observations from Patient 001 are related to one another. The five observations from Patient 002 are also related to one another. But Patient 001 and Patient 002 are different individuals.
The correlation structure can therefore be represented conceptually as:
The Longitudinal Data Structure
A typical repeated-measures dataset is stored in long format.
| USUBJID | Treatment | Visit | Outcome |
|---|---|---|---|
| 001 | Drug A | Baseline | 72 |
| 001 | Drug A | Week 4 | 65 |
| 001 | Drug A | Week 8 | 61 |
| 001 | Drug A | Week 12 | 58 |
| 002 | Placebo | Baseline | 70 |
| 002 | Placebo | Week 4 | 69 |
| 002 | Placebo | Week 8 | 71 |
| 002 | Placebo | Week 12 | 70 |
Each row represents one patient at one measurement occasion.
The patient identifier tells PROC MIXED which observations belong to the same subject.
The Basic Repeated-Measures Model
A simple longitudinal model can be written as:
where:
- \(Y_{ij}\) is the outcome for patient \(i\) at visit \(j\)
- \(\beta_0\) is an intercept
- \(\beta_1\) represents treatment effects
- \(\beta_2\) represents visit effects
- \(\beta_3\) represents the treatment-by-visit interaction
- \(\epsilon_{ij}\) represents residual variation
The critical additional feature is that the residuals from the same patient are allowed to be correlated.
What PROC MIXED Does
PROC MIXED estimates two broad components:
- Fixed effects describing systematic differences in the population mean.
- Covariance parameters describing variability and correlation among repeated observations.
This separation is fundamental to understanding PROC MIXED.
A First PROC MIXED Example
Suppose the analysis dataset is called analysis
and contains:
USUBJID— patient identifierTRT01P— treatment groupAVISIT— analysis visitAVAL— analysis outcome
A basic repeated-measures model might be:
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT;
model AVAL =
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=un;
run;
This is one of the most important PROC MIXED patterns for clinical programmers to understand.
Breaking Down the PROC MIXED Syntax
The first line invokes PROC MIXED:
proc mixed data=analysis method=reml;
The DATA= option identifies the input dataset.
The METHOD=REML option requests restricted maximum
likelihood estimation of the covariance parameters.
REML is commonly used when estimating covariance parameters in linear mixed models.
The CLASS Statement
class USUBJID TRT01P AVISIT;
Categorical variables should generally be included in the CLASS statement.
For example:
| Variable | Role |
|---|---|
| USUBJID | Subject identifier |
| TRT01P | Treatment group |
| AVISIT | Categorical analysis visit |
Whether visit should be modeled categorically or continuously is an important modeling decision.
Categorical Versus Continuous Time
If visit is categorical:
class AVISIT; model AVAL = TRT01P AVISIT TRT01P*AVISIT / ddfm=kr;
the model estimates a separate mean at each visit.
If time is treated as continuous:
model AVAL = TRT01P WEEK TRT01P*WEEK / ddfm=kr;
the model instead imposes a functional relationship between outcome and time.
The MODEL Statement
The MODEL statement specifies the fixed-effects portion of the model.
model AVAL =
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
This model contains:
- Overall treatment effect
- Overall visit effect
- Treatment-by-visit interaction
The interaction is often particularly important in longitudinal clinical trials.
Why Treatment-by-Visit Matters
Suppose the treatment difference is small at Week 2 but substantial at Week 12.
The treatment effect therefore changes over time.
That pattern is represented by:
Without the interaction, the model imposes a common treatment difference across all visits.
With the interaction, the treatment difference can vary by visit.
Visualizing a Typical Longitudinal Treatment Effect
Illustrative data only. In an actual clinical trial, estimated means and confidence intervals would be obtained from the fitted model.
The REPEATED Statement
The REPEATED statement tells PROC MIXED how observations within a subject are correlated.
repeated AVISIT /
subject=USUBJID
type=un;
This contains three important pieces:
| Component | Meaning |
|---|---|
| AVISIT | Repeated measurement dimension |
| SUBJECT=USUBJID | Defines the independent clustering unit |
| TYPE=UN | Specifies an unstructured covariance matrix |
Why SUBJECT= Matters
Consider this model:
repeated AVISIT / subject=USUBJID type=un;
PROC MIXED understands that the observations for Patient 001 belong together.
The repeated observations for Patient 001 are therefore allowed to have correlation.
Patient 002 has a separate covariance cluster.
Conceptually:
where \(\Sigma\) represents the within-patient covariance matrix.
Understanding the Covariance Matrix
Suppose there are four visits.
An unstructured covariance matrix might look like:
Every variance and covariance is estimated separately.
This is extremely flexible.
But flexibility comes at a cost.
Common Covariance Structures
PROC MIXED provides several covariance structures that are useful for longitudinal analyses.
| TYPE= | Structure | General Interpretation |
|---|---|---|
| UN | Unstructured | Each variance and covariance is estimated separately |
| CS | Compound symmetry | Common variance and common covariance |
| AR(1) | First-order autoregressive | Correlation decreases as visits become farther apart |
| TOEP | Toeplitz | Correlation depends on lag but is not constrained geometrically |
| VC | Variance components | Independent residual variances by repeated level under the specified structure |
Unstructured Covariance
The most flexible commonly used structure is:
type=un
For \(q\) repeated visits, an unstructured covariance matrix contains:
covariance parameters.
For five visits:
parameters are required.
For ten visits:
parameters are required.
Compound Symmetry
Compound symmetry assumes a common variance and a common covariance across visits.
repeated AVISIT /
subject=USUBJID
type=cs;
Conceptually:
This structure is parsimonious but restrictive.
It assumes that the correlation between Week 4 and Week 8 is the same as the correlation between Week 4 and Week 24.
AR(1) Covariance
An autoregressive structure assumes that observations closer together in time are more strongly correlated.
repeated AVISIT /
subject=USUBJID
type=ar(1);
The correlation is approximately:
where \(\rho\) is the lag-one correlation.
Thus:
- Adjacent visits have correlation \(\rho\)
- Two visits apart have correlation \(\rho^2\)
- Three visits apart have correlation \(\rho^3\)
Toeplitz Covariance
Toeplitz covariance structures allow the covariance to depend on the lag without requiring the geometric decay imposed by AR(1).
repeated AVISIT /
subject=USUBJID
type=toep;
For example, observations one visit apart can share one covariance, observations two visits apart another covariance, and so forth.
This provides more flexibility than CS while potentially using fewer parameters than UN.
Choosing a Covariance Structure
There is no universally correct covariance structure.
Selection should be based on:
- Study design
- Number and spacing of visits
- Scientific plausibility
- Model convergence
- Information criteria
- Prespecified statistical-analysis-plan requirements
- Interpretability
Comparing Covariance Structures
Suppose the analyst fits:
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT;
model AVAL =
TRT01P AVISIT TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=un;
run;
and then compares it with:
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT;
model AVAL =
TRT01P AVISIT TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=ar(1);
run;
The analyst can examine fit statistics such as AIC and BIC.
| Criterion | General Purpose |
|---|---|
| AIC | Balances model fit against model complexity |
| AICC | Small-sample corrected AIC |
| BIC | Penalizes model complexity more strongly than AIC |
REML Versus ML
PROC MIXED commonly uses:
method=reml
for estimation of covariance parameters.
REML accounts for the loss of degrees of freedom associated with estimating fixed effects.
Maximum likelihood can be specified using:
method=ml
The distinction becomes particularly important when comparing models with different fixed-effects structures.
Kenward–Roger Degrees of Freedom
A common option in clinical-trial mixed models is:
ddfm=kr
This requests the Kenward–Roger method for denominator degrees of freedom and associated small-sample adjustments.
For example:
model AVAL =
TRT01P AVISIT TRT01P*AVISIT
/ ddfm=kr;
The method can improve the finite-sample behavior of tests and estimated fixed-effect covariance matrices in mixed models.
Why DDFM Matters
Mixed models do not always have a simple denominator degrees-of-freedom calculation.
This is especially relevant when:
- There are relatively few subjects
- Covariance parameters are estimated
- The design is unbalanced
- There are missing observations
- Different treatment groups have different numbers of observations
The choice of denominator degrees of freedom can therefore affect p-values and confidence intervals.
LS-Means
After fitting the model, analysts often want adjusted treatment means.
PROC MIXED provides these using the LSMEANS statement.
lsmeans TRT01P / diff cl;
This requests least-squares means for treatment, pairwise differences, and confidence limits.
For longitudinal trials, a more useful request is often treatment by visit:
lsmeans TRT01P*AVISIT /
diff
cl;
This produces adjusted means and comparisons for each treatment-by-visit combination.
Why LS-Means Are Important
The observed arithmetic mean and the model-based LS-mean are not necessarily the same.
The LS-mean represents a model-adjusted estimate of the mean outcome for a specified factor combination.
This is particularly useful when:
- Baseline covariates are included
- The dataset is unbalanced
- There are missing observations
- Interactions are present
- Other fixed effects are included
Treatment Difference at a Specific Visit
Suppose the primary question is:
The corresponding model-based comparison can be requested using:
lsmeans TRT01P*AVISIT /
diff
cl;
However, analysts often want only the relevant treatment comparison rather than every possible pair.
The PDIFF option and other LSMEANS options can be combined with appropriate SLICE or ESTIMATE/LSMESTIMATE statements depending on the desired contrast.
SLICE Effects
When an interaction is present, it is often useful to examine treatment effects within individual visits.
For example:
lsmeans TRT01P*AVISIT /
slice=AVISIT
diff
cl;
This asks for treatment comparisons within levels of the visit factor.
Adding a Baseline Covariate
A common clinical-trial model adjusts post-baseline outcomes for baseline measurements.
Suppose the baseline value is BASE.
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT;
model AVAL =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=un;
lsmeans TRT01P*AVISIT /
diff
cl;
run;
This is conceptually similar to a repeated-measures ANCOVA.
Why Baseline Adjustment Can Be Useful
Suppose two patients have different baseline values:
| Patient | Baseline | Week 12 |
|---|---|---|
| 001 | 80 | 60 |
| 002 | 120 | 90 |
Both patients may show a similar proportional change even though their absolute values differ.
Including baseline as a covariate can improve precision and account for baseline heterogeneity.
Change From Baseline as the Dependent Variable
Another common analysis uses change from baseline:
The model then becomes:
model CHG =
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
Whether to analyze the raw post-baseline outcome with baseline adjustment or analyze change from baseline depends on the estimand, SAP, disease area, endpoint characteristics, and study design.
The MMRM Framework
A particularly important application of PROC MIXED is the Mixed Model for Repeated Measures (MMRM).
A typical MMRM includes:
- Treatment
- Visit
- Treatment-by-visit interaction
- Baseline covariate where appropriate
- Within-subject covariance structure
A representative SAS implementation is:
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT;
model CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=un;
lsmeans TRT01P*AVISIT /
diff
cl;
run;
Why MMRM Is Popular in Clinical Trials
MMRM has several useful properties for longitudinal clinical-trial data.
- It models repeated observations directly.
- It accounts for within-patient correlation.
- It accommodates unequal numbers of observations per patient.
- It can use information from patients with incomplete follow-up.
- It provides model-based treatment comparisons at individual visits.
- It does not require a single imputed value for every missing observation.
Missing Data
Missing observations are extremely common in longitudinal trials.
For example:
| Patient | Week 4 | Week 8 | Week 12 | Week 24 |
|---|---|---|---|---|
| 001 | Observed | Observed | Observed | Observed |
| 002 | Observed | Missing | Observed | Missing |
| 003 | Observed | Observed | Missing | Missing |
PROC MIXED does not require every subject to have observations at every visit.
This is one of its major advantages over traditional complete-case repeated- measures approaches.
MMRM and the Missing-at-Random Assumption
The validity of likelihood-based inference under incomplete longitudinal data depends on assumptions concerning the missingness mechanism.
A commonly invoked assumption is:
Under MAR, after conditioning on observed information included in the model, the probability of missingness does not depend on the unobserved value itself.
Example of Early Treatment Discontinuation
Consider a patient who contributes:
but discontinues treatment after Week 12.
The patient can still contribute information to the model.
PROC MIXED does not require artificial values at Weeks 16 and 24 merely to retain the patient.
This is fundamentally different from approaches that require complete longitudinal records.
But Missingness Still Requires Clinical Investigation
A model-based analysis should not be interpreted without understanding why data are missing.
Important reasons include:
- Adverse events
- Lack of efficacy
- Progressive disease
- Withdrawal of consent
- Loss to follow-up
- Administrative reasons
- COVID-era disruptions or other operational events
The mechanism behind missing data can be clinically important even when the primary analysis uses an MMRM.
Repeated Statement Versus Random Statement
One common source of confusion is the difference between:
random
and:
repeated
They are not interchangeable.
The RANDOM Statement
The RANDOM statement specifies random effects.
For example:
random intercept / subject=USUBJID;
This allows each patient to have their own random intercept.
Conceptually:
where \(b_i\) represents patient-specific random variation.
Random Slopes
A model can also allow individual patients to have different slopes over time.
random intercept WEEK /
subject=USUBJID
type=un;
This allows correlation between the patient-specific intercept and slope.
Such models can be useful when time is treated continuously and subject-specific growth trajectories are scientifically meaningful.
RANDOM Effects Versus REPEATED Covariance
A random-effects model and a repeated covariance model represent dependence in different ways.
| Feature | RANDOM | REPEATED |
|---|---|---|
| Purpose | Models random effects | Models within-subject covariance |
| Typical use | Random intercepts/slopes | Longitudinal residual covariance |
| Subject specification | SUBJECT= | SUBJECT= |
| Common clinical MMRM approach | Not necessarily required | Often central |
A Common MMRM Template
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT;
model CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=un;
lsmeans TRT01P*AVISIT /
diff
cl;
run;
This compact program contains most of the ingredients encountered in real-world clinical-trial longitudinal analyses.
Adding a Stratification Factor
Suppose randomization was stratified by geographic region.
The model could include the stratification factor:
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT REGION;
model CHG =
BASE
REGION
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=un;
lsmeans TRT01P*AVISIT /
diff
cl;
run;
Whether a particular stratification factor belongs in the primary analysis should follow the SAP and statistical methodology.
Covariate Adjustment
Continuous baseline covariates can also be incorporated.
For example:
model CHG =
BASE
AGE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
Categorical covariates should generally appear in the CLASS statement.
Interactions With Baseline Covariates
In some analyses, the effect of a baseline covariate may vary by treatment.
That could be represented by:
model CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
BASE*TRT01P
/ ddfm=kr;
Such terms should not be added simply because they improve a model's fit.
They should have a statistical or scientific justification.
Reference Coding and CLASS Variables
SAS's CLASS-variable parameterization determines how model coefficients are represented.
For example:
class TRT01P(ref="Placebo")
AVISIT(ref="Baseline");
This explicitly defines reference levels.
Reference-level choices can make parameter estimates easier to interpret.
Using ESTIMATE
The ESTIMATE statement can construct specific linear combinations of model parameters.
For example:
estimate "Treatment difference at Week 12"
TRT01P*AVISIT 1 -1
/ cl;
The exact coefficients depend on the CLASS-variable parameterization.
For complex models, LS-means and LSMESTIMATE are often easier to maintain because the desired comparisons can be expressed in terms of factor levels.
Using LSMESTIMATE
An example pattern is:
lsmestimate TRT01P*AVISIT
"Treatment difference at Week 12"
0 0 1 -1
/ cl;
Again, the coefficient vector must match the ordering produced by the model.
Outputting Results to Datasets
ODS OUTPUT is particularly useful for production clinical programming.
ods output LSMeans=lsmeans
Diffs=diffs
Tests3=tests3
CovParms=covparms;
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT;
model CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=un;
lsmeans TRT01P*AVISIT /
diff
cl;
run;
ods output close;
This is an important technique for integrating PROC MIXED into automated clinical-reporting pipelines.
Why ODS OUTPUT Matters
Instead of manually copying values from the SAS Results Viewer, production programs can capture model output directly into SAS datasets.
Those datasets can then be used to produce:
- Tables
- Listings
- Figures
- Statistical summaries
- Automated validation reports
Key PROC MIXED Output Tables
| Output | What It Contains |
|---|---|
| CovParms | Estimated covariance parameters |
| Tests3 | Type III tests of fixed effects |
| LSMeans | Estimated least-squares means |
| Diffs | Differences among LS-means |
| SolutionF | Fixed-effect parameter estimates |
| FitStatistics | Model fit criteria |
Reading the Covariance Parameters
Suppose the output contains covariance estimates such as:
| Parameter | Estimate |
|---|---|
| UN(1,1) | 25.4 |
| UN(2,1) | 14.8 |
| UN(2,2) | 31.2 |
These values describe the estimated variability and covariance among repeated measurements.
They are not treatment effects.
Reading Type III Tests
The Type III tests provide hypothesis tests for fixed effects.
For example:
| Effect | F Value | Pr > F |
|---|---|---|
| Treatment | 4.82 | 0.031 |
| Visit | 18.42 | <.001 |
| Treatment × Visit | 3.77 | 0.009 |
A statistically significant treatment-by-visit interaction indicates that the treatment effect is not constant across visits under the fitted model.
Do Not Stop at the Interaction P-Value
Suppose:
This indicates evidence that treatment differences vary by visit.
It does not directly answer:
- What is the treatment difference at Week 12?
- What is its confidence interval?
- What is the adjusted p-value?
Those questions require appropriate contrasts or LS-means.
Confidence Intervals
A treatment comparison should generally be interpreted using its estimate and confidence interval rather than relying only on the p-value.
For example:
with:
would indicate an estimated treatment difference of −5.8 units with the specified confidence interval.
The clinical interpretation depends on the endpoint and its direction.
Least-Squares Means Versus Raw Means
Suppose the raw observed means at Week 12 are:
| Treatment | Observed Mean |
|---|---|
| Drug A | 61.2 |
| Placebo | 65.8 |
The model-adjusted LS-means might instead be:
| Treatment | LS-Mean |
|---|---|
| Drug A | 60.7 |
| Placebo | 66.1 |
The difference is due to model adjustment.
Estimated Marginal Means Plot
This display illustrates the type of figure commonly produced from PROC MIXED LS-means. The values are simulated and are not actual clinical-trial results.
Building a Complete Clinical-Trial Program
A production program will usually contain several components.
Checking Convergence
A successful SAS program execution does not necessarily mean that the fitted model is scientifically or statistically satisfactory.
The programmer should inspect:
- Convergence status
- Covariance parameter estimates
- Warnings in the SAS log
- Boundary estimates
- Positive-definiteness issues
- Singularities
- Unexpected standard errors
When UN Does Not Converge
An unstructured covariance model may fail when:
- The number of visits is large relative to sample size.
- Some visits contain very few observations.
- There is substantial missingness.
- Correlation parameters are poorly identified.
- The data contain little information about certain covariance components.
Possible alternatives include more parsimonious structures such as:
type=cs type=ar(1) type=toep
However, the alternative should be selected according to the prespecified strategy or justified statistical methodology.
Unequal Numbers of Visits
A major advantage of PROC MIXED is that patients do not need to have identical numbers of observations.
For example:
| Patient | Number of Measurements |
|---|---|
| 001 | 6 |
| 002 | 6 |
| 003 | 4 |
| 004 | 3 |
| 005 | 6 |
PROC MIXED can use the available observations rather than automatically discarding every patient who lacks a complete record.
Unequal Visit Timing
There is an important distinction between categorical visit and actual elapsed time.
Suppose assessments occur at:
If AVISIT is treated categorically, the exact
spacing between these visits does not directly determine the mean structure.
If a continuous time variable is used, the spacing becomes part of the model.
Visit as a CLASS Variable
For a standard scheduled-visit MMRM:
class AVISIT;
model CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
The model makes no assumption that the treatment effect changes linearly between visits.
This flexibility is one reason categorical visit is common in clinical-trial MMRM analyses.
Continuous Time Model
A different model might use:
model CHG =
BASE
TRT01P
WEEK
TRT01P*WEEK
/ ddfm=kr;
This assumes a specified functional relationship between outcome and time.
If the true trajectory is strongly nonlinear, a simple linear time term may be inappropriate.
Polynomial Time Effects
A more flexible continuous-time model could include quadratic time:
model CHG =
BASE
TRT01P
WEEK
WEEK*WEEK
TRT01P*WEEK
TRT01P*WEEK*WEEK
/ ddfm=kr;
This allows curvature.
However, increasingly complex mean structures should be supported by the study's scientific objectives rather than added indiscriminately.
Post-Baseline Population
A common MMRM uses post-baseline records as the repeated observations and includes baseline separately as a covariate.
For example:
data mmrm;
set analysis;
where ANL01FL="Y"
and AVISITN > 0;
run;
The exact filtering criteria depend on the analysis dataset and SAP.
Example Analysis Dataset
USUBJID TRT01P AVISITN AVISIT BASE CHG 001 Drug A 4 Week 4 72 -7 001 Drug A 8 Week 8 72 -11 001 Drug A 12 Week 12 72 -14 001 Drug A 24 Week 24 72 -18 002 Placebo 4 Week 4 70 -1 002 Placebo 8 Week 8 70 1 002 Placebo 12 Week 12 70 0 002 Placebo 24 Week 24 70 2
This structure is suitable for a repeated-measures analysis because each patient contributes multiple post-baseline rows.
Sorting the Data
It is good programming practice to sort longitudinal analysis data by subject and analysis visit.
proc sort data=analysis out=analysis_sorted;
by USUBJID AVISITN;
run;
Sorting is especially useful for inspection and validation even when the procedure itself does not require a particular physical ordering in every situation.
Duplicate Records
Repeated-measures models require careful attention to duplicate observations.
For example, the following may indicate a problem:
001 Week 12 -14 001 Week 12 -15
The analyst should determine whether these represent:
- Duplicate records
- Unscheduled assessments
- Multiple measurements requiring a derivation rule
- Data-entry errors
The model should not simply be allowed to treat an accidental duplicate as another independent repeated observation.
Unscheduled Assessments
Clinical trials often contain unscheduled visits.
The analysis specification should define whether these observations are:
- Excluded
- Mapped to a nominal visit
- Used according to actual timing
- Used only for sensitivity analyses
This is an analysis-data derivation issue as much as it is a modeling issue.
Covariance Structure by Treatment
In some settings, the analyst may want different covariance structures by treatment group.
For example:
repeated AVISIT /
subject=USUBJID
type=un
group=TRT01P;
The GROUP= option permits covariance parameters to differ across groups.
This can be useful in some analyses but also increases model complexity.
Randomization Stratification Versus Covariance Grouping
These concepts should not be confused.
| Concept | Purpose |
|---|---|
| Stratification factor | Fixed-effect adjustment for design or prognostic factor |
| GROUP= in REPEATED | Allows covariance parameters to differ across groups |
Model Selection Workflow
Model Fit Statistics
Suppose three candidate models produce:
| Structure | AIC | AICC | BIC |
|---|---|---|---|
| CS | 1542.3 | 1543.0 | 1564.8 |
| AR(1) | 1538.6 | 1539.2 | 1561.1 |
| UN | 1534.1 | 1537.0 | 1580.2 |
There is no single criterion that should automatically determine the final model.
The analysis plan may specify, for example, a particular hierarchy of candidate structures and a selection criterion.
Why AICC Can Be Useful
AIC can favor overly complex models in smaller samples.
AICC applies a finite-sample correction.
This can be particularly useful when the number of covariance parameters is not negligible relative to the amount of information available.
Model Diagnostics
PROC MIXED analyses should also consider residual diagnostics.
Useful questions include:
- Are residuals approximately symmetric?
- Are there extreme outliers?
- Is variance changing substantially over time?
- Does the covariance structure appear plausible?
- Are there influential observations?
Formal diagnostic procedures should be proportionate to the role of the model in the study.
Residual Diagnostics
ODS GRAPHICS can be enabled for additional diagnostics.
ods graphics on;
proc mixed data=analysis method=reml;
class USUBJID TRT01P AVISIT;
model CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated AVISIT /
subject=USUBJID
type=un;
run;
ods graphics off;
Influential Patients
Because longitudinal models use multiple observations from each patient, individual patients can sometimes have substantial influence on parameter estimates.
A patient with:
- Very unusual baseline values
- Extreme longitudinal changes
- Many observations
- Unusual covariance behavior
may deserve additional investigation.
What Does a Treatment-by-Visit Interaction Mean?
Suppose the estimated treatment differences are:
| Visit | Drug A − Placebo |
|---|---|
| Week 4 | −1.2 |
| Week 8 | −3.8 |
| Week 12 | −6.4 |
| Week 24 | −8.1 |
The treatment effect appears to become progressively larger.
A significant interaction would be consistent with the hypothesis that treatment differences vary over time.
What If the Interaction Is Not Significant?
A nonsignificant treatment-by-visit interaction does not necessarily mean that there is no treatment benefit.
It means there is insufficient statistical evidence, under the specified model, that treatment differences vary across visits.
The interpretation of the treatment main effect then depends on the exact model, estimand, and analysis objective.
Estimated Treatment Difference at Week 24
Suppose the model produces:
with:
The model therefore estimates an 8.1-unit lower mean outcome for Drug A relative to Placebo at Week 24, subject to the endpoint's interpretation and the specified direction of benefit.
Multiple Comparisons
When treatment is compared at many visits, multiple statistical comparisons may arise.
PROC MIXED supports multiplicity adjustments for appropriate LS-means comparisons.
For example:
lsmeans TRT01P*AVISIT /
diff
adjust=tukey
cl;
Other adjustments may be appropriate depending on the comparison family and the statistical-analysis plan.
Producing a Treatment Profile From LS-Means
The model can produce adjusted means that are then plotted over time.
Conceptually:
This is often more appropriate for a clinical-trial report than simply plotting raw arithmetic means.
Example SAS Output Workflow
ods output
LSMeans=work.lsmeans
Diffs=work.diffs
CovParms=work.covparms
Tests3=work.tests3
SolutionF=work.solutionf
FitStatistics=work.fitstats;
proc mixed data=analysis method=reml;
class
USUBJID
TRT01P
AVISIT;
model
CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr
solution;
repeated
AVISIT /
subject=USUBJID
type=un;
lsmeans
TRT01P*AVISIT /
diff
cl;
run;
ods output close;
Building a Reusable Macro
Clinical programming teams often encapsulate repeated model specifications in macros.
%macro run_mmrm(
data=,
out_lsmeans=,
out_diffs=,
out_cov=,
covtype=UN
);
ods output
LSMeans=&out_lsmeans
Diffs=&out_diffs
CovParms=&out_cov;
proc mixed data=&data method=reml;
class
USUBJID
TRT01P
AVISIT;
model
CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated
AVISIT /
subject=USUBJID
type=&covtype;
lsmeans
TRT01P*AVISIT /
diff
cl;
run;
ods output close;
%mend;
%run_mmrm(
data=analysis,
out_lsmeans=lsmeans_un,
out_diffs=diffs_un,
out_cov=cov_un,
covtype=UN
);
Reusable macros can reduce duplicated code across endpoints and studies.
MMRM Validation
Validation should occur at several levels.
| Validation Layer | Example |
|---|---|
| Data | Verify analysis population and records |
| Derivation | Verify baseline and change-from-baseline calculations |
| Model | Verify fixed effects and covariance structure |
| Output | Verify LS-means and treatment differences |
| Presentation | Verify rounding, labels, confidence intervals, and footnotes |
Independent Validation of LS-Means
A strong validation strategy should not simply rerun identical SAS code.
For example, the production analysis could be validated against:
- An independently programmed SAS implementation
- R or another statistical package
- Manual calculations for selected simple contrasts
- Known test datasets
- Historical validated outputs
The validation method should be appropriate for the complexity of the model.
Manual Validation of a Simple Difference
Suppose two estimated means at Week 12 are:
and:
The estimated difference is:
The corresponding PROC MIXED contrast should agree with this value, subject to the exact LS-means and contrast definition.
Common PROC MIXED Mistakes
- Ignoring within-subject correlation. Repeated observations from the same patient are not generally independent.
- Using the wrong SUBJECT= variable. The subject variable should represent the independent clustering unit.
- Automatically choosing TYPE=UN. UN is flexible but can become unstable as the number of visits increases.
- Automatically choosing TYPE=CS. CS may be too restrictive for longitudinal data whose correlation decreases with time.
- Confusing RANDOM and REPEATED. They represent different aspects of mixed-model specification.
- Ignoring convergence warnings. Successful output does not guarantee an adequate model fit.
- Interpreting covariance parameters as treatment effects. Covariance parameters describe variability and correlation.
- Reporting raw means when the analysis requires LS-means. The inferential result should correspond to the prespecified model.
- Ignoring multiplicity. Multiple treatment comparisons can require adjustment.
- Changing the model after seeing the results. Primary-model specifications should be prespecified.
- Assuming PROC MIXED solves missing data automatically. Inference depends on assumptions about the missingness mechanism.
- Failing to validate the treatment contrast. The final estimate should be independently traceable.
PROC MIXED Versus PROC GLIMMIX
PROC MIXED is primarily intended for linear mixed models with approximately normally distributed continuous outcomes.
For non-normal outcomes requiring generalized linear mixed models, PROC GLIMMIX may be more appropriate.
| Procedure | Typical Use |
|---|---|
| PROC MIXED | Continuous approximately normal longitudinal outcomes |
| PROC GLIMMIX | Generalized mixed models for non-normal outcomes |
| PROC GENMOD | Generalized linear models without the same mixed-model structure |
The endpoint distribution and estimand should determine the modeling approach.
PROC MIXED Versus PROC GLM
PROC GLM can analyze many fixed-effects designs, but it is not a direct replacement for a mixed model when within-subject covariance must be modeled.
The distinction becomes particularly important with:
- Unequal numbers of observations
- Missing longitudinal measurements
- Complex covariance structures
- Random effects
PROC MIXED Versus Repeated-Measures ANOVA
Traditional repeated-measures ANOVA often relies on restrictive covariance assumptions such as sphericity.
PROC MIXED allows the analyst to specify alternative covariance structures directly.
This makes mixed models substantially more flexible for many modern longitudinal clinical-trial designs.
Clinical-Trial Interpretation
Suppose the analysis estimates the treatment difference at Week 12 as:
The appropriate interpretation is that the model estimates a 4.8-unit lower mean outcome in the treatment group relative to control at Week 12, with the specified confidence interval.
The clinical importance depends on the endpoint's measurement scale.
For a symptom score, a 4.8-unit difference might be clinically important. For a laboratory value, the same numerical difference might be trivial.
Statistical Significance Is Not Clinical Significance
Suppose a very large trial estimates:
The result may be statistically significant while having limited clinical importance.
Clinical interpretation should therefore consider:
- Magnitude of the treatment effect
- Confidence interval
- Known clinically meaningful thresholds
- Safety
- Other efficacy endpoints
- Overall benefit-risk profile
Responder Analysis Is Different
PROC MIXED is generally designed for continuous longitudinal outcomes.
If the endpoint is a binary responder status, a different modeling approach may be required.
For example:
- Responder/non-responder
- Event/no event
- Count outcomes
may require generalized models rather than a standard linear mixed model.
Repeated Measures With Binary Outcomes
For a binary longitudinal endpoint, a generalized mixed model may be more appropriate.
Conceptually:
This is outside the standard PROC MIXED framework.
Repeated Measures and Baseline Adjustment
One common clinical-trial specification is:
The baseline value is a patient-level covariate, while treatment and visit describe the longitudinal mean structure.
Why Baseline Should Be Examined Carefully
Baseline should not simply be inserted into the model because it is available.
The analyst should consider:
- How baseline is defined
- Whether baseline is measured before treatment
- Whether the baseline value is appropriate for the endpoint
- Whether baseline is part of the estimand
- Whether the SAP specifies adjustment
Model Specification Checklist
MMRM Programming Checklist
| Item | Question |
|---|---|
| Population | Are all included patients correctly flagged? |
| Baseline | Is the baseline value correct? |
| Outcome | Is the analysis variable derived correctly? |
| Visit | Are nominal visits correctly assigned? |
| Treatment | Is treatment assignment correct? |
| Covariance | Is the prespecified covariance structure used? |
| DDFM | Is the correct denominator degrees-of-freedom method used? |
| LS-means | Are the requested comparisons correct? |
| Multiplicity | Are adjustments applied according to the SAP? |
| Output | Are values correctly captured and reported? |
Example of a Complete Production-Style Program
/*=========================================================
MMRM ANALYSIS
Endpoint: Change from Baseline
=========================================================*/
proc sort
data=adam.adqs
out=work.mmrm;
by USUBJID AVISITN;
run;
ods output
LSMeans = work.mmrm_lsmeans
Diffs = work.mmrm_diffs
CovParms = work.mmrm_covparms
Tests3 = work.mmrm_tests3
SolutionF = work.mmrm_solutionf
FitStatistics= work.mmrm_fit;
proc mixed
data=work.mmrm
method=reml;
class
USUBJID
TRT01P
AVISIT;
model
CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr
solution;
repeated
AVISIT /
subject=USUBJID
type=un;
lsmeans
TRT01P*AVISIT /
diff
cl;
run;
ods output close;
This is intentionally written in a form resembling the type of program that might be adapted for a production clinical-trial analysis.
Production Programming Considerations
In a regulated clinical environment, the final program should also make clear:
- Source datasets
- Analysis population flags
- Endpoint derivations
- Baseline rules
- Visit windows
- Covariance-selection rules
- Model version
- Output datasets
- Rounding rules
- Validation procedures
The goal is reproducibility.
Model Version Control
A small change in the model can materially change the reported results.
For example, changing:
type=un
to:
type=ar(1)
changes the covariance assumptions.
Changing:
ddfm=kr
to another degrees-of-freedom method can also change inferential results.
These changes should therefore be version-controlled and documented.
What Should Be Reported?
A clinical-trial table based on PROC MIXED might include:
- Number of patients
- Adjusted mean
- Standard error
- 95% confidence interval
- Treatment difference
- 95% confidence interval for treatment difference
- P-value where appropriate
The exact reporting format depends on the SAP and table shell.
Example Clinical-Trial Table
| Visit | Drug A LS-Mean | Placebo LS-Mean | Difference | 95% CI |
|---|---|---|---|---|
| Week 4 | −2.1 | −0.8 | −1.3 | (−3.7, 1.1) |
| Week 8 | −5.6 | −1.7 | −3.9 | (−6.5, −1.3) |
| Week 12 | −8.4 | −2.0 | −6.4 | (−9.4, −3.4) |
| Week 24 | −10.1 | −2.7 | −7.4 | (−11.0, −3.8) |
These values are illustrative.
Reading the Example Table
The treatment difference becomes increasingly negative over time.
If lower values indicate improvement, this would suggest increasing benefit over time.
The confidence intervals provide information about the precision of each estimate.
Longitudinal Plot and Table Together
A useful clinical-trial reporting strategy is to combine:
The table provides precision.
The figure provides pattern recognition.
The patient-level display provides context about heterogeneity.
Common Questions About PROC MIXED
Does PROC MIXED require complete data?
No. Patients can contribute different numbers of observations, although the validity of inference with missing data depends on the assumptions of the analysis.
Does PROC MIXED automatically impute missing values?
No. PROC MIXED uses likelihood-based estimation with the observed data under the specified model; it does not create a conventional single imputed value for each missing observation.
Should every longitudinal model use TYPE=UN?
No. UN is flexible but may be inefficient or unstable with many visits or limited sample size.
Should visit always be categorical?
No. Categorical visit is common when estimating visit-specific treatment effects, but continuous-time models may be appropriate for other scientific questions.
Is PROC MIXED only for randomized clinical trials?
No. It can be used for many longitudinal and clustered continuous outcomes, including observational studies, laboratory studies, repeated-measure experiments, and clinical trials.
Does a significant treatment effect prove clinical benefit?
No. Statistical significance must be interpreted together with effect size, precision, endpoint meaning, multiplicity, safety, and the prespecified estimand.
When PROC MIXED Is a Good Choice
PROC MIXED is particularly useful when:
- The outcome is continuous.
- Measurements are repeated within subjects.
- Within-subject correlation is important.
- The data are unbalanced.
- Patients have incomplete longitudinal follow-up.
- A covariance structure can reasonably represent the repeated observations.
- Model-based adjusted means are desired.
When to Consider Another Approach
Another modeling framework may be more appropriate when:
- The outcome is binary.
- The outcome is a count.
- The outcome is strongly non-normal.
- The endpoint is time-to-event.
- The scientific question is explicitly subject-specific.
- The missing-data mechanism requires a specialized sensitivity analysis.
PROC MIXED and Regulatory Reporting
For regulated clinical-trial analyses, the model should be traceable to the statistical-analysis plan.
The programmer should be able to answer:
- Why was this endpoint analyzed?
- Why was this baseline definition used?
- Why was this covariance structure selected?
- Why was this degrees-of-freedom method used?
- Why were these treatment comparisons requested?
- How was multiplicity handled?
- How were missing data handled?
The SAS program is therefore an implementation of the statistical methodology, not a substitute for the methodology itself.
MMRM and the Estimand
Modern clinical-trial analysis should distinguish the statistical model from the estimand.
The model describes how observed outcomes are analyzed.
The estimand describes the treatment effect being targeted.
Questions such as treatment policy, hypothetical, while-on-treatment, or other strategies can affect how intercurrent events and post-discontinuation measurements are handled.
Post-Treatment Measurements
Whether post-treatment observations belong in the primary MMRM depends on the estimand and SAP.
For example, a treatment-policy strategy may retain certain observations after treatment discontinuation, whereas a hypothetical strategy may require a different framework.
Therefore, "include all available observations" is not universally correct.
Sensitivity Analyses
Sensitivity analyses can evaluate how conclusions change under alternative assumptions.
Examples may include:
- Alternative covariance structures
- Alternative missing-data assumptions
- Pattern-mixture models
- Reference-based imputation
- Alternative analysis populations
- Alternative handling of intercurrent events
These analyses should be prespecified or appropriately documented.
A Practical MMRM Decision Tree
If yes: consider PROC MIXED.
If yes: specify the subject and covariance structure.
If yes: include treatment-by-visit.
If yes: include the appropriate baseline covariate.
If yes: understand the missingness assumptions.
If yes: follow the prespecified covariance-selection strategy.
If yes: define LS-means or appropriate contrasts.
Example End-to-End Analysis
Suppose a randomized clinical trial compares Drug A with Placebo. The primary continuous endpoint is measured at Weeks 4, 8, 12, and 24. The SAP specifies:
- Change from baseline as the response
- Baseline as a covariate
- Treatment as a fixed effect
- Visit as a categorical fixed effect
- Treatment-by-visit interaction
- Unstructured covariance
- REML estimation
- Kenward–Roger degrees of freedom
- LS-mean treatment comparisons at each visit
The corresponding program is:
proc mixed
data=analysis
method=reml;
class
USUBJID
TRT01P
AVISIT;
model
CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated
AVISIT /
subject=USUBJID
type=un;
lsmeans
TRT01P*AVISIT /
diff
cl;
run;
How to Explain the Model to a Non-Programmer
A useful explanation is:
The Three Most Important PROC MIXED Statements
For a standard longitudinal clinical-trial analysis, remember:
class ...;
defines categorical variables.
model ...;
defines the fixed-effects mean structure.
repeated ... / subject=... type=...;
defines the repeated-measures covariance structure.
Everything else builds on these concepts.
A Compact MMRM Cheat Sheet
| Goal | SAS Syntax |
|---|---|
| Fit mixed model | proc mixed; |
| Use REML | method=reml |
| Define categorical variables | class |
| Specify fixed effects | model |
| Specify repeated covariance | repeated |
| Identify subject | subject=USUBJID |
| Unstructured covariance | type=un |
| Compound symmetry | type=cs |
| AR(1) | type=ar(1) |
| Kenward–Roger | ddfm=kr |
| LS-means | lsmeans |
| Pairwise differences | diff |
| Confidence intervals | cl |
| Capture output | ods output |
The Most Important Concept
The most important thing to understand about PROC MIXED for repeated measures is that the covariance structure is part of the model.
The fixed effects answer:
The covariance structure answers:
Both components are necessary for a properly specified longitudinal mixed model.
Final Clinical-Trial Workflow
Bottom Line
proc mixed data=analysis method=reml;
class
USUBJID
TRT01P
AVISIT;
model
CHG =
BASE
TRT01P
AVISIT
TRT01P*AVISIT
/ ddfm=kr;
repeated
AVISIT /
subject=USUBJID
type=un;
lsmeans
TRT01P*AVISIT /
diff
cl;
run;
Once this structure is understood, many more advanced longitudinal models become much easier to interpret.
References
Littell, R.C., Milliken, G.A., Stroup, W.W., Wolfinger, R.D., & Schabenberger, O. SAS for Mixed Models.
SAS Institute.
Westfall, P.H., Tobias, R.D., Rom, D., Wolfinger, R.D., & Hochberg, Y. Multiple Comparisons and Multiple Tests Using SAS.
SAS Institute.
Kenward, M.G. & Roger, J.H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983–997.
SAS Institute Inc. SAS/STAT User's Guide: The MIXED Procedure.
SAS Institute.
Fitzmaurice, G.M., Laird, N.M., & Ware, J.H. Applied Longitudinal Analysis.
Wiley.
Mallinckrodt, C.H., Clark, W.S., & David, S.R. (2001). Accounting for dropout bias using mixed-effects models. Journal of Biopharmaceutical Statistics.