Written and maintained by CASRAI Editorial Board
Published
On this page
PROC MIXED in SAS fits linear mixed models for continuous outcomes with correlated observations or unequal variances. Specify fixed effects in MODEL, random effects in RANDOM, and residual correlation in REPEATED. The practical distinction is where you put the dependence: a subject intercept and a repeated residual structure describe different parts of the model.
This walkthrough supplies a small, reproducible data example, two alternative specifications, and an output checklist. The downloadable data table compares covariance assumptions and parameter counts so you can connect a SAS statement to the model it actually fits.
What PROC MIXED is used for in research
Researchers use SAS PROC MIXED when observations belong to groups or recur within the same experimental unit. Its linear mixed-model framework models both the expected response and its covariance. SAS documents Gaussian assumptions and a mean that is linear in the model parameters; the procedure name does not mean that any outcome distribution is suitable.
For example, a researcher might model repeated continuous measurements from each participant, or measurements nested within experimental blocks. A random intercept lets each subject have a deviation from the overall intercept. A residual covariance structure instead describes dependence among that subject’s errors after accounting for the fixed effects. Both components can appear in a justified model, but neither should be inserted merely because the dataset contains an identifier.
The distinction between fixed and random effects in mixed models comes before choosing syntax. Here the focus is implementation: declare the unit that groups observations, write the mean model, specify the covariance, and inspect what SAS estimated. The broader SAS statistical software guide explains the surrounding software environment.
How to install or access PROC MIXED
PROC MIXED is documented in SAS/STAT. Start with an institutional SAS environment that provides that procedure, then run the program in its SAS editor. PROC MIXED is a procedure invoked by a program, rather than a separate desktop application to download.
For learning the workflow, SAS’s official OnDemand for Academics page describes browser-based SAS Studio access for students, educators and independent learners without installing SAS locally. Use the official access link in Sources. That teaching and learning offer should not be treated as permission to move an institution’s research files into an external service; choose the environment authorized for your project.
Keep the analysis program and input data together with the SAS log. This is a practical record of the statements you submitted and the messages they produced. The examples below specify the estimation method explicitly, even though SAS documents REML as the default, so a collaborator can see that choice in the program.
How to fit a linear mixed model step by step
Prepare long-format data for PROC MIXED in SAS
The following is an illustrative composite with invented measurements, not results from a study. It contains eight subjects, two groups and three equally spaced visits per subject: 24 observations. Each row identifies one subject at one visit. The response has arbitrary units and is included only to demonstrate the program.
- Create the example data. Paste this block into your SAS program. The input pattern follows SAS’s documented DATA-step examples; replace the invented records with your prepared research dataset when adapting the analysis.
data mixed_demo;
input id group $ visit response @@;
datalines;
1 A 0 10 1 A 1 12 1 A 2 11
2 A 0 14 2 A 1 13 2 A 2 16
3 A 0 9 3 A 1 11 3 A 2 12
4 A 0 12 4 A 1 14 4 A 2 13
5 B 0 11 5 B 1 14 5 B 2 17
6 B 0 15 6 B 1 16 6 B 2 20
7 B 0 8 7 B 1 12 7 B 2 14
8 B 0 13 8 B 1 15 8 B 2 19
;
run;
Before fitting your own data, confirm that IDs identify the intended subjects and that visits have the intended coding. The PROC CONTENTS guide for checking SAS variables helps inspect types and metadata. A numeric subject code still needs to be treated as an identifier rather than a continuous predictor.
- Declare the categorical variables and mean model. Put
idandgroupinCLASS. Leavevisitout of CLASS here because this first model uses a linear time trend. The interaction allows that trend to differ between groups. - Add the subject random intercept. The explicit
INTERCEPTin RANDOM creates the subject-level term; SAS does not add a random intercept automatically.SUBJECT=ididentifies the grouping unit. - Run the complete model. MODEL must follow CLASS, and RANDOM must follow MODEL. Options after the slash request parameter estimates, confidence limits and a named degrees-of-freedom method.
proc mixed data=mixed_demo method=reml;
class id group;
model response = group visit group*visit
/ solution cl ddfm=kr;
random intercept / subject=id;
run;
SOLUTION requests fixed-effect estimates and CL their confidence limits. DDFM=KR is SAS’s documented alias for the Kenward–Roger method. This is an explicit example choice, not a claim that it is the correct choice for every design. Record the method used rather than assuming that defaults remain identical across specifications.
In this model, repeated measurements share a subject intercept. No REPEATED statement is present, so the residual component has SAS’s default independent, equal-variance form. The observations are still correlated marginally because they share the random intercept. “No REPEATED statement” therefore does not mean “no within-subject correlation.”
Specify a repeated residual structure
A different analysis can treat visit as categorical and model residual dependence directly. This example uses an AR(1) residual covariance and no random intercept. Including visit in CLASS gives each visit its own categorical mean contribution; it also identifies the repeated occasions.
proc mixed data=mixed_demo method=reml;
class id group visit;
model response = group visit group*visit
/ solution cl ddfm=kr;
repeated visit / subject=id type=ar(1);
run;
The two examples change both the mean specification and the covariance specification. They demonstrate distinct modelling choices; their output should not be described as a comparison that changes covariance alone. To investigate only covariance, first hold the MODEL and CLASS definitions fixed, then change the covariance statement deliberately.
SAS’s REPEATED documentation defines AR(1) as a correlation pattern indexed by occasion separation. SAS specifically advises using it for a common set of equally spaced time points; its support note identifies a spatial power structure as an alternative for unequal spacing. Do not relabel irregular observation times as visits 1, 2 and 3 and assume that the elapsed-time information has been retained.
How to read the output
Read the model description and fitting diagnostics before interpreting hypothesis tests. A useful reading order is the specification, the observations used, convergence, covariance estimates, then fixed effects. Each table answers a different question.
- Model Information: verify the response, estimation method, covariance structure and degrees-of-freedom method. This checks whether the run represents your intended analysis.
- Class Level Information: inspect the categories SAS recognized. Unexpected levels can reveal a coding problem before it becomes an interpretation problem.
- Number of Observations: compare records read with records used. For the complete illustrative data, the input contains 24 records; investigate any discrepancy when adapting the program.
- Convergence Status: check the optimization message and related warnings. SAS documents that successful convergence can coexist with a Hessian that is not positive definite, so the success message alone is insufficient.
- Covariance Parameter Estimates: identify the random-intercept and residual variance in the first model, or the AR(1) parameters in the second. These describe variation and dependence, rather than group mean differences.
- Type 3 Tests of Fixed Effects: read the effect, numerator and denominator degrees of freedom, F statistic and p-value. These test effects listed in MODEL.
The requested solution table addresses individual fixed-effect parameters. With a group-by-visit interaction, the group coefficient depends on how the other terms are coded. In the first example, visit zero is the origin of the linear trend. Interpret the group contrast at that origin together with the interaction, rather than treating one coefficient as a difference averaged over all visits.
SAS also supplies fit statistics such as AIC, AICC and BIC in smaller-is-better form. Keep their role separate from an individual fixed-effect test. A fit criterion summarizes a candidate fitted model; it does not by itself explain the direction, size or scientific relevance of a group difference.
For reproducible reporting, state the outcome, fixed effects, grouping unit, random terms, residual covariance, estimation method and degrees-of-freedom method. Then report the estimates and uncertainty actually produced by your analysis. The invented dataset above supplies no study finding to report.
Troubleshooting PROC MIXED
Missing estimates or an unintended model
If the fixed-effect coefficient table is absent, check that SOLUTION appears after the MODEL slash. If you expected subject variation, check for an explicit RANDOM statement. Declaring an ID in CLASS does not itself add a random effect, and listing it in MODEL makes it part of the fixed-effects specification.
Check statement order against the SAS syntax reference. Also inspect the log before interpreting output from an earlier successful run: save the log with the corresponding program and make the dataset name explicit in DATA=.
Singular covariance or convergence warnings
For a repeated effect, SAS requires distinct levels within each subject. Duplicate subject–occasion records can produce identical covariance rows and an infinite likelihood. Resolve whether duplicates represent data errors, another grouping level or a design feature; do not delete observations solely to remove a warning.
SAS’s computational guidance identifies poorly conditioned data and covariance parameters on very different scales as possible convergence problems. Check units and scaling, model complexity and the actual covariance specification before changing numerical tolerances. A zero variance estimate can occur at a parameter boundary; it may motivate reconsidering the model, but SAS cautions that changing random effects can change degrees-of-freedom calculations.
The data table below compares four explicit covariance specifications for three visits under shared parameters across subjects. An unstructured residual matrix estimates six covariance parameters in this setting, compared with two for AR(1). This parameter count is a property of the specification, not evidence that the larger model is supported by your dataset.
Free alternatives to PROC MIXED
R’s nlme and lme4 packages are distributed under GNU GPL licences and fit mixed models. They provide alternative software implementations, while the underlying model still needs to be specified. Their official package pages and documentation are linked in Sources.
| Alternative | Documented capability | What to translate from SAS |
|---|---|---|
| R with nlme | The lme function fits linear mixed-effects models with nested random effects and permits correlated or unequal-variance within-group errors. | Translate the fixed effects, random structure, correlation and variance specification separately. |
| R with lme4 | Fits linear and generalized linear mixed-effects models. | Match the intended response model and random terms before comparing estimates. Consult its documentation for the specific covariance model. |
The linear mixed-model guide for R provides a companion workflow. When checking agreement between software, write down the mean and covariance assumptions first, then compare estimation and inference settings. Similar-looking formulas or identical variable names are not a complete specification of the same analysis.
Sources
- SAS: SAS/STAT User’s Guide, The MIXED Procedure, 2024.1, checked 2026-11-17.
- SAS: Syntax, MIXED Procedure, checked 2026-11-17.
- SAS: MODEL Statement, checked 2026-11-17.
- SAS: RANDOM Statement, checked 2026-11-17.
- SAS: REPEATED Statement, checked 2026-11-17.
- SAS: Default Output, checked 2026-11-17.
- SAS: Computational Issues, checked 2026-11-17.
- SAS: SAS OnDemand for Academics, checked 2026-11-17.
- SAS: Specifying a repeated AR(1) structure for unequally-spaced time points, checked 2026-11-17.
- R Project CRAN: nlme package and licence, checked 2026-11-17.
- R Project CRAN: nlme reference manual, Linear Mixed-Effects Models, checked 2026-11-17.
- R Project CRAN: lme4 package and licence, checked 2026-11-17.
Data: PROC MIXED covariance specifications for three visits
Original crosswalk compiled from the SAS RANDOM and REPEATED documentation. Counts cover covariance parameters only for three observations per subject, one common covariance structure across subjects, no GROUP effect and no additional random effects.
| Specification | SAS covariance statement | Covariance parameters (parameters) | Covariance assumption | Source section |
|---|---|---|---|---|
| Subject random intercept | random intercept / subject=id; | 2 | One subject-intercept variance plus one independent residual variance. | SAS RANDOM; SAS REPEATED defaults |
| Residual compound symmetry | repeated visit / subject=id type=cs; | 2 | Constant residual variance and constant covariance between different visits; no RANDOM statement. | SAS REPEATED: CS |
| Residual autoregressive | repeated visit / subject=id type=ar(1); | 2 | Common residual variance with correlation indexed by occasion separation; no RANDOM statement. | SAS REPEATED: AR(1) |
| Residual unstructured | repeated visit / subject=id type=un; | 6 | Three variances and three distinct covariances for three visits; no RANDOM statement. | SAS REPEATED: UN |
Sources
- SAS: RANDOM Statement (accessed 2026-11-17)
- SAS: REPEATED Statement (accessed 2026-11-17)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







