/* Richard A. DeVenezia 2/16/2001; * www.devenezia.com * * This annontation example was originally posted to SAS-L on Feb. 16, 2001 * Updated 1/21/2004 to generate png image file and use truetype fonts */ data risk; retain seed 54321; drop seed; do patientid = 1 to 5000; length treatment $8; if ranuni (seed) < .5 then treatment = 'Trt 1'; else treatment = 'Placebo'; daysIntoStudy = int (9 * ranuni(seed)) * 30; patientAge = 20 + int (50*ranuni(seed)); output; end; label daysIntoStudy = 'Days into study' patientAge = 'Patient age' ; run; proc format; value ageGroup 20-29 = 'Twenties' 30-39 = 'Thirties' 40-49 = 'Forties' 50-59 = 'Fifties' 60-69 = 'Sixties' 70-79 = 'Seventies' ; run; * ensure the summary has all treatments at all days; proc sql; create table allDaysTreat as select *, 0 as N from (select distinct daysIntoStudy from risk) , (select distinct treatment from risk) ; create table treatmentSummary as select daysIntoStudy , treatment , count (treatment) as N from risk group by daysIntoStudy, treatment ; quit; data anno (keep=xsys ysys x y function text when); length when $1 function $8; retain ysys '3' function 'LABEL' when 'AFTER'; merge allDaysTreat treatmentSummary; by daysIntoStudy treatment; retain yDelta 3; if first.daysIntoStudy then row=0;else row++1; Y = 13 - row * .9 * yDelta; if daysIntoStudy = 0 then do; if _n_ = 1 then do; xsys = '1'; X = 50; Y = Y + yDelta; text = 'Patients at risk'; output; Y = Y - yDelta; end; xsys = '3'; X = 10.5; text = treatment; output; end; xsys = '2'; X = daysIntoStudy; text = trim(left(put(N,best8.))); output; run; data frame; xsys='3'; ysys='3'; x= 0;y= 0;function='MOVE';output; x= 0;y=100;function='DRAW';output; x=100;y=100;function='DRAW';output; x=100;y= 0;function='DRAW';output; x= 0;y= 0;function='DRAW';output; run; options errors=0; libname gdevice0 "%sysfunc(pathname(WORK))"; proc gdevice catalog=gdevice0.devices nofs; delete bigpng; copy png from=sashelp.devices newname=bigpng; modify bigpng xmax=11.6in xpixels=1102 ymax=11.6in ypixels=1102; run; goptions reset=all; *goptions device=win targetdevice=winprtc rotate=landscape; *goptions ftext=swiss; goptions ftext='Comic Sans MS'; goptions target=bigpng hsize=8in vsize=7in; *filename pngout "\\Extreme\samples\stacked-vbar-chart.png"; *goptions device=bigpng gsfname=pngout; axis1 origin=(15pct,24pct) length=75pct label=NONE ; axis2 label=('N') length=65pct; title1 j=c h=5pct "Drug trial"; title2 j=c h=2.5pct "Bars stacked by subgroup 'patient age'"; title3 j=c h=2.5pct "Annotate displays subgroup 'patients at risk'"; goptions htext=2.5pct; proc gchart data=risk annotate=anno; format patientAge ageGroup.; vbar daysIntoStudy / discrete maxis = axis1 raxis = axis2 subgroup = patientAge width=6 anno=frame ; run; quit; options errors=20; goptions reset=all;