%let gpath='c:\'; %let dpi=150; /*--Compute data ranges for volume and close--*/ data ibm; retain volMin 1E10 volMax -1e10; retain yMin 1E10 yMax -1e10; set sashelp.stocks(where=(stock = 'IBM' and date > '01Jan2003'd)) end=last; keep date stock close volume; volMin=min(volMin, volume); volMax=max(volMax, volume); yMin=min(yMin, close); yMax=max(yMax, close); if last then do; call symputx ("volMin", volMin); call symputx ("volMax", volMax); call symputx ("volRange", volMax-volMin); call symputx ("yMin", yMin); call symputx ("yMax", yMax); call symputx ("yRange", yMax-yMin); end; run; %let height=300; %let maxThick=200; %let minThick=1; /*--Compute band thickness in terms of y axis data range--*/ data ibm2; set ibm; label volmil='Volume (Millions)'; format volmil f3.1; volMil=volume/1e6; thick=(volume-&volMin)/&volRange; delta=(&minThick + thick) * &yrange / &height; lower=close - &maxThick * delta; run; /*--Conditioned Series Plot--*/ ods html close; ods listing gpath=&gpath image_dpi=&dpi; /*--Series Plot with Volume--*/ ods graphics / reset width=5in height=3in imagename='SeriesNeedle'; proc sgplot data=ibm2 noautolegend; title 'Monthly Closing Price with Volume'; series x=date y=close / lineattrs=graphdata1(thickness=3) transparency=0.3; needle x=date y=volmil / y2axis lineattrs=(thickness=5) transparency=0.5; yaxis grid offsetmin=0.4; y2axis grid offsetmax=0.7 offsetmin=0; run; /*--Conditioned Series Plot with Volume--*/ footnote j=l 'Width of plot represents the trading volume'; ods graphics / reset width=5in height=3in imagename='ThickSeries'; proc sgplot data=ibm2 noautolegend; title 'Monthly Closing Price Conditioned by Volume'; band x=date upper=close lower=lower / fill fillattrs=graphdata1 transparency=0.5; needle x=date y=volume / y2axis; yaxis min=0 grid; y2axis display=(noticks novalues nolabel) offsetmax=0.7; run; /*--Conditioned Series Plot with Volume--*/ ods graphics / reset width=5in height=3in imagename='ThickSeries_HighLow'; proc sgplot data=ibm2 noautolegend; title 'Monthly Closing Price Conditioned by Volume'; band x=date upper=close lower=lower / fill fillattrs=graphdata1 transparency=0.3; series x=date y=close / lineattrs=(thickness=2) transparency=0.5; highlow x=date high=close low=lower / transparency=0.8; yaxis min=0 grid; y2axis display=(noticks novalues nolabel); run; /*--Compute data ranges for volume and close--*/ data TwoStocks; retain volMin 1E10 volMax -1e10; retain yMin 1E10 yMax -1e10; set sashelp.stocks(where=(stock ne 'Microsoft' and date > '01Jan2003'd)) end=last; keep date stock close volume; volMin=min(volMin, volume); volMax=max(volMax, volume); yMin=min(yMin, close); yMax=max(yMax, close); if last then do; call symputx ("volMin", volMin); call symputx ("volMax", volMax); call symputx ("volRange", volMax-volMin); call symputx ("yMin", yMin); call symputx ("yMax", yMax); call symputx ("yRange", yMax-yMin); end; run; %let height=300; %let maxThick=50; %let minThick=1; /*--Compute band thickness in terms of y axis data range--*/ data TwoStocks2; set TwoStocks; thick=(volume-&volMin)/&volRange; delta=(&minThick + thick) * &yrange / &height; lower=close - &maxThick * delta; run; /*--Conditioned Series Plot with Volume--*/ ods listing gpath=&gpath image_dpi=&dpi; ods graphics / reset width=5in height=3in imagename='ThickSeries_TwoStocks'; proc sgplot data=TwoStocks2 noautolegend; title 'Monthly Closing Price Conditioned by Volume'; band x=date upper=close lower=lower / group=stock fill transparency=0.3; series x=date y=close / group=stock lineattrs=(pattern=solid thickness=2) transparency=0.5 curvelabel curvelabelpos=max curvelabelattrs=(weight=bold); highlow x=date high=close low=lower / group=stock lineattrs=(pattern=solid) transparency=0.8; yaxis grid; y2axis display=(noticks novalues nolabel); run; footnote;