When reading repeating
sections of data (such as the revenue sections in the Master and
Universal files), stop processing the repeated section when all clauses
have been satisfied. Extra control of DO loops is available in the
LEAVE and CONTINUE statements. The LEAVE statement causes execution of
the loop to terminate and processing continues at the next statement
after the END statement for that loop. The CONTINUE statement jumps
back to the start of the DO loop.
The DELETE and RETURN
statements are similar in that they prematurely return processing to
the start of a data step. The RETURN statement forces the current
observation to be output.
The following example scans the Type63 file for accounts with 3 live products.
Data Rdtype63(Keep = District Instid) / View=Rdtype63;
Infile
Rdtype63;
Input @71 Active
Pd2.
@;
If Active Gt
0;
Do Kounter = 77 To 77+(Active-1)*24 By 24;
Input
@Kounter+10 Prodcode
$6.@;
If
Prodcode In ('A90101',’A90102’,’A90103’) Then
Do;
Input @Kounter+16 Enddate
8.@;
If Enddate Then Delete;
Prodcnt = Sum(Prodcnt,1);
If Prodcnt=3 Then Leave;
End;
Else If Prodcode gt (‘A90103’) Then Delete;
End;
If Prodcnt ne 3 Then Delete;
Input @3 District
$2.
@5 Instid $8.;
The do loop in the above example could have been written as ;
Do Kounter = 77 To 77+(Active-1)*24 By 24 Until (Prodcnt=3);
and the line If Prodcnt=3 Then
Leave; could then have been removed. This would have been less
efficient since the variable Kounter would have been updated by the do
loop & tested before the clause Until (Prodcnt=3) was evaluated.