/*--Adverse Events timeline data--*/ data ae0; retain aestdateMin; retain aeendateMax; attrib aestdate informat=yymmdd10. format=date7.; attrib aeendate informat=yymmdd10. format=date7.; format aestdateMin aeendateMax date7.; drop aestdateMin aeendateMax; input aeseq aedecod $ 5-39 aesev $ aestdate aeendate; aestdateMin=min(aestdate, aestdateMin); aeendateMax=max(aeendate, aeendateMax); call symputx('mindate', aestdateMin); call symputx('maxdate', aeendateMax); y=aeseq; if aedecod="DUMMY" then y=-100; cards; 1 DUMMY MILD 2013-03-06 2013-03-06 3 3 1 DUMMY MODERATE 2013-03-06 2013-03-06 3 3 1 DUMMY SEVERE 2013-03-06 2013-03-06 3 3 1 DIZZINESS MODERATE 2013-03-06 2013-03-06 3 3 2 COUGH MILD 2013-03-20 . 17 . 3 APPLICATION SITE DERMATITIS MILD 2013-03-26 2013-06-18 23 107 4 DIZZINESS MILD 2013-03-27 2013-03-27 24 24 5 ELECTROCARDIOGRAM T WAVE INVERSION MILD 2013-03-30 . 27 . 6 DIZZINESS MILD 2013-04-01 2013-04-11 29 39 7 DIZZINESS MILD 2013-04-01 2013-04-11 29 39 8 APPLICATION SITE DERMATITIS MODERATE 2013-03-26 2013-06-18 23 107 9 HEADACHE MILD 2013-05-17 2013-05-18 75 76 10 APPLICATION SITE DERMATITIS MODERATE 2013-03-26 2013-06-18 23 107 11 PRURITUS MODERATE 2013-05-27 2013-06-18 85 107 ; run; /*--Evaluate min and max day and dates--*/ data _null_; set ae0; minday=0; maxday= &maxdate - &mindate; min = -12; delta = min - &minday; mindate2 = &mindate + delta; call symputx('mindate2', mindate2); call symputx('minday2', min); call symputx('minday', minday); call symputx('maxday', maxday); run; /*--Compute start and end date and days and X position of event name--*/ data ae1; set ae0; aestdy= aestdate-&mindate+0; aeendy= aeendate-&mindate+0; startday=aestdy; endday=aeendy; if aestdy=. then startday=&minday; if aeendy=. then endday=&maxday; run; /*--Find longest aedecod name length--*/ data _null_; retain maxlen 0; set ae1 end=last; maxlen=max(maxlen, length(strip(aedecod))+2); if last then call symputx("MaxLen", 2*(maxlen)); run; /*--Load aedecod name into a name buffer that is twice the longest aedecod name--*/ /*--The aedecod name is placed right justified in the first half of the buffe r--*/ /*--If buffer is 40 char, do this ..........DIZZYNESS..................... --*/ data ae; /* keep xs ys y lastday aesev aestdy aeendy aestdate aeendate buffer aeseq aedecod;*/ length buffer $&maxlen; set ae1; if aedecod ne '' then do; len = length(strip(aedecod)); offset = &maxlen/2-len; /*--Replace all blanks in the string buffer with nbsp--*/ buffer=translate(buffer, 'A0'x, ' '); /*--Insert the aedecod string into the buffer, right justified to the center--*/ substr(buffer, offset, len)=strip(aedecod); end; run; /*--Custom style for severity of events--*/ proc template; define Style AETimeline; parent = styles.listing; style GraphColors from graphcolors / "gcdata" = cx000000 "gcdata1" = cx1fcf1f "gcdata2" = cxdfbf1f "gcdata3" = cxbf1f1f; style GraphFonts from GraphFonts / 'GraphDataFont' = (", ",5pt) 'GraphValueFont' = (", ",7pt) 'GraphTitleFont' = (", ",11pt); end; run; /*--Draw the Graph--*/ %let gpath='C:\'; ods listing style=AETimeline image_dpi=100 gpath=&gpath; ods graphics / reset width=7in height=4in imagename="AE_Timeline_V92"; title "Adverse Events for Patient Id = xx-xxx-xxxx"; proc sgplot data=ae noautolegend nocycleattrs; refline 0 / axis=x lineattrs=(thickness=1 color=black); /*--Draw the events--*/ vector x=endday y=y / xorigin=startday yorigin=y noarrowheads lineattrs=(thickness=9px); vector x=endday y=y / xorigin=startday yorigin=y noarrowheads lineattrs=(thickness=7px pattern=solid) transparency=0 group=aesev name='sev'; /*--Draw start and end events--*/ scatter x=aestdy y=y / markerattrs=(size=13px symbol=circlefilled); scatter x=aestdy y=y / markerattrs=(size=11px symbol=circlefilled) group=aesev; scatter x=aeendy y=y / markerattrs=(size=13px symbol=circlefilled); scatter x=aeendy y=y / markerattrs=(size=11px symbol=circlefilled) group=aesev; /*--Draw the event name using non-proportional font--*/ scatter x=aestdy y=y / markerchar=buffer markercharattrs=(family='Lucida Console' size=9); /*--Assign dummy plot to create independent X2 axis--*/ scatter x=aestdate y=y / markerattrs=(size=0) x2axis; /*--Assign axis properties data extents and offsets--*/ yaxis display=(nolabel noticks novalues) min=0; xaxis grid label='Study Days' offsetmin=0.1 offsetmax=0.02 values=(&minday2 to &maxday by 2); x2axis notimesplit display=(nolabel) offsetmin=0.1 offsetmax=0.02 values=(&mindate2 to &maxdate); /*--Draw the legend--*/ keylegend 'sev'/ title='Severity :'; run;