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?
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?
3) I am unable to get these graphs in SAS, does anyone know what code I could use?
Thanks so much!
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;
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.
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?
@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.
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.
I think you want to use CONTOURPLOT instead of INTERACTION
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.
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.
Use CONTOUR (you have a typo)
Thanks Rick.
Still getting an error after I run this:
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 ??
When trying ksharps solution, I get the below error:
My goal is to create the below plot:
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 :
and got the fixed effect model results:
I am just trying to create the graphs now . Thanks!
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.
Unfortunately, I am getting this Java error now.
Also, can proc gplot be used instead of proc plm?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.