How are your data organized? Your best option would be to create a driver dataset that contains all your necessary information - essentially the same as the table in your first post. If you don't have this, you can derive it from your analytic dataset - I assume all your fund information is in one dataset? Also, are you running 3 different rolling regs per fund as indicated in your initial table? It is unclear what the requirements are. If you are running rolling regs, there shouldn't be any need to have multiple iterations per fund since you would be duplicating effort. To that end, I would suggest obtaining the min and max dates for each fund, then use that as inputs to your macro and run each fund only once for the entire time frame you have data. Once you have that, you will need to loop through your data, likely having two loops. The first loop is for each fund (e.g. i=1 to 2048). Then, the second loop is for the rolling regs themselves (e.g. j=36 to &end) where &end is the number of data points derived from your table created above. In your input dataset, you can create some counter variable to drive the rolling regs rather than dates where the first data point for each fund is 1. If your data are structured in a long format with all funds stacked on top of each other, it could be as simple as: data test2;
set test;
retain id;
if first.permno then id=1;
else id+1;
run; Then your proc reg might look like: proc reg data=test noprint outest=out_estimates;
model ER = RMRF HML SMB;
where permno = &i and (&j-35 <= ID <= &j);
run;
... View more