Hi folks,
I want to show predicted event rates for Y by X at two different values of Z1 and two different values of Z2 in a single plot using "effectplot" in proc genmod. I can plot at two different values of Z1 (or Z2) using the "sliceby" command, and I can compare these curves across two different values of Z2 (or Z1) across two different plots by adding a "plotby" command. Is there any way to stack or overlay these two plots in SAS? Conceptually, I think it would be equivalent to simultaneously requesting two "sliceby" commands, though that does not appear to be a possibility. Here is an example of my code:
ods graphics on ;
proc genmod data=tempd plots=(resraw resdev);
model prjdlqad = female age16p famsplit famstep famoth finsesza acachfs
impulsza allblfza morctxza impulsza*allblfza impulsza*morctxza allblfza*morctxza
/ dist=nb link=log; store nbmodel1; run;
ods html style=statistical ;
title "Impulsivity & Projected Delinquency, by Moral Beliefs & Context";
proc plm source=nbmodel1;
effectplot slicefit(x=impulsza sliceby=allblfza= -8.12 8.12 plotby=morctxza= -4.42 4.42)
/ CLM at(female=0 age16p=0 famsplit=0 famstep=0 famoth=0);
run;
ods graphics off;
Thanks in advance for any help!
Jon
ods trace on;
ods output FitPlot=plot;
proc genmod data=sashelp.class;
model sex=age weight height;
effectplot fit(x=age);
run;
ods trace off;
proc sgplot data=plot;
band x=_xcont1 lower=_lclm upper=_uclm;
series x=_xcont1 y=_predicted/lineattrs=(color=red);
run;
One way I could think is useing ODS TRACE to get the name of graphic and using ODS OUTPUT to get their data and finally using proc sgplot to overlap the graphic.
Thank you for your helpful reply. I do not have much experience with sgplot but I will give this a try.
If you are aware of an example of this being done, please share!
ods trace on;
ods output FitPlot=plot;
proc genmod data=sashelp.class;
model sex=age weight height;
effectplot fit(x=age);
run;
ods trace off;
proc sgplot data=plot;
band x=_xcont1 lower=_lclm upper=_uclm;
series x=_xcont1 y=_predicted/lineattrs=(color=red);
run;
Thank you! This is exactly what I needed. After your initial post, I was able to save the predicted values using ods output. Then, I created a new "group" variable using the "_plotby" and "_group" variables and modified the sgplot code you provided here by adding "/group=z" after the series. Now I just need to learn how to tweak the colors! Here is the full code in case anyone else ever has this question:
ods graphics on ; ods trace on;
proc genmod data=tempd plots=(resraw resdev);
model prjdlqad = female age16p famsplit famstep famoth finsesza acachfs
impulsza allblfza morctxza impulsza*allblfza impulsza*morctxza allblfza*morctxza
/ dist=nb link=log; store nbmodel1; run;
ods listing style=statistical;
title "Impulsivity & Projected Delinquency, by Moral Beliefs & Context";
proc plm source=nbmodel1;
effectplot slicefit(x=impulsza sliceby=allblfza= -8.12 8.12 plotby=morctxza= -4.42 4.42)
/ CLM at(female=0 age16p=0 famsplit=0 famstep=0 famoth=0) ;
ods output SliceFitPanel = mygraph;
run;
data mygraph2; set mygraph;
if _plotby = "morctxza=-4.42" & _group = -8.12 then morfiltr = 1;
if _plotby = "morctxza=-4.42" & _group = 8.12 then morfiltr = 2;
if _plotby = "morctxza=4.42" & _group = -8.12 then morfiltr = 3;
if _plotby = "morctxza=4.42" & _group = 8.12 then morfiltr = 4;
run;
proc sgplot data=mygraph2;
title "Impulsivity & Projected Delinquency, by Moral Beliefs & Context";
band x=_xcont1 lower=_lclm upper=_uclm / group=morfiltr;
series x=_xcont1 y=_predicted/group=morfiltr lineattrs=(color=red);
run;
Thanks again. I really appreciate the help!
Jon
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.