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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1283 views
  • 0 likes
  • 2 in conversation