Linked In Icon Twitter Icon Facebook Icon

"entertaining and informative"

Hays Pharma

PhUSE Wiki

Forest Plot Using Sas 

Wiki content first added by: Sanjay Matange

  

Contents

  1. Graph
  2. Code

A Forest Plot is a graphical display of the relative strength of treatment effects in multiple quantitative scientific studies addressing the same question (Wikipedia).  This is an example of one common display of a Forest Plot created using the SGPLOT Procedure of SAS ® 9.2.

Graph 

Section content first added by: Sanjay Matange

Forest Plot using SAS

Code 

Section content first added by: Sanjay Matange

/*--Data for Forest Plot--*/
data work.forest;
  input Study $1-16 grp OddsRatio LowerCL UpperCL Weight;
  format weight percent5.;
  format Q1 Q3 4.2;
  format study2 $char8.;
  ObsId=_N_;
  if grp=1 then do;
    weight=weight*.05;
    Q1=OddsRatio-OddsRatio*weight;     
    Q3=OddsRatio+OddsRatio*weight;
  end;
  else do;
    study2=study;
    study="";
  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 0.233 0.462  .
;
run;
/*proc print data=work.forest; run;*/

proc sort data=work.forest;
  by descending obsid;
  run;

data work.forest2;
  set work.forest;
  format oddsratio lowercl uppercl 5.3;
  drop grp;

  if grp=1 then do;
    lcl2=lowercl;
    ucl2=uppercl;
  end;

  OR='OR'; LCL='LCL'; UCL='UCL'; WT='Weight';
  run;
/*proc print data=work.forest2; run;*/

ods html close;

data _null_;
  pct=0.75/nobs;
  call symputx("pct", pct);
  call symputx("pct2", 2*pct);
  set forest nobs=nobs;
run;

proc template;
  define Style styles.foreststyle;
    parent = styles.analysis;
    style GraphFonts  from GraphFonts /
     'GraphFootnoteFont' = ("<MTsans-serif-unicode>",10pt,italic);
 end;
run;

ods escapechar '^';
ods listing sge=off image_dpi=100 style=styles.foreststyle;
ods graphics / reset width=7in height=4.5in imagename="ForestPlot_V92";
title "Impact of Treatment on Mortality by Study";
title2 h=8pt 'Odds Ratio and 95% CL';
footnote j=l "This graph is created using SAS^{unicode '00ae'x} 9.2 SGPLOT Procedure";
proc sgplot data=work.forest2 noautolegend;
  scatter y=study2 x=oddsratio /
            markerattrs=graphdata2(symbol=diamondfilled size=10);
  scatter y=study x=oddsratio / xerrorupper=ucl2 xerrorlower=lcl2
            markerattrs=graphdata1(symbol=squarefilled);
  scatter y=study x=or / markerchar=oddsratio x2axis;
  scatter y=study x=lcl / markerchar=lowercl x2axis;
  scatter y=study x=ucl / markerchar=uppercl x2axis;
  scatter y=study x=wt / markerchar=weight x2axis;
  refline 1 100  / axis=x;
  refline 0.01 0.1 10 / axis=x lineattrs=(pattern=shortdash) transparency=0.5;
  inset '               Favors Treatment'  / position=bottomleft;
  inset 'Favors Placebo'  / position=bottom;
  xaxis type=log offsetmin=0 offsetmax=0.35 min=0.01 max=100
          minor display=(nolabel) ;
  x2axis offsetmin=0.7 offsetmax=0.05 display=(noticks nolabel);
  yaxis display=(noticks nolabel) offsetmin=&pct2 offsetmax=&pct;
  run;
title;

Contibute to this Wiki

Register You need to register to contribute to this Wiki.

Login If you are already regsitered please login.