AFHood Group Blog The thoughtless yammerings of marketing junkies..

7Oct/090

SAS Do loops – Do While

Here is yet another Do Loop post.

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 WHILE loops. Do while loops are different because they evaluate the condition at the top of the loop. Example:

Data new_ds;

Set old_ds;

Do while var > 100;

Some SAS statements;

End;

Run;

This loop will not execute the loop if the condition is not met upon the first execution. This is what makes WHILE so valuable. Conditional processes that allows you to exit the loop before the first iteration.