Chapter Contents |
Previous |
Next |
LEAVE |
Category: | Control Flow |
Comparisons: | SAS Statement with limitations in SCL |
Syntax | |
Details | |
Examples | |
Example 1: LEAVE Statements Without Label Names | |
Example 2: LEAVE Statements With Label Names | |
See Also |
Syntax |
LEAVE <label>; |
Type: Character
Details |
The LEAVE statement is provided in SCL to control the execution of DO groups. When you need to force the statements in a DO group to stop executing, you can use the LEAVE statement to stop executing statements in a DO group and to start executing a statement that is outside of that DO group.
Note: In DATA step code, the LEAVE statement stops processing only the current DO loop. In SCL code, the LEAVE statement stops processing the current DO loop or DO group, whichever is closest. For example, suppose your code contains a DO loop that contains DO groups:
do n=1 to 5; /* DO loop */ if n=3 then do; leave; end; /* DO group */ put n=; end;When this code is compiled and run as part of an SCL program, the output is:
n=1 n=2 n=3 n=4 n=5When this code is submitted as part of a DATA step, the output is:
n=1 n=2 n=3See DO for more information on DO groups and DO loops.
Examples |
If a LEAVE statement does not contain the name of a program label, the program stops executing the statements in the DO group and starts executing the first statement after the DO group's END statement. For example, when the condition in the IF statement in the following program is true (that is, when the value of SUM > 10), the program jumps immediately to the statement following the END statement (in this case, the PUT statement).
INIT: return; MAIN: do while(i<5); sum+i; i=i+2; if (sum>10) then do; leave; end; put sum=; end; totalsum=sum; return; TERM: return;
In this example, when the condition SUM > 50 is true, the program leaves the LAB1 DO group and returns to the next statement following the DO group (in this case, the PUT statement).
INIT: sum=45; return; MAIN: link LAB1; return; LAB1: do i=1 to 10; if (sum>10) then do; k=0; do until (k>=20); sum+k; if (sum>50) then leave LAB1; k+2; end; end; end; put 'LEAVE LAB1, sum >50 ' sum=; return; TERM: return;
See Also |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.