BookmarkSubscribeRSS Feed
556
Calcite | Level 5 556
Calcite | Level 5
CompanyA1.3%3.9%1.7%0.5%0.1%3%4%5%1%0.7%6%4.7%
MonthsJanFebMarAprMayJuneJulyAugSepOctNovDec

if invest 3000 per month, first monthly return =3000*1.013, second monthly return =(3000+3000*1.013)*3.9% etc...

Total investment period: 10 years , how to write the codes?

5 REPLIES 5
Reeza
Super User

How does your input data look like? Is it in rows like that? Do you have multiple companies/months?

556
Calcite | Level 5 556
Calcite | Level 5
CompanyA1.3%3.9%1.7%0.5%0.1%3%4%5%1%0.7%6%4.7%
MonthsJanFebMarAprMayJuneJulyAugSepOctNovDec

Exactly look like the table above

Question: Every month, $3000 is invested and the rate of return is based on the past twelve month's pattern.

               It requires us to calculate the total return by monthly investment after 10 years.


For example, the monthly return for the first $3000 invested = $3000*(1+1.3%),

                    the accumulated monthly return for the next $3000 invested = ($3000*(1+1.3%)+$3000)*3,9%


Total return by monthly investment after 10 years should be $2,611,500.69

Reeza
Super User

What do the months represent? Do you have 120 interest rates, 1 per month?

556
Calcite | Level 5 556
Calcite | Level 5

12 interest rates only, keep repeating from Jan to Dec

                                                                                             accumulated monthly return

Jan2000 1.3%              $3000*(1+1.13)  =                                        $3039

Feb2000 3,9%              ($3039+$3000)*(1+3.9%)  =                         $6274.521  

Mar2000 1.7%              ($6274.521+$3000)*(1+1.7%)   =                  $9432.19

Apr2000 0.5%              ($9432.19+$3000)*(1+0.5%)     =                  $12494.35

     .                                           .                                                         .

     .                                           .                                                         .

     .                                           .                                                         .

Dec2000 4.7%             ($38989.36+$3000)*(1+4.7%)   =                  $43962.86

Jan2001 1.3%              ($43962.86+$3000)*(1+1.3%)   =                  $47573.38

Feb2001 3.9%              ($47573.38+$3000)*(1+3.9%)   =                  $52545.74

     .

     .

     .

Dec2010 4.7%              ($2491270+$3000)*(1+4.7%)   =                   $2611500.69

Reeza
Super User

Your data can't be in that format, you have character and numeric values in the same variable.

Assuming your interest rates have the variable names ir1-ir12, where ir1=January's interest rate and Ir12 = Decembers interest rate something like the following will work. I think you have some calculation mistakes in your example though, an interest rate of 1.3% is 1.013 not 1.13.

data have;

informat ir1-ir12 percent.;

format ir1-ir12 percent8.1;

input company $ ir1-ir12 ;

cards;

CompanyA 1.3% 3.9% 1.7% 0.5% 0.1% 3% 4% 5% 1% 0.7% 6% 4.7%

;

run;

data want;

set have;

array ir(12) ir1-ir12;

monthly=3000;

value=0;

do i=1 to 10; *for 10 years;

     do j=1 to 12; *for 12 months/year;

     value=(value+monthly)*(1+ir(j));

     end;

   output;

end;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1003 views
  • 0 likes
  • 2 in conversation