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
Rhodochrosite | Level 12

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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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