proc format; value stock 3='Microsoft' 2='Intel' 1='IBM' other=''; run; /*--Sort subset of data by Stock--*/ proc sort data=sashelp.stocks(where=(date ge '01Jan04'd and date le '31dec05'd)) out=stocks2005; by stock; run; /*--Compute range of closing values for each stock--*/ data _null_; set stocks2005; retain min max n 0; by stock; if close ne .; if first.stock then do; min=1000; max=0; n+1; end; min=min(close, min); max=max(close, max); if last.stock then do; call symput ("Max" || put (n, 1.0), max); call symput ("Min" || put (n, 1.0), min); end; run; /*--Normalize and stack the values--*/ /*--YearMin and YearMax are used in the table--*/ /*--YRef is used to draw the alternate bands--*/ data spark; set stocks2005(keep=stock date open close high low adjclose volume); retain y n max min range 0; format yearmin yearmax dollar6.2; by stock; if close ne .; MinLabel="Min"; MaxLabel="Max"; if first.stock then do; y + 1; n + 1; max=symget("Max" || put (n, 1.0)); min=symget("Min" || put (n, 1.0)); range=max - min; yearMin=min; yearMax=max; if mod(y, 2) ne 0 then yref=y; output; yref=.; end; yc = y + 0.6 * ((close-min)/range-0.5); output; run; %let gpath='C:\'; ods listing gpath=&gpath image_dpi=150; ods graphics / reset width=3in height=1.5in antialiasmax=1000 imagename='Stock_Table_SG'; title h=1 'Stock Trends Spark Plot'; proc sgplot data=spark noautolegend; format y yc yref stock.; refline yref / lineattrs=(thickness=32) transparency=0.85; series x=date y=yc / group=stock lineattrs=graphdatadefault(pattern=solid); scatter y=y x=MaxLabel / markerchar=yearmax x2axis; scatter y=y x=MinLabel / markerchar=yearmin x2axis; xaxis display=none offsetmin=0.01 offsetmax=0.3; x2axis display=(nolabel noticks) offsetmin=0.75; yaxis values=(1 to 3) valueshint display=(nolabel noticks); run;