DATA Step, Macro, Functions and more

Loops: why do I get i+1 iterations instead of i ?

Reply
N/A
Posts: 0

Loops: why do I get i+1 iterations instead of i ?

Hi,
I submitted this code:

data MyTable;
do i=1 to 5;
end;
run;


and I got

Obs i
1 6
.

I'm confused : Why do I get 6 and not 5 ??

Thank you in advance
Frequent Contributor
Posts: 102

Re: Loops: why do I get i+1 iterations instead of i ?

Posted in reply to deleted_user
Because the loop incremented the value of i until it was greater than 5 (6) and then the implied OUTPUT statement that occurs before the RUN statement executed.
I think you want this:
-----------------------------
data MyTable;
do i=1 to 5;
OUTPUT;
end;
run;
----------------------------
When you explicitly specify an OUTPUT statement, it overrides the implied OUTPUT statement that occurs before the RUN statement, so on the value of i that occured inside the loop are output;
Hope that was clear.
N/A
Posts: 0

Re: Loops: why do I get i+1 iterations instead of i ?

Posted in reply to CurtisMack
Yes ok thank you Smiley Wink
Ask a Question
Discussion stats
  • 2 replies
  • 120 views
  • 0 likes
  • 2 in conversation