67Writing Loops in the DATA Step
In the DO WHILE loop, the expression is evaluated at the top of the DO
loop. The DO loop will not execute if the expression is false. We can rewrite
program5.4 by using the DO WHILE loop.
Program 5.5:
data ex5_5(drop = rannum);
do while (id < 4);
id + 1;
rannum = ranuni(2);
if rannum > 0.5 then group = 'D';
else group = 'P';
output;
end;
run;
In Program 5.5, the ID variable is created inside the loop with the SUM
statement. Thus, the variable ID is initialized to 0 in the PDV at the begin-
ni