12-13-2017 06:22 AM
When I executed codes below, I got 11 in variable i. Why it is not 10? Could you kindly explain a little more regarding to how SAS works in this case? Thanks!
data a; do i = 1 to 10; end; output; run; proc print data=a; run;
12-13-2017 06:34 AM
The do loop value is incremented by the step value (default is 1) at the encounter of an end statement. Therefore the end result of your code is one more than the do loop, and that is output. The code within the do loop is only executed until incrementor is above the high limit.
You can read the documentation on do loops:
12-13-2017 06:38 AM
i is set to 1, and 1 is less than or equal to 10 so the loop continues
i is set to 10, and 10 is less than or equal to 10 so the loop continues
i is set to 11, and 11 is not less than or equal to 10 so the code in the loop is not executed and SAS goes on to the next statement.
i is 11 at output time.
12-13-2017 07:38 AM
While the first couple of responses outline the rules, here are a couple of DATA steps you can play with to try to get the idea:
do k=1 to 7 by 4;
do k=1 to 9 by 4;
k = k + 1;