Previous Page | Next Page

Statements

LEAVE Statement



Stops processing the current loop and resumes with the next statement in the sequence.
Valid: in a DATA step
Category: Control
Type: Executable

Syntax
Without Arguments
Details
Comparisons
Examples

Syntax

LEAVE;


Without Arguments

The LEAVE statement stops the processing of the current DO loop or SELECT group and continues DATA step processing with the next statement following the DO loop or SELECT group.


Details

You can use the LEAVE statement to exit a DO loop or SELECT group prematurely based on a condition.


Comparisons


Examples

This DATA step demonstrates using the LEAVE statement to stop the processing of a DO loop under a given condition. In this example, the IF/THEN statement checks the value of BONUS. When the value of BONUS reaches 500, the maximum amount allowed, the LEAVE statement stops the processing of the DO loop.

data week;
   input name $ idno start_yr status $ dept $;
   bonus=0;
   do year= start_yr to 1991;
      if bonus ge 500 then leave;
      bonus+50;
   end;
   datalines;
Jones 9011 1990 PT PUB
Thomas 876 1976 PT HR
Barnes 7899 1991 FT TECH
Harrell 1250 1975 FT HR
Richards 1002 1990 FT DEV
Kelly 85 1981 PT PUB
Stone 091 1990 PT MAIT
;

Previous Page | Next Page | Top of Page