%let gpath='C:\'; %let dpi=200; data ae; input Pref $1-30 NA NB SNA SNB; datalines; ABDOMINAL PAIN 20 61 216 431 ANOREXIA 2 15 216 431 ARTHRALGIA 1 15 216 431 BACK PAIN 10 23 216 431 BRONCHITIS 8 11 216 431 CHEST PAIN 9 12 216 431 CHRONIC OBSTRUCTIVE AIRWAY 76 95 216 431 COUGHING 13 26 216 431 DIARRHEA 23 90 216 431 DIZZINESS 9 29 216 431 DYSPEPSIA 8 42 216 431 DYSPNEA 15 9 216 431 FATIGUE 4 16 216 431 FLATULENCE 6 20 216 431 GASTROESOPHAGEAL REFLUX 5 12 216 431 HEADACHE 14 36 216 431 HEMATURIA 2 14 216 431 HYPERKALEMIA 4 9 216 431 INFECTION VIRAL 12 26 216 431 INJURY 12 30 216 431 INSOMNIA 4 26 216 431 MELENA 7 12 216 431 MYALGIA 6 12 216 431 NAUSEA 10 82 216 431 PAIN 4 17 216 431 RASH 4 9 216 431 RESPIRATORY DISORDER 4 11 216 431 RHINITIS 11 17 216 431 SINUSITIS 13 28 216 431 UPPER RESP TRACT INFECTION 33 68 216 431 URINARY TRACT INFECTION 6 12 216 431 VOMITING 6 37 216 431 WEIGHT DECREASE 2 9 216 run; /*--Compute Proportions for treatment A & B, Mean and Risk--*/ data ae_risk; set ae; keep pref a b mean lcl ucl; a=na/sna; b=nb/snb; factor=1.96*sqrt(a*(1-a)/sna + b*(1-b)/snb); lcl=a-b+factor; ucl=a-b-factor; mean=0.5*(lcl+ucl); run; /*--Sort by mean value--*/ proc sort data=ae_risk out=ae_sort; by mean; run; /*--Add alternate reference lines--*/ data ae_ref; set ae_sort; if mod(_n_, 2) eq 0 then ref=pref; run; proc print;run; /*--Create template for AE graph--*/ proc template; define statgraph AEbyRelativeRisk; dynamic _thk _grid; begingraph; entrytitle 'Most Frequent On-Therapy Adverse Events Sorted by Risk Difference'; layout lattice / columns=2 rowdatarange=union columngutter=5; /*--Row block to get common external row axes--*/ rowaxes; rowaxis / griddisplay=_grid display=(tickvalues) tickvalueattrs=(size=5); endrowaxes; /*--Column headers with filled background--*/ column2headers; layout overlay / border=true backgroundcolor=cxdfdfdf opaque=true; entry "Proportion"; endlayout; layout overlay / border=true backgroundcolor=cxdfdfdf opaque=true; entry "Risk Difference with 0.95 CI"; endlayout; endcolumn2headers; /*--Left side cell with proportional values--*/ layout overlay / xaxisopts=(display=(ticks tickvalues) tickvalueattrs=(size=7)); referenceline y=ref / lineattrs=(thickness=_thk) datatransparency=0.9; scatterplot y=pref x=a / markerattrs=graphdata2(symbol=circlefilled) name='a' legendlabel="Treatment (N=&NA)"; scatterplot y=pref x=b / markerattrs=graphdata1(symbol=trianglefilled) name='b' legendlabel="Control (N=&NB)"; endlayout; /*--Right side cell with Relative Risk values--*/ layout overlay / xaxisopts=(label='Less Risk More Risk' labelattrs=(size=8) tickvalueattrs=(size=7)); referenceline y=ref / lineattrs=(thickness=_thk) datatransparency=0.9; scatterplot y=pref x=mean / xerrorlower=lcl xerrorupper=ucl markerattrs=(symbol=circlefilled size=5); referenceline x=0 / lineattrs=graphdatadefault(pattern=shortdash); endlayout; /*--Centered side bar for legend--*/ sidebar / spacefill=false; discretelegend 'a' 'b' / border=false; endsidebar; endlayout; endgraph; end; run; ods html close; ods listing gpath=&gpath image_dpi=&dpi style=listing; /*--Render the graph with grid lines without horizontal bands--*/ ods graphics / reset width=6in height=4in imagename='AEbyRelativeRisk'; proc sgrender data=ae_ref template=AEbyRelativeRisk; dynamic _thk='0' _grid='on'; run; /*--Render the graph without grid lines and with horizontal bands--*/ ods graphics / reset width=6in height=4in imagename='AEbyRelativeRiskRef'; proc sgrender data=ae_ref template=AEbyRelativeRisk; dynamic _thk='9' _grid='off'; run;