Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Forecasting
- /
- proc expand movprod

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 08-30-2018 06:23 AM
(3688 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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:

I hope this helps!

DW

7 REPLIES 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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:

I hope this helps!

DW

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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 ? **

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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!

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.