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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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