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 😉

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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