BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jrbrauer
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

4 REPLIES 4
Ksharp
Super User

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.

jrbrauer
Fluorite | Level 6

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!

Ksharp
Super User
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;
jrbrauer
Fluorite | Level 6

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 2042 views
  • 5 likes
  • 2 in conversation