BookmarkSubscribeRSS Feed
gdr1
Fluorite | Level 6

Hello SAS community! 

 

I am very new to SAS and I have used R to run some linear mixed models. I now have to run the exact same in SAS but I have a few questions. 

*For context, I am looking at interest variables to see the level of interest in using herbs and spices (interest1 variable) before and after (time variable) watching short and long (randomization variable) nutrition videos.*

 

1) After running this model in R using the code below, I tried to run it in SAS. I am not sure if this code is right, but the p values aren't the same (in R and in SAS) and some significant variables in R are not significant in SAS. Does anyone have recommendations on how to correct my code in SAS so I am able to get the same outputs in both softwares?

gdr1_3-1720704506853.png

 

proc mixed data=results.cormick;
class record_id education time income randomization;
model interest1=time randomization age education sex income time*randomization /solution;
random record_id;
repeated /subject=record_id type=un;
run;

 

2) Also, I am not sure which p-values I should be reporting from these two tables. Does anyone have recommendations?

gdr1_1-1720704256081.png

gdr1_2-1720704290791.png

3) I am unable to get these graphs in SAS, does anyone know what code I could use?

gdr1_4-1720704671203.png

 

 

 

Thanks so much!

16 REPLIES 16
Ksharp
Super User

Check @Rick_SAS blogs:

https://blogs.sas.com/content/iml/2016/06/22/sas-effectplot-statement.html

 

proc mixed data=sashelp.heart(obs=1000);
class bp_status sex status;
model weight=height sex status/s;
random int/subject=bp_status;
/*repeated /subject=bp_status type=un;*/
store out=mixedmodel;
run;
proc plm source=mixedmodel;
   effectplot INTERACTION(x=sex  sliceby=status /*plotby=CigsPerDay*/ )/limits connect;
run;

Ksharp_0-1720749255255.png

 

Rick_SAS
SAS Super FREQ

Look at the R table of parameter estimates. The R model appears to treat all variables as continuous, whereas in SAS you are treating many variables as factors. Resolve that issue first or you'll never get the same estimates.

 

Also, I suspect you want to add Sex to the CLASS statement so that the Sex variable is treated as a categorical variable. 

 

 

gdr1
Fluorite | Level 6

Hi Rick, 

 

Thanks for the advice. When you say treat the variables as continuous in SAS, do you mean input them all in the model statement even if I inputted them in the class statement?

PaigeMiller
Diamond | Level 26

@gdr1 wrote:

Hi Rick, 

 

Thanks for the advice. When you say treat the variables as continuous in SAS, do you mean input them all in the model statement even if I inputted them in the class statement?


It means: put the continuous variables in the model statement and NOT in the class statement.

--
Paige Miller
gdr1
Fluorite | Level 6

Thank you! It worked. 

 

I am still unable to get the graphs. Do you have any recommendations on how to get the graphs? When I run the bottom code, I get the fixed effects but then the plm procedure doesn't work. "time" and "randomization" are not continuous variables. 

 

gdr1_0-1721415359939.pnggdr1_1-1721415382172.png

gdr1_2-1721415475760.png

 

PaigeMiller
Diamond | Level 26

I think you want to use CONTOURPLOT instead of INTERACTION

--
Paige Miller
Mike_N
SAS Employee

I think @Rick_SAS is saying you need to specify the same model in both R and SAS. As stated by @PaigeMiller, one way to do that is to treat all of the predictors in your SAS model as continuous by specifying them in the model statement and not the class statement.

 

The other way is to treat the class variables from the SAS model as factors in your R model. That is:

m1 <- lmer(interest1 ~ time*randomization + age + factor(education) + sex + factor(income) + (1|record_id)

The choice will depend on how education and income are coded, and whether it is reasonable to assume a linear relationship between those variables and the model outcome. Treating those variables as categorical does not require that kind of assumption but will usually decrease the power of statistical tests (i.e., you will get higher p-values) compared to treating those variables as continuous. 

gdr1
Fluorite | Level 6

Thank you! I added the class statement back in and it makes more sense now since education, sex and income are categorical variables. 

 

I am still unable to get the graphs. Currently getting this error.

 

gdr1_0-1721418922611.png

 

gdr1
Fluorite | Level 6

Thanks Rick. 

 

Still getting an error after I run this: 

gdr1_0-1721664414532.pnggdr1_1-1721664459985.png

 

PaigeMiller
Diamond | Level 26

There is no SLICEBY= for contour plots. You need a Y= option however.

 

Or maybe the whole idea of a CONTOUR plot is going down the wrong path. Somehow, this won't get the plots you showed from R. So tell us, using the SAS variable names, what plots you want, what is on the x- axis, what is on the y-axis, and what lines or curves should be drawn on the plot?

 

Also, what is wrong with the solution from @Ksharp ??

--
Paige Miller
gdr1
Fluorite | Level 6

When trying ksharps solution, I get the below error:

gdr1_0-1721848637134.png

 

My goal is to create the below plot: 

gdr1_1-1721848718809.png

where randomization = short or long videos, time = pre or post, and the lines across the graph are the mean values of the variable of interest (interest1)

 

 

So far I used the code below :

gdr1_2-1721848901588.png

and got the fixed effect model results:

gdr1_3-1721848935027.png

I am just trying to create the graphs now . Thanks!

 

PaigeMiller
Diamond | Level 26

This is the source of all of your problems in this thread. You need to put RANDOMIZATION into the CLASS statement of PROC MIXED, and also into the model statement.

--
Paige Miller
gdr1
Fluorite | Level 6

Unfortunately, I am getting this Java error now. 

 

gdr1_0-1721852991616.png

 

Also, can proc gplot be used instead of proc plm?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 16 replies
  • 1525 views
  • 11 likes
  • 5 in conversation