25Sep/090
SAS Do Loop – Do Until
Do loops are great for a long list of tasks. Understanding do loops can save you an innumerable amount of programming and work arounds.
The basic form of a do loop is as follows:
Data new_ds;
Set old_ds;
Do some_index_var= 1 to 50 by 1;
Some SAS statements go here;
End;
run;
However, specifically in this post we want to talk about DO UNTIL loops. Do until loops are different because they evaluate the condition at the bottom of the loop. Example:
Data new_ds;
Set old_ds;
Do until var > 100;
Some SAS statements;
End;
Run;
This loop will execute the SAS statements at least one time and evaluate the var>100 condition at the bottom of the loop. If the condition is false, the loop will execute again.