SAS Component Language Dictionary |
Stops processing the current DO group or DO loop and resumes with
the next statement in sequence
Category: |
Control Flow
|
Comparisons: |
SAS Statement with limitations in SCL
|
-
label
-
is the name of a program label that is associated
with the DO group.
Type: Character
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=5
When this code is submitted as part of a DATA step, the output is:
n=1
n=2
n=3
See DO for more information on DO groups and DO loops. ![[cautionend]](../../../../common/64368/HTML/default/images/cautend.gif)
For details about
the LEAVE statement in the Base SAS language, see
SAS Language Reference: Dictionary.
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;
CONTINUE
DO
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.