Hi all, I'm currently learning Basic SAS and am trying to learn the mechanics of DO Loops. I have a simple code here but would like to understand how SAS would execute it. Here is the code:
data balance;
bal=1000;
do i=1 to 12;
bal=bal*1.01;
output;
end;
run;
Although I do know what the result would be, I still have a few questions that I would like to ask that would better help me understand how SAS executes this loop.
1. assume SAS is reading this for the first time and is on its first loop (i=1). Since we're given that bal=1000 outside the DO Loop, how come IN the Do Loop, SAS will calculate it as bal = 1000*1.01 and not 1000 = 1000*10.1? Shouldn't the variable be different say total=bal*1.01?
2. so after SAS goes through the loop once, the balance after 1000 is multiplied by 1.01 and gives 1010, so how does SAS memorize the 1010 for the 2nd loop execution and multiply that by 1.01? Does SAS change the bal=1000 outside the DO Loop to bal=1010? If not, then how is SAS able to memorize the result from the previous loop and carry it into the next loop for calculation?
Hope my questions are not confusing...thanks!
... View more