DATA Step, Macro, Functions and more

do loop

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

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,044

Re: do loop

Posted in reply to Ravikumarpa4
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;

View solution in original post


All Replies
Super User
Super User
Posts: 7,988

Re: do loop

Posted in reply to Ravikumarpa4

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.

PROC Star
Posts: 7,492

Re: do loop

Posted in reply to Ravikumarpa4

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,044

Re: do loop

Posted in reply to Ravikumarpa4
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,044

Re: do loop

Posted in reply to Ravikumarpa4

It is equivalent with:

 

1

1+1.045

1+1.045+1.045**2

Contributor
Posts: 54

Re: do loop

Posted in reply to Ravikumarpa4
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

Re: do loop

Posted in reply to Ravikumarpa4
Yes, but
If your interest rate (0.045) for one month and want to calculate simple annual interest multiply by 12
Cum=cum+(1.045)*12
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 261 views
  • 4 likes
  • 5 in conversation