DATA Step, Macro, Functions and more

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

Accepted Solution Solved
Reply
Super User
Posts: 2,061
Accepted Solution

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

[ Edited ]

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;

 


Accepted Solutions
Solution
‎12-10-2017 03:35 PM
Super User
Super User
Posts: 8,279

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

[ Edited ]
Posted in reply to novinosrin

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


All Replies
SAS Super FREQ
Posts: 508

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

Posted in reply to novinosrin

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. */

Solution
‎12-10-2017 03:35 PM
Super User
Super User
Posts: 8,279

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

[ Edited ]
Posted in reply to novinosrin

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.

Super User
Posts: 2,061

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

Thank you Tom, Nice one indeed!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 183 views
  • 1 like
  • 3 in conversation