Proc mixed in SAS vs. R

I am trying to reproduce output from the PROC MIXED procedure using R.

proc mixed data=m;
class name y country;
model y = name|year;
repeated / type=ar(1) sub=country;

Does anybody know what I'm doing in R?
Thank you in advance.

you are doing a linear mixed model.
Here is a guide I googled on R, that seems a good place to start.
A Practical Guide to Mixed Models in R (

1 Like

I don't know the SAS syntax well enough, so I cannot help in direct translation, but I recognize that this is not a mixed model (MIXED), but rather a model for repeated observations (REPEATED), with only fixed effects (contrary to its name, MMRM) and fits a marginal (population-average) model via GLS (generalized least square). GLS is the SAS way to handle the REPEATED clause.

You can fit such model using the nlme::gls().

Now, if the model is like this:
response: Y
fixed terms: name, year and their interaction

then it's something like: gls(y ~ year*name, correlation = corAR1(form = ~ 1 | country), weights = varIdent(form = ~ 1 | year), data=m, method = "REML")

year*name translates to: year + name + year:name
the weights parameter handles heteroscedasticity at each time point.
correlation is self describing :slight_smile:
Here country is the grouping cluster, for which you have repeated observations, right?

As I said I'm not sure about the exact translation from SAS to R.

The problem will be also in the degrees of freedom. For REPEATED SAS will probably use BETWITHIN.
GLS will probably use the residual ones.

You may specify DDFM=SATTERTHWAITE and try getting the same with additional R package called "emmeans" (LS-means, called in R EM-means for estimated marginal means). It gives Satterthwaite for a GLS fitted model, either exact or approximate (if estimation of the var-cov fails). Then the results may be closer between SAS and R.

You may also try the "parameters" package which seems to handle BETWITHIN degrees of freedom for the nlme, but I don't know if it handles gls().

In general it's difficult to obtain exactly same results between SAS and R and you'll need some experimenting.


I have gathered some I hope useful links for you to look at:

I hope this helps but please have a look at @Frequentist detailed explanation from the expert.


Thank you for your kind explanation.


Thank you for your detailed and kind explanation.
Your advice was very helpful.

I have one more question.
How do I change the name and year as categorical variables?

Thank you in advance.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.