Hello,
I'm trying to plot 2 separate PROC MIXED outputs in 1 PROC SGPLOT. Here is the output I am keeping -only estimate and 95% CI's. Could you please suggest a way for me to plot them in the same PROC SGPLOT series plot along with 95% CI's?
/*1st output for the total sample*/
proc mixed data = temp;
class ID visit group;
model outcome = visit group visit *group / cl ;
repeated visit / type=un subject=ID r;
lsmeans visit group visit *group / cl;
ods output lsmeans = plot1(where=(Effect="visit*group"));
run;
/*2 nd output from a subset of people */
proc mixed data = temp;
where subset = 1;
class ID visit group;
model outcome = visit group visit *group / cl ;
repeated visit / type=un subject=ID r;
lsmeans visit group visit *group / cl;
ods output lsmeans = plot2(where=(Effect="visit*group"));
run;
*This scatter plot plots a 1 output but can add 95% CI's, while proc sgplot series cannot add 95% CI's.
proc sgplot data=plot1;
scatter y=Estimate x=visit/ yerrorlower=Lower yerrorupper=Upper
markerattrs=(symbol=diamondfilled) group=GRP groupdisplay=cluster;
refline 0 / axis=x;
xaxis grid values=(1 to 3 by 1);
yaxis values=(7 to 12 by 1) grid colorbands=odd display=(nolabel) discreteorder=data;
run;
Hi @ballardw ! Thanks for the suggestions! A combination PROC SGPLOT with both bands and scatter worked well.
proc sgplot data=allplot;
band x=visit lower=Lower upper=Upper / group=Source fillattrs=GraphConfidence1 legendlabel="95% CL" name="band";
scatter x=visit y=Estimate / group=Source yerrorlower=Lower yerrorupper=Upper groupdisplay=overlay;
position=bottomright;
xaxis grid values=(1 to 3 by 1);
yaxis grid colorbands=odd display=(nolabel) discreteorder=data;
run;
You would combine the data in a data step. Something like this perhaps:
Data allplot; set plot1 plot2 indsname=ds; Source=ds; run;
The Indsname option creates a temporary variable with the name of the data set records come from. The Source variable keeps that so you can use it later. You may want to use this as a Group option variable in plots to indicate just which plot you are looking at.
Large economy sized hint: If you use a SERIES plot and a SCATTER plot with the same x and y variables they will overlay each other. So the errorbars from the scatter appear with to be from the series.
Hi @ballardw ! Thank you for the quick reply to my post.
I followed your suggestion and combined the 2 data in a data step and plotted them in PROC SGPLOT using both scatter and series. Please see the code below. However, the plot looks a bit messy. I was hoping to get more of connected lines like in time series and 95% CI's as bands around them. Thanks in advance for any suggestions!
proc sgplot data=allplot noautolegend;
series x=VISIT y=Estimate / group=Source;
scatter x=VISIT y=Estimate / group=Source yerrorlower=Lower yerrorupper=Upper groupdisplay=cluster;
xaxis grid values=(1 to 3 by 1);
yaxis values=(7 to 12 by 1) grid colorbands=odd display=(nolabel) discreteorder=data;
run;
@jeff_b wrote:
Hi @ballardw ! Thank you for the quick reply to my post.
I followed your suggestion and combined the 2 data in a data step and plotted them in PROC SGPLOT using both scatter and series. Please see the code below. However, the plot looks a bit messy. I was hoping to get more of connected lines like in time series and 95% CI's as bands around them. Thanks in advance for any suggestions!
proc sgplot data=allplot noautolegend;
series x=VISIT y=Estimate / group=Source;
scatter x=VISIT y=Estimate / group=Source yerrorlower=Lower yerrorupper=Upper groupdisplay=cluster;
xaxis grid values=(1 to 3 by 1);
yaxis values=(7 to 12 by 1) grid colorbands=odd display=(nolabel) discreteorder=data;
run;
The BAND plot instead of series or scatter then.
proc sgplot data=allplot noautolegend; band x=VISIT y=Estimate lower=Lower upper=Upper / group=Source ; xaxis grid values=(1 to 3 by 1); yaxis values=(7 to 12 by 1) grid colorbands=odd display=(nolabel) discreteorder=data; run;
But I think you need to look at your output data set a bit. I'm not sure about that your "limits" are as intended.
Hi @ballardw ! Thanks for the suggestions! A combination PROC SGPLOT with both bands and scatter worked well.
proc sgplot data=allplot;
band x=visit lower=Lower upper=Upper / group=Source fillattrs=GraphConfidence1 legendlabel="95% CL" name="band";
scatter x=visit y=Estimate / group=Source yerrorlower=Lower yerrorupper=Upper groupdisplay=overlay;
position=bottomright;
xaxis grid values=(1 to 3 by 1);
yaxis grid colorbands=odd display=(nolabel) discreteorder=data;
run;
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!
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.