BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Toni2
Lapis Lazuli | Level 10

hi,

 

I am new is SAS

 

I am trying to replicate a product calculation in SAS but i am not sure how i can do it - see the attached pdf

 

In short, I need to replicate column C using the formula (formula in the pdf) which calculates the 12 month growth rate

 

Then i need to populate all column C. For example, cell C16 needs to be =(PRODUCT(B5:B16)-1)*100, C17 to be =(PRODUCT(B6:B17)-1)*100 and so on

 

Any help will be appreciated 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

A simple modification to the code:

 

growth=(RD12mG*lag11(RD12mG)*lag10(RD12mG)*lag9(RD12mG)*
/* I'm lazy, you type the rest */
-1)*100;

 

You can also use PROC EXPAND, which would be less typing and more flexible.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Some of us will not (or cannot) download attachments. You can show us (a portion of) your data and formula by including it in your reply. Data should be provided following these instructions. Formula can be included in your reply as a screen capture.

--
Paige Miller
Toni2
Lapis Lazuli | Level 10

Hi,

 

Thanks for the advises

 

Below you can see part of my dataset

 

I want to create a new variable to calculate the 12 month growth in % for the RD12MG based on date

 

Starting in 31JUL1983 in Excel the formula that I want to use is =((PRODUCT(G12:G23)-1)*100) where G12 = 1.011 and G23 = 1.008

 

Then, for example, for next dates the formula has to be : 

31AUG1983 the calculation has to be =((PRODUCT(G13:G24)-1)*100)  where G13 = 1.008 and G24 = 1.003

30SEP1983 the calculation has to be =((PRODUCT(G14:G25)-1)*100)  where G14 = 1.013 and G25 = 1.006

 

 

Obs Date RD12mG
231JUL1982.
331AUG19821.011
430SEP19821.008
531OCT19821.013
630NOV19821.012
731DEC19821.016
831JAN19831.005
928FEB19831.012
1031MAR19831.007
1130APR19831.009
1231MAY19831.018
1330JUN19831.013
1431JUL19831.008
1531AUG19831.003
1630SEP19831.006
1731OCT19831.014
1830NOV19831.011
1931DEC19831.016
2031JAN19841.004
2129FEB19841.009
2231MAR19841.012
2330APR19841.013
2431MAY19841.010
2530JUN19841.010

 

PaigeMiller
Diamond | Level 26

Since these are months, there are no missing months, you can use the LAG11 function.

 

data want;
    set have;
    growth=(RD12mG*lag11(RD12mG)-1)*100;
run;
--
Paige Miller
Toni2
Lapis Lazuli | Level 10

thanks. I think that your formula multiples only the first and last value but we need all the values in the interval 

 

I mean for example, for 31JUL1983 the formula has to calculate growth as below :

 

growth = (1.011 * 1.008 * 1.013 * 1.012 * 1.016 * 1.005 * 1.012 * 1.007 * 1.009 * 1.011 * 1.013 * 1.008) - 1)*100) = 13.3

 

Any idea?

PaigeMiller
Diamond | Level 26

A simple modification to the code:

 

growth=(RD12mG*lag11(RD12mG)*lag10(RD12mG)*lag9(RD12mG)*
/* I'm lazy, you type the rest */
-1)*100;

 

You can also use PROC EXPAND, which would be less typing and more flexible.

--
Paige Miller
Toni2
Lapis Lazuli | Level 10

yes, you are right, sorry!

 

thanks for the support 🙂

SAS Innovate 2025: Call for 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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1821 views
  • 0 likes
  • 2 in conversation