%let name=stock; filename odsout '.'; /* Put the stock ticker and number of days of data you're interested in in the following macro variables. The stock ticker abbreviation must be one that is used on ichart.finance.yahoo.com, and I have put a list of ones that I verified are good in stock_list.txt */ %let sticker=AAPL; %let fullname=Apple; %let days=250; /* If I want 'n' days worth of data, I have to read down to observation 'n+1' in the data, since the first line is the column headers. Remember, this is "trading days", which excludes weekends. */ %let obsnum=%eval(&days+1); filename dataurl url "http://ichart.finance.yahoo.com/table.csv?s=&sticker" proxy='http://inetgw.fyi.sas.com:80' debug; data mydata; format date date7.; format open high low close adj_close dollar12.2; format volume comma12.0; infile dataurl dlm=',' firstobs=2 obs=&obsnum; input date yymmdd10. open high low close volume adj_close; run; /* insert missing date values for the weekends, so you can use "skipmiss" */ proc sql; select min(date) into :mindate from mydata; select max(date) into :maxdate from mydata; quit; run; data alldates; format date date7.; do date = &mindate to &maxdate; output; end; run; proc sql; create table mydata_plot as select alldates.date, mydata.* from alldates left join mydata on alldates.date = mydata.date; quit; run; /* Guarantee that the data is sorted in ascending order, for the area & skipmiss plot */ proc sort data=mydata_plot out=mydata_plot; by date; run; /* split each obsn into 3 obsns, to use with the gplot hiloc interpolation */ data mydata_plot; set mydata_plot; hlc=high; output; hlc=low; output; hlc=close; output; run; goptions ftitle="arial" ftext="arial" htitle=13pt htext=10pt; GOPTIONS DEVICE=png; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="SAS/Graph Stock Market Plots for &sticker") options(pagebreak='no') style=minimal; axis1 label=none color=graydd value=(color=black) minor=none offset=(0,0); /* axis2 label=(color=black font="albany amt/bold" 'Price' j=r font="albany amt" '(hi/low/close)') */ axis2 label=(color=black font="albany amt/bold" 'Price') color=graydd value=(color=black) major=(number=5) minor=none offset=(0,0); axis3 label=(color=black font="albany amt/bold" 'Volume') color=graydd value=(color=black) major=(number=5) minor=none offset=(0,0); symbol1 color=cx003F87 interpol=join; symbol2 color=cx003F87 value=none interpol=hilocj; pattern1 v=solid color=cxC6E2FF; goptions xpixels=800 ypixels=260; title1 ls=1.5 "Stock Market high/low/close data for: " color=red "&sticker"; title2 c=red "&fullname"; footnote1 h=3pct " "; /* add some white-space between the 2 graphs */ proc gplot data=mydata_plot; plot close*date=1 hlc*date=2 / overlay skipmiss areas=1 haxis=axis1 vaxis=axis2 noframe autohref chref=graydd des='' name="&name"; run; /* Now, do the same plot, but with y-axis starting at zero */ goptions xpixels=800 ypixels=190; title; footnote1 h=3pct " "; /* add some white-space between the 2 graphs */ proc gplot data=mydata_plot; plot close*date=1 hlc*date=2 / overlay skipmiss vzero areas=1 haxis=axis1 vaxis=axis2 noframe autohref chref=graydd des='' name="&name"; run; goptions xpixels=800 ypixels=190; symbol1 color=white interpol=join value=none; symbol2 color=cx009900 interpol=needle; pattern1 v=solid color=cxC6E2FF; pattern1 v=solid color=vlig; pattern1 v=solid color=cxE0EEE0; title1; footnote1 h=15pct " "; proc gplot data=mydata_plot; plot volume*date=2 / haxis=axis1 vaxis=axis3 noframe autohref chref=graydd vref=0 cvref=graydd vzero des='' name="&name"; run; title; footnote link="http://ichart.finance.yahoo.com/table.csv?s=&sticker" "http://ichart.finance.yahoo.com/table.csv?s=&sticker"; proc print data=mydata noobs; run; quit; ods html close ; ods listing ;