Identifies a statement that is referred to by another statement.
| Valid in: | DATA step |
|---|---|
| Categories: | CAS |
| Control | |
| Type: | Declarative |
Table of Contents
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 |
|
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:
|
| Example |
|
The statement label identifies the destination of one of the following language elements:
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
;
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...
;
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;