Hi, I am doing a momentum strategy research, and I am running into these errors when running a procedure (SAS Studio):
In the future please post the code and error message from the log and paste into a code box (either the {i} or run icon) to preserve formatting. The ERROR 22-322 is usually accompanied by an underscore under the postion in code that triggered the error message. Posting into a code box will maintain the orginal formatting and allow us to see where the underscore is in the code.
Also the values of macro variable resolution help, so run the code with Options Mprint; so the log will show the code generated by the macro variable(s).
I will say it looks a tad odd to me comparing the same value, &J, to both a number of months and another count (which might need CALCULATED to resolve in the HAVE clause) .
You want rolling J-month cumulative returns for each permno.
It looks to me like you are usuing the CRSP monthly returns data, not the daily returns.
Given that CRSP data is almost always sorted by permno/date, you can use a DATA step to process the data much faster. This program untested program makes the following assumptions.
data umd (drop=month0_date m);
set commonstocks;
by permno;
/* define array to hold cumulative log(1+ret) starting month 0 up to 20 years*/
array sumlog_retplus1 {0:240} _temporary_ ();
if first.permno then do;
month0_date=date;
do m=0 to 240; sumlog_retplus1{m}=0; end;
end;
retain month0_date;
m=intck('month',month0_date,date);
if m=0 then sumlog_retplus1{m}=log(1+ret);
else sumlog_retplus1{m}=log(1+ret)+sumlog_retplus1{m-1};
if m<&J then delete;
else if m=&J then cmret=exp(sumlog_retplus1{m})-1;
else cmret=exp(sumlog_retplus1{m}-sumlog_retplus1{m-&J})-1;
run;
The second version accomodates holes in the monthly series:
data umd (drop=month0_date m m2 lastm);
set commonstocks;
by permno;
/* define array to hold cumulative log(1+ret) starting month 0 up to 20 years*/
array sumlog_retplus1 {0:240} _temporary_ ();
if first.permno then do;
month0_date=date;
do m=0 to 240; sumlog_retplus1{m}=0; end;
end;
retain month0_date;
m=intck('month',month0_date,date);
lastm=lag(m);
if m=0 then sumlog_retplus1{m}=log(1+ret);
else if m=lastm+1 then sumlog_retplus1{m}=log(1+ret)+sumlog_retplus1{m-1};
else do m2=lastm+1 to m-1;
else sumlog_retplus1{m2}=sumlog_retplus1{m2-1};
end;
if m<&J then delete;
else if m=&J then cmret=exp(sumlog_retplus1{m})-1;
else cmret=exp(sumlog_retplus1{m}-sumlog_retplus1{m-&J})-1;
run;
In the future please post the code and error message from the log and paste into a code box (either the {i} or run icon) to preserve formatting. The ERROR 22-322 is usually accompanied by an underscore under the postion in code that triggered the error message. Posting into a code box will maintain the orginal formatting and allow us to see where the underscore is in the code.
Also the values of macro variable resolution help, so run the code with Options Mprint; so the log will show the code generated by the macro variable(s).
I will say it looks a tad odd to me comparing the same value, &J, to both a number of months and another count (which might need CALCULATED to resolve in the HAVE clause) .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.