/*------------------------------------------------------------------*/
/* Ticker.sas – A Simple Stock Quote Retrieval Program */
/*------------------------------------------------------------------*/
filename in url
"http://finance.yahoo.com:80/d/quotes.txt?s=YHOO+IBM+HPQ&f=sl1d1t1c1ohgv&e=.txt)";
data;
infile in dsd end=eof termstr=crlf;
input Ticker : $4. Price TradeDate : $10. TradeTime: $7. Change Open High Low Volume;
options nodate nonumber nocenter ls=70;
proc print width=u;
title 'Stock Quotes';
id Ticker;
run;
/*-----------------------------------------------------------------------*/
/* TickerMacro.sas – Stock Quote Retrieval With Refresh */
/* Parameters: */
/* SYMBOLS stock symbols */
/* SLEEP seconds between stock quote refreshes */
/* MAX number of times to refresh stock quotes */
/* OUT sas data set name containing stock quotes */
/*------------------------------------------------------------------------*/
%macro GetQuotes(Symbols=, Sleep=1, Max=10,Out=work.getquotes);
*--> Fetch Stock Quotes Specified Number Of Times;
%do i=1 %to &max;
filename in url "http://finance.yahoo.com:80/d/quotes.txt?s=&symbols.&f=sl1d1t1c1ohgv&e=.txt)"; *--> Retrieve Stock Quotes From Yahoo; data; infile in dsd end=eof termstr=crlf; input Ticker : $4. Price TradeDate : $10. TradeTime: $7. Change Open Hi Lo Volume; AsOf=put(today(),yymmdd10.)||' At '|| put(time(),time8.); *--> Add Stock Quotes To SAS Data Set; proc append base=&out data=_last_; options nodate nonumber nocenter ls=70 ps=1000; *--> Produce Cumulative Stock Quote Comparison Report; proc tabulate data=GetQuotes; Title Stock Quotes By Ticker; class Ticker AsOf TradeDate TradeTime; var Price Change; tables Ticker*AsOf*TradeDate*TradeTime, (Price Change)*f=7.2 / rts=50; keylabel sum=' '; *--> Pause Specified Number Of Seconds Between Refreshes; data; %if &i<=&max %then x=sleep(&sleep);; run; %end; %mend; /* Get Quotes For Yahoo, IBM, and Hewlett Packard Wait 5 Minutes (300 */ /* Seconds) Before Refreshing Stock Quotes Refresh Quotes 36 Times */ /*%GetQuotes(Symbols=YHOO+IBM+HPQ, Sleep=300, Max=36);*/ %GetQuotes(Symbols=YHOO+IBM+HPQ, Sleep=10, Max=5); |
/* 看官,请点击帖子左下角的“评分”给点鼓励吧! */