Hi! SAS has a long chapter about compilation and execution but I have problems understanding the distinction between executions and iterations in the DO LOOP. On page 117 the prep guide 9.4 says: Each loop (or cycle of execution) is called an iteration. It provides the following sample on page 212: data work.earnings;
amount=1000;
rate= 0.75/12
do month=1 to 12;
earned+(amount+earned)*rate;
end;
run; After the 12th execution of the DO loop, the value of month is incremented to 13. Because 13 exceeds the stop value of the iterative DO statement, the DO loop stops executiong, and processing continues to the next DATA step statement. [...] Only one observation is written to the data set. -> said observation's value for the iteration variable month is 13. In the quiz section one questions refers to the program above and asks about the number of times the do loop executes. Answer: The number of iterations is determined by the DO statement's stop value, which in this case is 12. I don't understand this solution; in my opinion it contradicts the previous paragraph. According to that I would have guessed the number is 13. Another question about that topic uses this program: data work.invest;
do year= 1990 to 2004;
capital+5000;
output;
end;
run; So, if the stop value determines the number of iterations then the last year should be 2004, I think? But then again the paragraph at the top states that it would increment to 2005, stop and print 2005. That's also the answer in the appendix. What am I missing? I guess I'm confusing something. Could it be that the iterations are only counted as complete cycles and executions by the number of times they start? So in the example of earnings program we have 12 complete iterations but start 13 executions?
... View more