全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2384 7
2013-05-17
编程的目的是:将每个股票(300多个)从第1个交易日(不同股票不一样)到第n个交易日(n=10~1200)的股票价格看做y变量,将大盘指数看做x变量,做回归,得出自变量的系数,系数的p值,回归的拟合优度。并将这些结果以及每次计算的时间、股票代码做成表格的形式呈现出来。
我已经编好了,但速度比较慢,而且越运行到后面就越慢,但是关闭SAS重新开始,就快些了。
一共要做240000多次回归,如果按照这速度。。。1年才能做完啊。。。希望高手帮忙优化!争取答辩之前做出来呀!

%macro yy(code,date);
/*创建一个新数据集,用于存放从原始数据beta中提取的需要回归的数据*/
data data&code&date;
set beta;
where code=&code and date<=&date;

/*将回归结果显示到数据集中*/
ods listing close;
ods output parameterestimates(match_all persist=proc)=Estimates&code&date;
ods output fitstatistics(match_all persist=proc)=fitstatistics&code&date;

/*做回归*/
proc reg data=data&code&date;
model prc=idx ;
run;

/*对目标数据集中加入两个变量:时间和股票代码*/
data Estimates&code&date;
set Estimates&code&date;
code=&code;
date=&date;
run;

data fitstatistics&code&date;
set fitstatistics&code&date;
code=&code;
date=&date;
run;

/*删除数据集中多余的变量,并保存到optimize文件夹中*/
data optimize.Est;
set Estimates&code&date optimize.Est;
drop _Run_ Model DF _proc_ dependent;
run;
data optimize.fits;
set fitstatistics&code&date optimize.fits;
drop _Proc_ _Run_ Model Label1 cValue1 nValue1 dependent;
run;
ods listing;

/*删除所有的临时数据集*/
proc datasets library=work kill nolist; quit;

   %mend yy;
%include "E:\optimize\yy2.txt";
run;
quit;



yy2.txt:(大概内容如下)
%yy( 600603 , 19971201 );%yy( 600603 , 19971202 );%yy( 600603 , 19971203 );%yy( 600603 , 19971204 );%yy( 600603 , 19971205 );%yy( 600603 , 19971208 );%yy( 600603 , 19971209 );%yy( 600603 , 19971210 );%yy( 600603 , 19971211 );%yy( 600603 , 19971212 );%yy( 600603 , 19971215 );

二维码

扫码加我 拉你入群

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

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

全部回复
2013-5-17 21:03:39
BY-Group processing is the key, DO NOT use  macro at all.

(1) First repeat each record as many times as the number regressions including the record.
Sort your data by code and date.
Within code i: Let N_i = # of dates within Code i. Repeat record 1 for N_i-9 times, record 2 for N_i-10 times, ..., and so on.
Assign each replicate into a unique regression #.
(2) Sort by code, Regression #
(3) run PROC REG by code and regression #.
二维码

扫码加我 拉你入群

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

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

2013-5-17 21:19:57
邓贵大 发表于 2013-5-17 21:03
BY-Group processing is your answer.
group by语句吗?分组?能说具体一点吗?谢谢!
二维码

扫码加我 拉你入群

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

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

2013-5-17 21:29:22
邓贵大 发表于 2013-5-17 21:03
BY-Group processing is your answer.
能写出具体的程序吗,给大家介绍共同学习一下。
二维码

扫码加我 拉你入群

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

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

2013-5-17 22:03:14
It takes about 10-20 minutes.
复制代码
If you're pretty familar with the matrix algebra behind Simple Linear Regression, do it in IML or maybe PROC FCMP. That'll be much faster as you don't have to roll your data along the time line.
二维码

扫码加我 拉你入群

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

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

2013-5-18 04:47:28
邓贵大 发表于 2013-5-17 22:03
It takes about 10-20 minutes. If you're pretty familar with the matrix algebra behind Simple Linear  ...
非常精彩的sas语句。受益良多。
对作者的要求也许略有不同。比如max(10,)。但是无论如何,10以下的数据是几乎不消耗时间的。
今天刚好下午清闲。按照作者的数据尺寸(24万的数据,每个code含有记录从10到1000不等),把这个ROLLING REGRESSION做了一遍。大概时间消耗如下:
展开数据:4分钟(数据记录大概1亿上下)
排序:13分钟
回归:5分钟
其他:0.5分钟

总计:22.5分钟。顺便说一句:我的电脑配置很烂。
因为是simple regression, (one predictor), 所以可以在数据步里做。只需要10秒左右。没有iml。无法测试。
另外,这也印证了我的一个感觉:凡是在SIMULATION里写宏程序的,基本上都不自觉地采用那个最慢的方法。
京剧
具体可以参看:http://blog.sina.com.cn/s/blog_a3a926360101cxve.html
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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