Hi SAS experts,
How to interpret the below code of bold line ?
proc expand data=crsp_m (keep=permno date ret) out=umd method=none;
by permno;
id date;
convert ret = cum_return / transformin=(+1) transformout=(MOVPROD &J -1 trimleft &J);
quit;
proc printto;
run;
Thanks
Hi,
For your CONVERT statement shown below, where your macro variable &J resolves to the value of 6:
convert ret = cum_return / transformin=(+1) transformout=(MOVPROD &J -1 trimleft &J);
PROC EXPAND performs the following operations (in the order specified in the CONVERT statement):
For more details, please see the Transformation Operations section of the PROC EXPAND documentation at the following link:
I hope this helps!
DW
Do you know what the value of the macro variable J is when that code is executed?
Since a single macro variable potentially contains a lot of code with out an explicit value it can be pretty hard to say what any given statement will actually do.
for instance if &j is a blank I suspect that code would throw an error.
If &j contains a single word that is not a variable name it may throw an error.
If longer than who knows.
Hi @ballardw The macro variable J is a fixed number 6. How to interpret the code ? Thanks
Hi,
For your CONVERT statement shown below, where your macro variable &J resolves to the value of 6:
convert ret = cum_return / transformin=(+1) transformout=(MOVPROD &J -1 trimleft &J);
PROC EXPAND performs the following operations (in the order specified in the CONVERT statement):
For more details, please see the Transformation Operations section of the PROC EXPAND documentation at the following link:
I hope this helps!
DW
Hi @dw_sas,
Thank you for the detailed reply. So MOVPROD &J includes the current month for calculating product. It is RET1_t * RET1_t-1 *...* RET1_t-5, rather than RET1_t -1* RET1_t-2 *...* RET1_t-6 ?
Hi @Nieves,
I'm glad the information was helpful! Regarding your follow-up question, the MOVPROD does include the current observation in the backward moving product calculation. The computational formula for the MOVPROD transformation operator can be found in Table 15.2 in the Transformation Operations section of the PROC EXPAND documentation (see the link in my earlier reply). Additional information can be found in the Moving Time Window Operators section of the documentation shown below:
I hope this helps!
DW
Hi,
What would be the best way to compute the cumulative returns from t-6 to t-1(i.e. skipping the current month). That is: RET1_t -1* RET1_t-2 *...* RET1_t-6.
One way I can think of is to compute the cumulative return from t-6 to t using this code
convert ret = cum_return / transformin=(+1) transformout=(MOVPROD 6 -1 trimleft 6);
And then divide the result by the current month return.
cum_ret_wanted = (1+cum_return)/(1+ret)-1;
But this involves an extra DATA step. Can we achieve this within the PROC EXPAND step?
You will get the most attention, @somebody, by posting a new question since this one has already been solved. Best of luck!
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 to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.