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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 507 views
  • 0 likes
  • 2 in conversation