|
Jesper Sahner wrote:
> Hi!
>
> Just a little teaser :-)
>
> Try the following:
>
> data test;
> do until (last);
> set sashelp.prdsale end=last;
> end;
> output;
> run;
>
> No problem. Now try this:
>
> data test2;
> retain first 1;
> if first then do;
> first=0;
> do until (last);
> set sashelp.prdsale end=last;
> end;
> end;
> output;
> run;
>
> This doesn't work. What is the EXACT explanation?
Not exact, but briefly...
In test, in the second implicit data step loop (IDSL) iteration (_n_=2), the
SET statement is reached and the data set has no more rows to read, causing
the the DATA Step to end immediately (with only one record output at the end
of IDSL _n_=1).
In test2, the 'if first' prevents the SET from occuring in the _N_=2 loop,
so the SET is never reached when it is exhausted, which means the step
cannot end at the _n_=2 SET. Instead, control flows past the "if then do"
block, to the OUTPUT, which creates the 2nd obs of test2. Control returns
back to the top IDSL. The data step automatically detects a 'looping'
condition, that is an infinite IDSL, which occurs when none of the PDV
variables change state (i.e. get a new value by some effect of the prior
_n_). When 'no changes' happening condition occurs, the data step ends
with a "NOTE: DATA STEP stopped due to looping." This is what happens in
test2
--
Richard A. DeVenezia
http://www.devenezia.com
|