全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
25829 113
2012-12-22
为了能够及时跟踪证券市场的行情,证券分析师或者投资者需要及时“刷新”浏览器来检查各类报价。那么,如何以SAS系统为平台从互联网上直接获取证券报价?这里将通过一个简短的SAS程序和宏代码,展示如何基于SAS URL技术来检索广域或者局域网站的数据。这样,有兴趣的人们便可以基于SAS平台,通过数据分析来把握证券的实时走势了。
/*------------------------------------------------------------------*/
/* 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;
simple.png
/*-----------------------------------------------------------------------*/
/* 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);
quotes.png
/* 看官,请点击帖子左下角的“评分”给点鼓励吧! */

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-12-22 12:11:25
哈哈,楼主的签名亮了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-12-23 08:44:11
SAS URL技术不仅可用来接收股票报价  
做互联网的文本挖掘也是可以的
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-12-23 13:33:28
take a look and leave a mark!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-12-23 23:42:37
页面保存下来,慢慢啃,感谢大神分享~~~
很有启示。。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-12-24 10:06:00
louzhuqueshilihaia
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群