Sample 70217: Create a forest plot with a YAXISTABLE
This sample illustrates how to create a forest plot with a YAXISTABLE using the SGPLOT procedure. SAS® 9.4M3 (TS1M3) or a later release is required for this sample.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample illustrates how to create a forest plot with a YAXISTABLE using the SGPLOT procedure. SAS 9.4M3 or later is required for this sample.
/** ***
* SAS 9.4 SGPlot implementation of Forest plot using
* YAxisTable
*/
data forest;
input Study $1-16 grp OR LCL UCL Weight;
format Weight percent5. or lcl ucl 5.3;
format Q1 Q3 4.2 ;
or2=or;
if grp=1 then do;
%let wtFactor=0.008;
weight = weight*0.05;
Q1=or - or * weight; /* bar width for weight relative to OR */
Q3=or + or * weight;
or2=.;
end;
datalines;
Modano (1967) 1 0.590 0.096 3.634 1
Borodan (1981) 1 0.464 0.201 1.074 3.5
Leighton (1972) 1 0.394 0.076 2.055 2
Novak (1992) 1 0.490 0.088 2.737 2
Stawer (1998) 1 1.250 0.479 3.261 3
Truark (2002) 1 0.129 0.027 0.605 2.5
Fayney (2005) 1 0.313 0.054 1.805 2
Modano (1969) 1 0.429 0.070 2.620 2
Soloway (2000) 1 0.718 0.237 2.179 3
Adams (1999) 1 0.143 0.082 0.250 4
Truark2 (2002) 1 0.129 0.027 0.605 2.5
Fayney2 (2005) 1 0.313 0.054 1.805 2
Modano2 (1969) 1 0.429 0.070 2.620 2
Soloway2(2000) 1 0.718 0.237 2.179 3
Adams2 (1999) 1 0.143 0.082 0.250 4
Overall 2 0.328 . . .
;
run;
/* Create obs for explantory labels using non-breaking space ('A0'x) as
* place holder on the discrete Y axis for the study variable. */
data bottomLabels;
study='A0'x;
lblX=0.1; lbl='Favors Treatment'; output;
lblX=10; lbl='Favors Placebo'; output;
run;
/* Append bottom labels obs */
data forestFinal;
set forest bottomLabels;
run;
/*--Simple Forest Plot using AxisTable--*/
ods _all_ close;
option missing=' ';
ods listing style=analysis image_dpi=300;
ods graphics / reset
imagename="SAS94M3_ForestPlot_SGPlot";
title "Impact of Treatment on Mortality by Study";
title2 h=8pt 'Odds Ratio and 95% CL';
proc sgplot data=forestFinal
noautolegend nocycleattrs nowall noborder;
styleattrs axisextent=data; /* SAS9.4M3 feature */
/* left side table */
yaxistable study / y=study location=inside position=left
labelattrs=(size=7);
/* Odds-ratio plot */
highLow y=study low=lcl high=ucl / type=line;
/* Weight bar */
highLow y=study low=q1 high=q3 / type=bar barWidth=0.7;
/* Overall marker */
scatter y=study x=or2 / markerattrs=graphdata2(symbol=diamondFilled);
/* right side table */
yaxistable or lcl ucl / y=study location=inside position=right
labelattrs=(size=7);
yaxistable weight / y=study location=inside position=right
labelattrs=(size=7);
refline 1 / axis=x noclip;
refline 0.01 0.1 10 100 / axis=x lineattrs=(pattern=shortdash)
transparency=0.5 noclip;
text y=study x=lblX text=lbl / position=center contributeoffsets=none;
xaxis type=log max=100 minor display=(nolabel) valueattrs=(size=7);
yaxis display=none fitpolicy=none reverse
colorbands=even colorbandsattrs=Graphdatadefault(transparency=0.8)
valueattrs=(size=7);
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.

This sample illustrates how to create a forest plot with a YAXISTABLE using the SGPLOT procedure. SAS® 9.4M3 (TS1M3) or a later release is required for this sample.
Date Modified: | 2023-07-03 13:38:57 |
Date Created: | 2023-06-28 08:04:58 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.4 TS1M0 | |
z/OS 64-bit | 9.4 TS1M0 | |
Microsoft® Windows® for x64 | 9.4 TS1M0 | |
Microsoft Windows 8 Enterprise x64 | 9.4 TS1M0 | |
Microsoft Windows 8 Pro x64 | 9.4 TS1M0 | |
Microsoft Windows 8.1 Enterprise 32-bit | 9.4 TS1M0 | |
Microsoft Windows 8.1 Enterprise x64 | 9.4 TS1M0 | |
Microsoft Windows 8.1 Pro 32-bit | 9.4 TS1M0 | |
Microsoft Windows 8.1 Pro x64 | 9.4 TS1M0 | |
Microsoft Windows 10 | 9.4 TS1M0 | |
Microsoft Windows Server 2008 R2 | 9.4 TS1M0 | |
Microsoft Windows Server 2008 for x64 | 9.4 TS1M0 | |
Microsoft Windows Server 2012 Datacenter | 9.4 TS1M0 | |
Microsoft Windows Server 2012 R2 Datacenter | 9.4 TS1M0 | |
Microsoft Windows Server 2012 R2 Std | 9.4 TS1M0 | |
Microsoft Windows Server 2012 Std | 9.4 TS1M0 | |
Windows 7 Enterprise x64 | 9.4 TS1M0 | |
Windows 7 Professional x64 | 9.4 TS1M0 | |
64-bit Enabled AIX | 9.4 TS1M0 | |
64-bit Enabled Solaris | 9.4 TS1M0 | |
HP-UX IPF | 9.4 TS1M0 | |
Linux for x64 | 9.4 TS1M0 | |
Solaris for x64 | 9.4 TS1M0 | |