The OPTMODEL Procedure |
The LEAVE statement terminates the execution of the entire loop body (iterative DO, DO UNTIL, DO WHILE, or FOR) that immediately contains the LEAVE statement. Execution resumes at the statement that follows the loop. The following example demonstrates a simple use of the LEAVE statement:
proc optmodel; number i, j; do i = 1..5; do j = 1..4; if i >= 3 and j = 2 then leave; end; print i j; end;
The results from this code are displayed in Output 6.18.
For values of i equal to 1 or 2, the inner loop continues uninterrupted, leaving j with a value of 5. For values of i equal to 3, 4, or 5, the inner loop terminates early, leaving j with a value of 2.
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.