BookmarkSubscribeRSS Feed
whymath
Lapis Lazuli | Level 10

Thanks @Patrick  for inspiring me.

When using DOW-Loop, I used to not writing a "stop" statement, but today I see difference from this post:Why read data 1 times or 2 times when declare hash object with or with... - SAS Support Communities

 

DOW-Loop with "put _n_=" above:

data _null_;
  put _n_=;
  do until(_eof_);
    set sashelp.class end=_eof_;
  end;
run;

SAS Log:

_N_=1
_N_=2

 

DOW-Loop with "put _n_=" above and "stop" behind:

data _null_;
  put _n_=;
  do until(_eof_);
    set sashelp.class end=_eof_;
  end;
  stop;
run;

SAS Log:

_N_=1

 

DOW-Loop with "put _n_=" behind:

data _null_;
  do until(_eof_);
    set sashelp.class end=_eof_;
  end;
  put _n_=;
run;

SAS Log:

_N_=1

I have read The SAS Supervisor - SAS Support Communities and still not figure it out.

4 REPLIES 4
Kurt_Bremser
Super User

DO UNTIL forces at least one iteration.

So your step does this:

In the first iteration of the DATA step (_N_ = 1), it works through the dataset until the last observation is read and _eof_ is set.

Then it goes to the next DATA step iteration (_N_ = 2), performs the first iteration of the DO where the SET statement tries to read past the last observation, so the DATA step is terminated immediately.

yabwon
Amethyst | Level 16

I highly recommend reading:

https://analytics.ncsu.edu/sesug/2002/TU05.pdf

and

https://support.sas.com/resources/papers/proceedings09/038-2009.pdf

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Kurt_Bremser
Super User

For further clarification: the END= variable is set when the last observation is read, but the termination of the DATA step happens when a read past the last observation is attempted.

Tom
Super User Tom
Super User

Data steps that have input stop when a statement tries to read past its input. 

 

In these examples that is the SET statement. 

 

But the same thing applies to data steps that use an INPUT statements to read in data.

 

 

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
  • 4 replies
  • 73 views
  • 2 likes
  • 4 in conversation