01-29-2015 05:45 AM
How many times does the data step iterate when using set statement or input statement inside a do loop. For example
do i=1 to 10;
I understand when index variable i=1 when sas reads of the first obs in have, output statment writes to output dataset, then after end statement, it goes back to the top of the loop and I believe reads the 2nd observation and so on. Now, my question is once that comes outside the loop, as it hits the run statement, step boundary is reached. My understanding, is the loop iterated 1o times and the datatep from data to run iterates only once. Is my understanding correct? Please explain and correct my understanding!
do i=1 to 10;
end;/*without the explicit output statement*/
here again, the loop iterates 10 times and the implicit output writes the last obs from have to the output dataset, but the datastep from data to run iterates only once. Is my understanding correct? Please explain and correct my understanding!
do until (last);
is this exactly the same as
do i=1 to nobs;
set have nobs=nobs;
also, my understanding is that the datastep iterates only once. Is my understanding correct? Please explain and correct my understanding!
/*some sas statments*/;
run; How many times the loop iterate and how many times does the datastep iterate here? also what happens when using explicit output and not explicit output here?
01-29-2015 06:03 AM
First you have to define HAVE. And then test test test.
01-29-2015 12:56 PM
I was saying if the example you gave is DOW loop.
01-29-2015 01:28 PM
Oh! Yes I suppose so. Although usually DOW has UNTIL(LAST.<byvar>);
As far as I know this SUGI presentation "The SAS Supervisor" by is the first reference I have found to using DO UNTIL(LAST.<BYVAR>);
I was there!
I don't have a SAS82 user guide anymore but there may be example in that document. Does anyone still have (ever had) one of those?
01-29-2015 06:04 PM
I just dug out my SAS82 manual and I did not see an example of that in there.
As far as I know, the supervisor paper that data_null_; mentioned is the first reference to that construct which was later popularized on SAS-L by Ian Whitlock.
01-29-2015 09:48 AM
Your understandings are basically correct ... just a few notes.
As data_null_ indicated, you can add to any of these steps:
If you add it at the end of the DATA step, it might help you understand more. _n_ counts the number of iterations of the DATA step.
In your Example #3, I'm assuming you meant to add END=LAST to the SET statement.
Example #4 is actually much more complicated, because the unspecified SAS statements might affect the number of iterations. For example, suppose they included:
Each mismatch on the subsetting IF ends that iteration of the DATA step.
01-30-2015 12:26 PM
The number of times the data step iterates in example 1 and 2 depends on the number of observations the have data set has:
N_iterations = ceil(observation_of_have_dataset / 10)
The number of iterations in Example 4 is the number of ID groups.