BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
novinosrin
Tourmaline | Level 20

How " 'just' 'leave' " not leave a DOW loop but "outputs"?

 

data have;

     do i=1 to 5;

           do _n_=1 to 8;

           output;

           end;

     end;

run;

 

 

data dow;

do until(last.i);

     set have;

     by i;

     leave; /* behaves as explicit output, why?*/

end;

run;

 

data dow;

do until(last.i);

     set have;

     by i;

     *leave; /* when commented, zips through in one shot to the last.i as known*/

end;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you leave the DO loop every time then the DO loop is doing nothing. So it works the same as if you coded.

data dow;
     set have;
     by i;
run;

So if you know why the simple data step above results in DOW having the same number of observations as HAVE then you can answer your own question.

View solution in original post

3 REPLIES 3
WarrenKuhfeld
Ammonite | Level 13

I read this several times and I am still not sure what you are asking.

Observations:

I would never (or almost never) put a SET statement within a loop without POINT=.

DATA steps have an implicit OUTPUT unless there is an explicit OUTPUT somewhere.

 

If you just want to process the last observation in each BY group skip the loop and use.

if last.i then output; /* or do or whatever you want to have happen. */

Tom
Super User Tom
Super User

If you leave the DO loop every time then the DO loop is doing nothing. So it works the same as if you coded.

data dow;
     set have;
     by i;
run;

So if you know why the simple data step above results in DOW having the same number of observations as HAVE then you can answer your own question.

novinosrin
Tourmaline | Level 20

Thank you Tom, Nice one indeed!

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
  • 3 replies
  • 1173 views
  • 1 like
  • 3 in conversation