02-15-2013 04:01 PM
Hello, Can someone help explain the data set generated by the following code?
X = 0;
do Index = 1 to 5 by 2;
X = Index;
put x= index=;
I don't understand why Index is 7.
02-15-2013 04:30 PM
The real question here is how does INDEX go from 1 to 5.
It starts at 1, and each time the loop hits the END statement SAS adds 2 to INDEX. Then it asks, "Am I done yet?"
So the third time through the loop, INDEX is 5. At the END statement SAS adds 2, giving a value of 7. Then SAS figures out the loop must be over because 7 is greater than the ending value for the loop (5).
Good luck on the cert test.