studying for cert

Reply
Valued Guide
Posts: 860

studying for cert

Hello,  Can someone help explain the data set generated by the following code?

data WORK.LOOP;

  X = 0;

  do Index = 1 to 5  by  2;

    X = Index;

  put x= index=;

end;

run;

I don't understand why Index is 7.

Thank You,

Super User
Posts: 5,516

Re: studying for cert

Posted in reply to Steelers_In_DC

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.

Ask a Question
Discussion stats
  • 1 reply
  • 157 views
  • 0 likes
  • 2 in conversation