BookmarkSubscribeRSS Feed
u39734216
Fluorite | Level 6

Hi All

 

    I'm facing problem to understand loops. what is the use of loops or why do we use By increment in  Do loop? 

 

(i)  I have a dataset which has a value of 7000 and I have to determine the value after 15 years by the constant annual interest rate of 12% and

(ii) compound annual interest rate 12%.

I was trying with this code but I think it's incorrect.


data deposit;
amount = 7000;
rate = 0.12;
do year = 1 to 15;
amount + earned;
earned + (amount*0.12);
principal = amount + earned;
output;
end;
run;

1 REPLY 1
Kurt_Bremser
Super User

Your use of a do loop is correct, but the sequence of calculations is not. Try this:

data deposit;
amount = 7000;
rate = 0.12;
do year = 1 to 15;
  earned = amount * 0.12;
  amount = amount + earned;
  output;
end;
run;

BY in a do statement is used to specify an increment other than 1. You can (among others) use to count down:

data _null_;
do i = 15 to 1 by -1;
  put i=;
end;
run;