BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
CurtisMack
Fluorite | Level 6
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.
deleted_user
Not applicable
Yes ok thank you 😉

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1248 views
  • 0 likes
  • 2 in conversation