%let gpath='C:\'; %let dpi=100; LIBNAME xdb EXCEL PATH='C:\Series.xls'; ods html close; ods listing gpath=&gpath image_dpi=&dpi; /*--Series Data Set--*/ data series; set xdb.series(where=(date < '01Aug10'd)); rename defect_count=count; run; /*--Sparse Series Data Set--*/ data SparseSeries; set series(where=(date < '01Aug10'd)); if mod(_n_-1, 5) eq 0; run; /*--SparseSeries with label Collision Avoidance--*/ ods graphics / reset width=5in height=3in imagename='SparseSeriesAllLabels'; title 'Open Defects by Date'; proc sgplot data=SparseSeries; series x=date y=count / datalabel=count lineattrs=(thickness=2); xaxis grid display=(nolabel); yaxis grid; run; /*--Series with label Collision Avoidance--*/ ods graphics / reset width=5in height=3in imagename='SeriesAllLabels'; title 'Open Defects by Date'; proc sgplot data=series; series x=date y=count / datalabel=count lineattrs=(thickness=2); xaxis grid display=(nolabel); yaxis grid; run; /*--Series without label Collision Avoidance--*/ ods graphics / reset width=5in height=3in labelmax=0 imagename='AllLabelsFixed'; title 'Open Defects by Date'; proc sgplot data=series; series x=date y=count / datalabel=count lineattrs=(thickness=2); xaxis grid display=(nolabel); yaxis grid; run; /*--Get Loess fit and limits--*/ ods graphics / reset; proc loess data=series; model count=date /smooth=0.1 residual cl alpha=0.001; ods output OutputStatistics=Loess; run; /*proc print data=loess;run;*/ /*--Series and band with reduced labels--*/ ods graphics / reset width=5in height=3in imagename='LoessBand'; title 'Open Defects by Date'; proc sgplot data=Loess; band x=date upper=upperCL lower=lowerCL; series x=date y=depvar; xaxis display=(nolabel); yaxis grid; run; /*--Thin labels in data set--*/ data loessLabels; set Loess end=last; retain prev 0; /*--Keep label if vertex is more than factor * band width from predicted--*/ band = uppercl - lowercl; /*--Do this only if bandwidth > 0--*/ if band > 0 then do; diff = abs(depvar-pred); ratio = diff / band; /*--If point is > 40% of bandwidth away from fit then label it--*/ /*--If 10th consecutive unlabeled point, then label it--*/ if ratio > 0.4 then do; loesslabel = depvar; loessPluslabel=depvar; prev=_n_; end; if (_n_ - prev > 10) then do; loessPluslabel = depvar; prev=_n_; end; end; /*--Label first and last points--*/ if last or _N_ = 1 then do; loesslabel = depvar; loessPluslabel=depvar; end; run; /*proc print;run;*/ /*--Series and band with reduced labels--*/ ods graphics / reset width=5in height=3in imagename='ReducedLabelsBand'; title 'Open Defects by Date'; proc sgplot data=loessLabels noautolegend; band x=date upper=upperCL lower=LowerCL; series x=date y=depvar / datalabel=loesslabel lineattrs=(thickness=2) datalabelattrs=(size=8); xaxis grid display=(nolabel); yaxis grid label='Defects'; run; /*--Series and Scatter with Loess labels--*/ ods graphics / reset width=5in height=3in imagename='ReducedLoessScatter'; title 'Open Defects by Date'; proc sgplot data=loessLabels noautolegend; series x=date y=depvar / datalabel=loesslabel lineattrs=(thickness=2) datalabelattrs=(size=8); scatter x=date y=loesslabel / markerattrs=(symbol=circlefilled size=9); scatter x=date y=loesslabel / markerattrs=(symbol=circlefilled size=5 color=white); xaxis grid display=(nolabel); yaxis grid label='Defects'; run; /*--Series Scatter and band with Loess + 10th labels--*/ ods graphics / reset width=5in height=3in imagename='ReducedLoessPlusScatter'; title 'Open Defects by Date'; proc sgplot data=loessLabels noautolegend; series x=date y=depvar / datalabel=loessPluslabel lineattrs=(thickness=2) datalabelattrs=(size=8); scatter x=date y=loessPluslabel / markerattrs=(symbol=circlefilled size=9); scatter x=date y=loessPluslabel / markerattrs=(symbol=circlefilled size=5 color=white); xaxis grid display=(nolabel); yaxis grid label='Defects'; run;