libname abc "C:"; %let gpath='C:\'; %let dpi=200; ods html close; ods listing gpath=&gpath image_dpi=&dpi; data dataset2; set abc.Test_dataset; if virus='V2' then virus='A1'; if virus='W1' then virus='B2'; if virus='W3' then virus='C3'; run; /*proc print;run;*/ ods html; /*proc print data=dataset2(firstobs=12 obs=18) noobs;*/ proc print data=dataset2 noobs; var year donset virus week; run; /*--This creates an dattrmap dataset to set the correct color values for the curves --*/ data attrmap; length ID $ 9 fillcolor $ 20; input id $ value $ fillcolor $; datalines; virus A1 darkgreen virus B2 gold virus C3 darkblue ; run; proc print;run; /*--Draw the graph with week labels at bottom--*/ ods graphics on / reset height=3 in width=6in imagename='Virus_BarChart'; proc sgplot data= dataset2 dattrmap=cases2; vbar week / group=virus attrid=virus outlineattrs=(color=black); xaxis label='Onset Week' valueattrs=(size=6); run; /*--Compute frequency values by virus, year, week--*/ proc means data=dataset2(where=(week <=52)); class virus year week; var week; output out=freq(where=(_type_ > 6)) N=N; run; proc print;run; data freq; set freq(keep=virus year week n); n=int(n+2*ranuni(2)); run; proc print;run; proc sort data=freq out=sorted; by year week virus; run; proc print;run; /*--Compute start and end values for each group as stacked on previous--*/ data stacked; retain low 0; format dateOfWeek date9.; length lbl $2; set sorted; by year week; dateOfWeek=mdy(1, 1, year)+(week-1)*7; lbl=' '; if first.week then do; low=0; lbl=put(week, 2.0); end; high=low+n; output; low=high; run; ods html; proc print data=stacked; var dateOfWeek year week virus low high lbl; run; ods html close; ods html close; ods listing gpath=&gpath image_dpi=&dpi; /*--Draw the graph--*/ ods graphics on / reset height=3 in width=6in imagename='HighLow_Timeline'; proc sgplot data=stacked dattrmap=attrmap; format week 2.; highlow x=dateOfWeek low=low high=high / group=virus name='a' type=bar lineattrs=(color=gray) attrid=virus; yaxis display=(nolabel) offsetmin=0 grid; xaxis display=(nolabel); keylegend 'a' / title='Virus' location=inside position=topright across=1; run; /*--Draw the graph with week labels at bottom--*/ ods graphics on / reset height=3 in width=6in imagename='HighLow_Timeline_Label'; proc sgplot data=stacked dattrmap=attrmap; format week 2.; highlow x=dateOfWeek low=low high=high / group=virus name='a' type=bar lineattrs=(color=gray) attrid=virus lowlabel=lbl labelattrs=g(color=black size=6); yaxis display=(nolabel) grid; xaxis display=(nolabel); keylegend 'a' / title='Virus' location=inside position=topright across=1; run; /*--Icon--*/ ods listing image_dpi=100; ods graphics on / reset height=1.8 in width=2.7in imagename='HighLow_Timeline_Icon'; proc sgplot data=stacked(where=(week > 35)) dattrmap=attrmap; format week 2.; highlow x=dateOfWeek low=low high=high / group=virus name='a' type=bar lineattrs=(color=gray) attrid=virus lowlabel=lbl labelattrs=g(color=black size=6); yaxis display=(nolabel) grid; xaxis display=(nolabel); keylegend 'a' / title='Virus' location=inside position=topright across=1; run;