BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nieves
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
dw_sas
SAS Employee

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):

 

  • add a value of 1 to RET  (Let's call this temporarily transformed variable RET1 for simplicity of illustration.)
  • perform a backward moving multiplication of RET1 for times, t, t-1, t-2, t-3, t-4, t-5 (ie. RET1_t * RET1_t-1 *...* RET1_t-5)
  • subtract 1 from the result of the backward moving product at time t to obtain CUM_RETURN
  • set the first 6 values of the final result contained in CUM_RETURN to missing

For more details, please see the Transformation Operations section of the PROC EXPAND documentation at the following link:

 

https://go.documentation.sas.com/?docsetId=etsug&docsetVersion=14.3&docsetTarget=etsug_expand_detail...

 

I hope this helps!

DW

View solution in original post

7 REPLIES 7
ballardw
Super User

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.

Nieves
Quartz | Level 8

Hi @ballardw The macro variable J is a fixed number 6. How to interpret the code ? Thanks

dw_sas
SAS Employee

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):

 

  • add a value of 1 to RET  (Let's call this temporarily transformed variable RET1 for simplicity of illustration.)
  • perform a backward moving multiplication of RET1 for times, t, t-1, t-2, t-3, t-4, t-5 (ie. RET1_t * RET1_t-1 *...* RET1_t-5)
  • subtract 1 from the result of the backward moving product at time t to obtain CUM_RETURN
  • set the first 6 values of the final result contained in CUM_RETURN to missing

For more details, please see the Transformation Operations section of the PROC EXPAND documentation at the following link:

 

https://go.documentation.sas.com/?docsetId=etsug&docsetVersion=14.3&docsetTarget=etsug_expand_detail...

 

I hope this helps!

DW

Nieves
Quartz | Level 8

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 ? 

dw_sas
SAS Employee

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:

 

https://go.documentation.sas.com/?docsetId=etsug&docsetTarget=etsug_expand_details19.htm&docsetVersi...

 

I hope this helps!

DW

somebody
Lapis Lazuli | Level 10

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?

ShelleySessoms
Community Manager

You will get the most attention, @somebody, by posting a new question since this one has already been solved. Best of luck!

 

 

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Multiple Linear Regression in SAS

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.

Discussion stats
  • 7 replies
  • 3366 views
  • 3 likes
  • 5 in conversation