我每天都需要滚动回归输出。数据集是股票返回和音量,模型仅返回=音量。我需要过去30天的回归系数,每天再进一步,以使30天的窗口保持完整。
基于我了解的问题,您想回顾一个巨大的数据集,每个月都要运行模型。这是我最近做过的类似的事情。
/*Select the parts of the data from base data based on input.*/
%macro model_by_dates(id, date1, date2);
data to_model;
set begin(where=( &date1. < date_var < &date2.));
run;
/*YOUR model code here*/
data result_file;
set From_model;
id=&id; /*To recognize from which model this is from.*/
run;
/*If you have huge files, do permanent data after every 10 loops or so. Depends.*/
proc append base=all_Results data=result_file force; run;
%mend model_by_dates;
/*here we create the dates list. You can do this in multiple ways. Datdiff maybe?*/
%let maxmonths=3;
data dates;
do i=0 to &maxmonths. by 1;
begin=date()-(i*30);
end = date()-( (i+1)*30);
output;
end;
run;
/*This is the master switch. It executes the macro for each row of the dates.*/
data _NULL_;
set dates;
call execute('%nrstr(%model_by_dates('
||strip(id)||','
||strip(begin)||','
||strip(end)||
'))');
run;
编辑基于进一步的澄清,我正在更改日期列表的创建:
data dates;
do i=0 to 30 by 1;
begin=date()-(i+30);
end = date()- i ;
output;
end;
run;