%let gpath=C:\; ods html close; %let w=5in; %let h=2.5in; %let dpi=200; ods listing gpath="&gpath" image_dpi=&dpi; libname data 'C:\Work\Data'; /*--Read CSV data for AMZN--*/ proc import datafile='C:\Work\Data\Amzn.csv' dbms=csv out=data.amzn replace; getnames=yes; run; /*--Convert to SAS data types--*/ data amzn; keep date high low open close; format date date7.; format high low open close dollar8.2; set data.amzn(firstobs=2 rename=(date=datec open=openc close=closec high=highc low=lowc)) end=last; date=input(datec, yymmdd10.); high=input(highc, 6.2); low=input(lowc, 6.2); open=input(openc, 6.2); close=input(closec, 6.2); run; proc sort data=amzn out=amzn_1; by date; run; /*--Convert to SAS data types--*/ data amzn_2; retain prev; length move $4; keep date high low open close lowcap highcap move lowlabel highlabel from to prev /*datec dater*/; format date date7.; format high low open close lowlabel highlabel from to dollar8.2; set amzn_1 end=last; if close > prev then do; move='Up'; highcap='FilledArrow'; highlabel=close; from=prev; to=close; end; else do; move='Down'; lowcap='FilledArrow'; lowlabel=close; from=close; to=prev; end; output; prev=close; run; /*--Basic HighLow Line plot--*/ ods graphics / reset width=&w height=&h imagename='HighLow'; title 'Stock price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Jan2017'd)) noborder; highlow x=date low=low high=high; yaxis display=(noline noticks nolabel) grid; xaxis display=(nolabel); run; /*--Basic OHLC Line plot--*/ ods graphics / reset width=&w height=&h imagename='HighLowOPenClose'; title 'Stock price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Apr2017'd)) noborder; highlow x=date low=low high=high / open=open close=close; yaxis display=(noline noticks nolabel) grid; xaxis display=(nolabel); run; /*--With caps--*/ ods graphics / reset attrpriority=color width=&w height=&h imagename='Cap_Line'; title 'Stock price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Jun2017'd)) noborder noautolegend; styleattrs datacontrastcolors=(green red); highlow x=date low=from high=to / lowcap=lowcap highcap=highcap group=move lineattrs=(thickness=2); yaxis display=(noline noticks nolabel) grid; xaxis display=(nolabel); run; /*--Type Bar--*/ ods graphics / reset attrpriority=color width=&w height=&h imagename='Cap_Bar'; title 'Stock price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Sep2017'd)) noborder noautolegend; styleattrs datacolors=(red green) datacontrastcolors=(black); highlow x=date low=from high=to / type=bar lowcap=lowcap highcap=highcap group=move; yaxis display=(noline noticks nolabel) grid; xaxis display=(nolabel); run; ods html; proc print data=amzn_2(where=(date > '01Sep2017'd)) ; run; ods html close; /*--Type Bar Skin label--*/ ods graphics / reset attrpriority=color width=&w height=&h imagename='Cap_Bar_Skin_Label'; title 'Stock price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Sep2017'd)) noborder noautolegend; styleattrs datacolors=(red green) datacontrastcolors=(black); highlow x=date low=from high=to / type=bar lowcap=lowcap highcap=highcap group=move dataskin=gloss lowlabel=lowlabel highlabel=highlabel labelattrs=(weight=bold); yaxis display=(noline noticks nolabel) grid; xaxis display=(nolabel); run; /*--Icon--*/ ods listing image_dpi=100; ods graphics / reset attrpriority=color width=2.7in height=1.8in imagename='HighLow_Icon'; title 'Stock price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '10Sep2017'd)) noborder noautolegend; styleattrs datacolors=(green red) datacontrastcolors=(black); highlow x=date low=from high=to / type=bar lowcap=lowcap highcap=highcap group=move dataskin=gloss lowlabel=lowlabel highlabel=highlabel labelattrs=(weight=bold); yaxis display=(noline noticks nolabel) grid; xaxis display=(nolabel); run; title;