libname abc 'C:\'; %let gpath='C:\'; %let dpi=200; ods html close; ods listing gpath=&gpath image_dpi=&dpi; /*--Sort data by onset date and virus--*/ proc sort data=abc.Test_dataset out=dataset; by donset virus; run; /*--Compute data range and YearWeek variable--*/ data dataset2; retain min 1e10 max -1e10; set dataset(keep=year donset virus week) end=last; if virus='V2' then virus='A1'; if virus='W1' then virus='B2'; if virus='W3' then virus='C3'; min=min(min, donset); max=max(max, donset); yearWeek=year || '-' || put(week, z2.0); if last then do; call symput ("Min", min); call symput ("Max", max); end; run; /*--Compute frequency values by virus, year, week--*/ proc means data=dataset2; class yearweek virus; var week; output out=freq(where=(_type_ > 2)) N=N; run; /*--Sort data by onset date and virus--*/ proc sort data=freq(keep=yearWeek virus n) out=sorted; by yearweek virus; run; /*--Create an observation for each week in date range--*/ data fill; drop prev; prev=-1; virus='A1'; do donset=&min to &max; year=year(donset); week=week(donset)+1; yearWeek=year || '-' || put(week, z2.0); if week ne prev then do; output; prev=week; end; end; run; /*--Merge data and add data for labels--*/ data merged; merge fill sorted; by yearWeek virus; zero=0; if virus='A1' then small=-0.3; else small=0; ywstrip=strip(yearweek); ylabel=11; xlabel1=' '; xlabel2=' '; label=' '; if ywstrip='2013-53' then do; xlabel1='2013-53'; label='<- 2013'; end; if ywstrip='2014-01' then do; xlabel2='2014-01'; label='2014 ->'; end; run; /*--Define GTL Template--*/ proc template; define statgraph Epidemic; begingraph / datacolors=(darkgreen orange); entrytitle 'Onset by Week and Virus'; layout overlay / walldisplay=none xaxisopts=(display=none) yaxisopts=(label='Frequency' display=(tickvalues label) tickvalueattrs=(size=6) griddisplay=on linearopts=(tickvaluelist=(0 2 4 6 8 10))); barchart category=ywstrip response=n / group=virus display=(fill) name='a'; scatterplot x=ywstrip y=small / markercharacter=week markercharacterattrs=(size=6) labelstrip=true; referenceline x='2014-01' / discreteoffset=-0.5; scatterplot x=xlabel1 y=ylabel / markercharacter=label markercharacterposition=left contributeoffsets=none; scatterplot x=xlabel2 y=ylabel / markercharacter=label markercharacterposition=right contributeoffsets=none; discretelegend 'a'; endlayout; endgraph; end; run; /*--Render Graph--*/ ods graphics / reset width=6in height=3in imagename='Epidemic_GTL_94'; proc sgrender data=merged template=Epidemic; run; /*--Template with Year block--*/ proc template; define statgraph EpidemicBlock; begingraph / datacolors=(darkgreen orange); entrytitle 'Onset by Week and Virus'; layout overlay / walldisplay=none xaxisopts=(display=none) yaxisopts=(label='Frequency' display=(tickvalues label) tickvalueattrs=(size=6) griddisplay=on linearopts=(tickvaluelist=(0 2 4 6 8 10))); blockplot x=ywstrip block=year / datatransparency=0.7 display=(fill values) valuehalign=center valuevalign=top filltype=alternate fillattrs=(color=lightblue) altfillattrs=(color=lightpink); barchart category=ywstrip response=n / group=virus display=(fill) name='a' dataskin=pressed; scatterplot x=ywstrip y=small / markercharacter=week markercharacterattrs=(size=6) labelstrip=true; referenceline x='2014-01' / discreteoffset=-0.5; discretelegend 'a'; endlayout; endgraph; end; run; /*--Render Graph--*/ ods graphics / reset width=6in height=3in imagename='Epidemic_Block_GTL_94'; proc sgrender data=merged template=EpidemicBlock; run;