我有以下的代碼來計算收益的滾動窗口上的偏度:計算滾動偏度和峯度在SAS迅速爲一個非常大的數據集
libname backup 'C:\Users\Anwender\Desktop\backup sas data';
data crsp_daily;
set backup.crsp_daily;
run;
proc sort data=crsp_daily;
by permno date;
run;
data crsp_daily1a;
set crsp_daily;
lastofmonth = last.month;
by permno year month;
run;
proc sql;
create table roll_ret as
select h2.permno, h2.Date, h1.retadj as lagret
from crsp_daily1a as h1,
crsp_daily1a as h2
where h1.permno = h2.permno
and intck("MONTH",h1.date,h2.date) between 0 and 11
group by h2.permno, h2.date
having count(h2.permno)>250 and h2.lastofmonth = 1
;
quit;
proc means data = roll_ret noprint;
by permno date;
var lagret;
output out=crsp_daily_final skew=skewRet kurt=KurtRet;
run;
輸入數據集提供每日日期變量,從中我已經構建了一個年份和月份變量。它還具有股票(permno)和日收益率(retadj)的ID。我想從上一年的所有觀察值計算滾動偏度,但前提是該窗口中至少有250個觀測值。我只對這個月最後的結果感興趣。
輸入數據集有60多萬!觀察,上面的代碼太簡單了。我已經嘗試使用視圖而不是roll_view的數據集而沒有改進。
如何快速計算在上述意義上滾動的偏度爲這個非常大的數據集?
在我的代碼一般評論將十分讚賞。
非常感謝!
您是否嘗試過配置代碼? – Kostya 2014-10-30 12:25:43
這將如何工作?這可以提供一個解決方案如何加快速度?主要的挑戰來自proc sql,它創建了一個龐大的數據集,有沒有辦法繞過這一步?在SAS – InfiniteVariance 2014-10-30 12:59:04
簡單的分析可以使用期權fullstimer和檢查日誌來完成(SAS還提供了腳本提取這些信息http://support.sas.com/rnd/scalability/tools/fullstim/)。我明白了,你已經知道瓶頸了:),會在答案中發佈一些關於優化的建議。 – Kostya 2014-10-30 13:52:32