Label: Statement

Identifies a statement that is referred to by another statement.

Valid in: DATA step
Categories: CAS
Control
Type: Declarative

Syntax

Required Arguments

label

specifies any SAS name. Follow the SAS name with a colon (:).

Requirement The name that you choose for your label must be followed by a colon (:).
Example
data mydata2;
   type="new"; num=0;
   if type ="new" then 
/* LINK to label calculate */
   link calculate; 
/* define destination (statement) for label calculate */
   calculate: if num=0 
      then order="yes";
   num=num+1;
run;

statement

specifies any executable statement, including a null statement (;).

Restrictions No two statements in a DATA step can have the same label.
If a statement in a DATA step is labeled, it should be referenced by a statement or option in the same step.
Requirement Both the label and statement arguments are required and they must be separated by a colon (:).
Tip A null statement can have a label:
ABC:;
Example
data test;
   <other-sas-DATA-step-statements>
   if x=1 then 
/* Define the label-name (mylabel) */
   GOTO mylabel;
/* Define the statement-name and destination for the label */
   mylabel:  PUT "Hello"; 
run;

Details

The statement label identifies the destination of one of the following language elements:

Comparisons

  • The LABEL statement assigns a descriptive label to a variable.
  • The statement label identifies a statement or group of statements that are referred to in the same DATA step by another statement, such as a GOTO statement.

Examples

Example 1: Jumping to Another Statement

In this example, if Stock=0, the GOTO statement causes SAS to jump to the statement that is labeled reorder. When Stock is not 0, execution continues to the RETURN statement and then returns to the beginning of the DATA step for the next observation.

data Inventory Order;
   input Item $ Stock @;
      /* go to label reorder: */
   if Stock=0 then goto reorder;
   output Inventory;
   return;
      /* destination of GOTO statement */
   reorder: input Supplier $;
   put 'ORDER ITEM ' Item 'FROM ' Supplier;
   output Order;
   datalines;
milk  0 A
bread 3 B
;

Example 2: Diverting Program Execution

In this example, when the value of variable TYPE is aluv, the LINK statement diverts program execution to the statements that are associated with the label CALCU. The program executes until it encounters the RETURN statement, which sends program execution back to the first statement that follows LINK. SAS executes the assignment statement, writes the observation, and then returns to the top of the DATA step to read the next record. When the value of TYPE is not aluv, SAS executes the assignment statement, writes the observation, and returns to the top of the DATA step.

data hydro;
   input type $ depth station $;
      /* link to label calcu: */
   if type ='aluv' then link calcu; 
   date=today();
      /* return to top of step */
   return;                         
   calcu: if station='site_1' 
      then elevatn=6650-depth;
   else if station='site_2' 
      then elevatn=5500-depth;
         /* return to date=today(); */
   return;                           
   datalines;
aluv 523 site_1
uppa 234 site_2
aluv 666 site_2
...more data lines...
;

Example 3: Using a Statement Label with Null

The Null statement is useful while you are developing a program. For example, use it after a statement label to test your program before you code the statements that follow the label.

data _null_;
   set dsn;
   file print header=header;
   put 'report text';
     ...more statements...
   return;
   header:;
run;
data _null_;
   set dsn;
   file print header=header;
   put 'report text';
     ...more statements...
   return;
   header:;
run;

See Also

Last updated: June 17, 2025