Help using Base SAS procedures

rolling regression in SAS

Reply
New Contributor
Posts: 2

rolling regression in SAS

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{&regSize}_temporary_;

array MSCINordicSV{&regSize}_temporary_;

array SandPSwedenSG{&regSize}_temporary_;

array CreditSuisseHY{&regSize}_temporary_;

array EcapEuroCorp{&regSize}_temporary_;

array Lag1Optimus{&regSize}_temporary_;

array Optimus{&regSize}_temporary_;

set mylib.myseries;

st=1+mod(_n_-1,&regSize);

MSCINordicLV{st}=x1;

MSCINordicSV{st}=x2;

SandPSwedenSG{st}=x3;

CreditSuisseHY{st}=x4;

EcapEuroCorp{st}=x5;

Lag1Optimus{st}=x6;

Optimus{st}=y;

if _n_>=&regSize then do;

date=1+_n_-&regSize;

do i=st+1 to &regSize,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{&regSize}_temporary_;

148  array MSCINordicSV{&regSize}_temporary_;

149  array SandPSwedenSG{&regSize}_temporary_;

150  array CreditSuisseHY{&regSize}_temporary_;

151  array EcapEuroCorp{&regSize}_temporary_;

152  array Lag1Optimus{&regSize}_temporary_;

153  array Optimus{&regSize}_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,&regSize);

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_>=&regSize then do;

164  date=1+_n_-&regSize;

165  do i=st+1 to &regSize,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

Trusted Advisor
Posts: 1,631

Re: rolling regression in SAS

My guess is that the ARRAY statement doesn't do what you want it to do.

Normally, the syntax is

array SandPSwedenSG{&regSize} _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

Super User
Posts: 9,691

Re: rolling regression in SAS

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

Ask a Question
Discussion stats
  • 2 replies
  • 302 views
  • 2 likes
  • 3 in conversation