@CC_J :
The number of executions is the number of times the body of the loop (i.e. the program statements between DO and END) is executed. The number of iterations is the number of times program control passes through the body of the loop. Thus, both are exactly equal.
Whether the value of the iteration variable, i.e. the loop index, exceeds the TO value after the loop is exited depends on how the loop is organized internally. The way the iterative DO loop is organized in SAS, the index variable is incremented at the bottom of the loop and then the internal logic checks whether it now exceeds the TO value. If yes, program control exits the loop; otherwise, it is passed to the top of the loop again. Run the following step and look at the log; hopefully, it will give you a clearer idea of what is going on:
data _null_ ;
FROM = 1 ;
TO = 3 ;
/* Internal logic */
x = FROM ;
do until (0) ; /* until(0) or while(1) means "iterate forever" */
put "Execute # " x ;
x = x + 1 ;
if x > TO then goto exit ;
end ;
exit:
put x= / ;
/* Equivalent to: */
x = FROM ;
do until (0) ; /* until(0) or while(1) means "iterate forever" */
put "Execute # " x ;
x = x + 1 ;
if x > TO then leave ;
end ;
put x= / ;
/* Equivalent to: */
x = FROM ;
do until (x > TO) ; /* Due to UNTIL, x > TO condition is checked at the bottom of the loop */
put "Execute # " x ;
x = x + 1 ;
end ;
put x= / ;
/* Equivalent to: */
do x = FROM to TO ;
put "Execute # " x ;
end ;
put x= ;
run ;
If you're rather keenly interested in the anatomy of the DO loop and many of its curious variations, I'd suggest that you read this:
http://support.sas.com/resources/papers/proceedings13/126-2013.pdf
Kind regards
Paul D.
... View more