Hi,
Could someone please share SAS code to make a simple forest plot out of this (two studies go on the y axis):
data forest;
input Study $1-16 OddsRatio LowerCL UpperCL;
format oddsratio lowercl uppercl 5.3;
datalines;
Modano (1967) 0.590 0.096 3.634
Borodan (1981) 0.464 0.201 1.074
;
run;
Many thanks!
data forest;
input Study $1-16 OddsRatio LowerCL UpperCL;
format oddsratio lowercl uppercl 5.3;
datalines;
Modano (1967) 0.590 0.096 3.634
Borodan (1981) 0.464 0.201 1.074
;
run;
title "Odds Ratios with 95% Wald Confidence Limits";
proc sgplot data=forest noautolegend;
scatter y=Study x=oddsratio / xerrorlower=LowerCL xerrorupper=UpperCL
markerattrs=(symbol=diamondfilled);
refline 1 / axis=x;
* xaxis grid type=log label="Odds Ratio (log scale)"; /* specify log scale */
* yaxis grid display=(nolabel) discreteorder=data reverse;
run;
Based on this post, but I commented out the log scale axis.
https://blogs.sas.com/content/iml/2015/07/29/or-plots-log-scale.html
Quite a few more complicated examples with data and code on the SAS blogs.
https://blogs.sas.com/content/graphicallyspeaking/2012/02/01/forest-plot-using-sgplot-procedure/
@pink_poodle wrote:
Hi,
Could someone please share SAS code to make a simple forest plot out of this (two studies go on the y axis):
data forest; input Study $1-16 OddsRatio LowerCL UpperCL; format oddsratio lowercl uppercl 5.3; datalines; Modano (1967) 0.590 0.096 3.634 Borodan (1981) 0.464 0.201 1.074 ; run;
Many thanks!
data forest;
input Study $1-16 OddsRatio LowerCL UpperCL;
format oddsratio lowercl uppercl 5.3;
datalines;
Modano (1967) 0.590 0.096 3.634
Borodan (1981) 0.464 0.201 1.074
;
run;
title "Odds Ratios with 95% Wald Confidence Limits";
proc sgplot data=forest noautolegend;
scatter y=Study x=oddsratio / xerrorlower=LowerCL xerrorupper=UpperCL
markerattrs=(symbol=diamondfilled);
refline 1 / axis=x;
* xaxis grid type=log label="Odds Ratio (log scale)"; /* specify log scale */
* yaxis grid display=(nolabel) discreteorder=data reverse;
run;
Based on this post, but I commented out the log scale axis.
https://blogs.sas.com/content/iml/2015/07/29/or-plots-log-scale.html
Quite a few more complicated examples with data and code on the SAS blogs.
https://blogs.sas.com/content/graphicallyspeaking/2012/02/01/forest-plot-using-sgplot-procedure/
@pink_poodle wrote:
Hi,
Could someone please share SAS code to make a simple forest plot out of this (two studies go on the y axis):
data forest; input Study $1-16 OddsRatio LowerCL UpperCL; format oddsratio lowercl uppercl 5.3; datalines; Modano (1967) 0.590 0.096 3.634 Borodan (1981) 0.464 0.201 1.074 ; run;
Many thanks!
Thank you for a simple and elegant solution. I have just one follow-up question, I would like population numbers as a secondary y-axis on a graph like this (please also see image below):
Study N
Modano (1967) 100
Borodan (1981) 200
How would you modify the code to accommodate the N variable?:
data forest;
input Study $1-16 N OddsRatio LowerCL UpperCL;
format oddsratio lowercl uppercl 5.3;
datalines;
Modano (1967) 100 0.590 0.096 3.634
Borodan (1981) 200 0.464 0.201 1.074
;
run;
title "Odds Ratios with 95% Wald Confidence Limits";
proc sgplot data=forest noautolegend;
scatter y=Study x=oddsratio / xerrorlower=LowerCL xerrorupper=UpperCL
markerattrs=(symbol=diamondfilled);
refline 1 / axis=x;
* xaxis grid type=log label="Odds Ratio (log scale)"; /* specify log scale */
* yaxis grid display=(nolabel) discreteorder=data reverse;
run;
Many thanks!
I can put population numbers in columns to the right, but am not sure which part of code is responsible for those columns
(https://blogs.sas.com/content/graphicallyspeaking/files/2012/02/Full-SAS-93-Code.txt)
/*--Set up columns to create the stat tables--*/
OR='OR'; LCL='LCL'; UCL='UCL'; WT='Weight';
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 0.233 0.462 .
;
run;
*Here is one way of doing it;title "Odds Ratios with 95% Wald Confidence Limits"; proc sgplot data=forest noautolegend; scatter y=Study x=oddsratio / xerrorlower=LowerCL xerrorupper=UpperCL markerattrs=(symbol=diamondfilled) datalabel=oddsratio datalabelattrs=(weight=bold); scatter y=study x=lowercl / datalabel = lowercl markerattrs=(size=0 color=crimson); scatter y=study x=uppercl / datalabel = uppercl markerattrs=(size=0 color=crimson); refline 1 / axis=x; * xaxis grid type=log label="Odds Ratio (log scale)"; /* specify log scale */ * yaxis grid display=(nolabel) discreteorder=data reverse; run;
The output looks right:
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.