%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_1; keep date high low open close datechar dateref; 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); datechar=put(date, date7.); run; /*--Sort--*/ proc sort data=amzn_1 out=amzn_s; by date; run; /*--Compute additional columns--*/ data amzn_2; retain prev prevmonth; drop pref prevmonth month; length move $4; set amzn_s; /*--Keep first date in a month--*/ month=month(date); if month ne prevmonth then do; dateref=datechar; prevmonth=month; end; if close > prev then move='Up'; else move='Down'; output; prev=close; run; /*--Stock Plot with Time x axis--*/ ods graphics / reset width=&w height=&h imagename='Stock_Plot_Linear'; title 'Stock Price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Jun2017'd)) noborder; highlow x=date low=low high=high / open=open close=close lineattrs=(thickness=2) y2axis; y2axis display=(noline noticks nolabel) grid; xaxis display=(nolabel); run; /*--Stock Plot with Default Discrete x axis--*/ ods graphics / reset width=&w height=&h imagename='Stock_Plot_Discrete_Default'; title 'Stock Price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Jun2017'd)) noborder; highlow x=datechar low=low high=high / open=open close=close lineattrs=(thickness=2) y2axis; y2axis display=(noline noticks nolabel) grid; xaxis type=discrete display=(nolabel) discreteorder=data; run; /*--Stock Plot with Discrete x axis and Axis Table--*/ ods graphics / reset width=&w height=&h imagename='Stock_Plot_Discrete'; title 'Stock Price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Jun2017'd)) noborder; refline dateref / axis=x lineattrs=graphgridlines; highlow x=datechar low=low high=high / open=open close=close lineattrs=(thickness=2) y2axis; xaxistable dateref / nolabel valueattrs=(weight=bold); y2axis display=(noline noticks nolabel) grid; xaxis type=discrete display=(nolabel novalues noticks) discreteorder=data; run; /*--Define attributes map data set--*/ data AttrMap; length id value linecolor $8; id='Move'; value='Up'; linecolor='Green'; output; id='Move'; value='Down'; linecolor='DarkRed'; output; run; /*--Stock Plot with nice axis and color--*/ ods graphics / reset attrpriority=color width=&w height=&h imagename='Stock_Plot_Discrete_Group'; title 'Stock Price for Amazon by Date'; proc sgplot data=amzn_2(where=(date > '01Jun2017'd)) noborder noautolegend dattrmap=attrmap; /* styleattrs datacontrastcolors=(darkred green);*/ refline dateref / axis=x lineattrs=graphgridlines; highlow x=datechar low=low high=high / open=open close=close group=move lineattrs=(thickness=2) y2axis attrid=Move; xaxistable dateref / nolabel valueattrs=(weight=bold); y2axis display=(noline noticks nolabel) grid; xaxis type=discrete display=(nolabel novalues noticks) discreteorder=data; run; title;