Solved
Contributor
Posts: 39

# do loop

need solution for below question by using do loop

each year an employee invests 5000 in an account determine the value of account after 3 year based on constant intrest rate of 4.5

Accepted Solutions
Solution
‎02-23-2017 12:54 AM
Super User
Posts: 10,848

## Re: do loop

``````data _null_;
cum=0;
do n=0 to 2;
cum=cum+1.045**n;

total=5000*cum;
year=n+1;
put year= total= ;
end;
run;``````

All Replies
Super User
Posts: 9,813

## Re: do loop

Solution is to use SAS code.  Realy what do you expect?  You have provided nothing, where is the test data (in the form of a datastep), where is the example output.  What code have you tried etc.

Super User
Posts: 8,214

## Re: do loop

There's a function for that: MORT (see: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245917.htm)

However, to use it, you'll have to specify whether the interest is compounded  daily, monthly or whatever.

Art, CEO, AnalystFinder.com

Solution
‎02-23-2017 12:54 AM
Super User
Posts: 10,848

## Re: do loop

``````data _null_;
cum=0;
do n=0 to 2;
cum=cum+1.045**n;

total=5000*cum;
year=n+1;
put year= total= ;
end;
run;``````
Contributor
Posts: 39

## Re: do loop

Hi

thanks for your code. i got the what i'm expecting but need one clarification on how you deceided  'cum=cum+1.045**n;'

Super User
Posts: 10,848

## Re: do loop

It is equivalent with:

1

1+1.045

1+1.045+1.045**2

Contributor
Posts: 54

## Re: do loop

Hi, your question is about to "compound interest calculation" which is calculated as c=c+(1+r)^n classical formula.
C is capital, r is interest rate, n is period.
Thanks for Ksharp's solution.
Contributor
Posts: 39

## Re: do loop

ok thanks but if want calcualte on simple interest then it will be 'cum=cum+1.045;' right?

Contributor
Posts: 54