I am trying to figure out a code for a rolling regression on financial time series, the return series of a hedge fund on a set of 6 equity factors.I have tried many methods already,but without any positive outcome. Can someone help ? I attach the code I've written in SAS 9.3 and the log script with errors:
%let regSize=262;
DATA mylib.rollwind(KEEP=DATE Optimus MSCINordicLV MSCINordicSV SandPSwedenSG CreditSuisseHY EcapEuroCorp Lag1Optimus)/view=mylib.rollwind;
array MSCINordicLV{®Size}_temporary_;
array MSCINordicSV{®Size}_temporary_;
array SandPSwedenSG{®Size}_temporary_;
array CreditSuisseHY{®Size}_temporary_;
array EcapEuroCorp{®Size}_temporary_;
array Lag1Optimus{®Size}_temporary_;
array Optimus{®Size}_temporary_;
set mylib.myseries;
st=1+mod(_n_-1,®Size);
MSCINordicLV{st}=x1;
MSCINordicSV{st}=x2;
SandPSwedenSG{st}=x3;
CreditSuisseHY{st}=x4;
EcapEuroCorp{st}=x5;
Lag1Optimus{st}=x6;
Optimus{st}=y;
if _n_>=®Size then do;
date=1+_n_-®Size;
do i=st+1 to ®Size,1 to st;
x1=MSCINordicLV{i};
x2=MSCINordicSV{i};
x3=SandPSwedenSG{i};
x4=CreditSuisseHY{i};
x5=EcapEuroCorp{i};
x6=Lag1Optimus{i};
y=Optimus{i};
output;
end;
end;
run;
proc reg data=mylib.rollwind outest=mylib.rollwind1;
by date;
model= Optimus= MSCINordicLV MSCINordicSV SandPSwedenSG CreditSuisseHY EcapEuroCorp Lag1Optimus /noint;
run;
The log in SAS is:
145 %let regSize=262;
146 DATA mylib.rollwind(KEEP=DATE Optimus MSCINordicLV MSCINordicSV SandPSwedenSG CreditSuisseHY
146! EcapEuroCorp Lag1Optimus)/view=mylib.rollwind;
147 array MSCINordicLV{®Size}_temporary_;
148 array MSCINordicSV{®Size}_temporary_;
149 array SandPSwedenSG{®Size}_temporary_;
150 array CreditSuisseHY{®Size}_temporary_;
151 array EcapEuroCorp{®Size}_temporary_;
152 array Lag1Optimus{®Size}_temporary_;
153 array Optimus{®Size}_temporary_;
154 set mylib.myseries;
ERROR: The variable type of Optimus is invalid in this context.
ERROR: The variable type of MSCINordicLV is invalid in this context.
ERROR: The variable type of MSCINordicSV is invalid in this context.
ERROR: The variable type of SandPSwedenSG is invalid in this context.
ERROR: The variable type of CreditSuisseHY is invalid in this context.
ERROR: The variable type of EcapEuroCorp is invalid in this context.
ERROR: The variable type of Lag1Optimus is invalid in this context.
155 st=1+mod(_n_-1,®Size);
156 MSCINordicLV{st}=x1;
157 MSCINordicSV{st}=x2;
158 SandPSwedenSG{st}=x3;
159 CreditSuisseHY{st}=x4;
160 EcapEuroCorp{st}=x5;
161 Lag1Optimus{st}=x6;
162 Optimus{st}=y;
163 if _n_>=®Size then do;
164 date=1+_n_-®Size;
165 do i=st+1 to ®Size,1 to st;
166 x1=MSCINordicLV{i};
167 x2=MSCINordicSV{i};
168 x3=SandPSwedenSG{i};
169 x4=CreditSuisseHY{i};
170 x5=EcapEuroCorp{i};
171 x6=Lag1Optimus{i};
172 y=Optimus{i};
173 output;
174 end;
175 end;
176 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
177 proc reg data=mylib.rollwind outest=mylib.rollwind1;
ERROR: File MYLIB.ROLLWIND.DATA does not exist.
178 by date;
179 model= Optimus= MSCINordicLV MSCINordicSV SandPSwedenSG CreditSuisseHY EcapEuroCorp Lag1Optimus
-
22
200
179! /noint;
ERROR: No data set open to look up variables.
ERROR: No data set open to look up variables.
ERROR: No data set open to look up variables.
ERROR: No data set open to look up variables.
ERROR: No data set open to look up variables.
ERROR: No data set open to look up variables.
ERROR: No data set open to look up variables.
NOTE: The previous statement has been deleted.
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, /, :, _ALL_, _CHARACTER_,
_CHAR_, _NUMERIC_, {.
ERROR 200-322: The symbol is not recognized and will be ignored.
180 run;
NOTE: PROCEDURE REG used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: The data set MYLIB.ROLLWIND1 has 0 observations and 0 variables
If my approach is wrong , what could be a solution?
Thanks a lot in advance
My guess is that the ARRAY statement doesn't do what you want it to do.
Normally, the syntax is
array SandPSwedenSG{®Size} _temporary_ SandPSwedenSG1-SandPSwedenSG262;
Which of course is not what you have typed in.
Furthermore, if I understand Rolling Regression properly, you want the previous 262 observations of SandPSwedenSG, and the array statement does not provide this at all, it provides 262 variables of a single observation (if you had the proper syntax). Key difference.
To obtain the previous 262 observations of SandPSwedenSG, you would need to use the LAG function 261 times, or use a Time Series approach, for example PROC AUTOREG from SAS/ETS
From your error log information, it seems that your array name conflict with all variable name . you should make them all unique like add underscore before them.
_optimus{}
and model statement should not contain = after it.
should be
model Optimus=
Message was edited by: xia keshan
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.