Chapter Contents |
Previous |
Next |
LINK |
Valid: | in a DATA step |
Category: | Control |
Type: | Executable |
Syntax | |
Arguments | |
Details | |
Comparisons | |
Examples | |
See Also |
Syntax |
LINK label; |
Details |
The LINK statement tells SAS to jump immediately to the statement label that is indicated in the LINK statement and to continue executing statements from that point until a RETURN statement is executed. The RETURN statement sends program control to the statement immediately following the LINK statement.
The LINK statement and the destination must be in the same DATA step. The destination is identified by a statement label in the LINK statement.
The LINK statement can branch to a group of statements that contains another LINK statement. This arrangement is known as nesting. To avoid infinite looping, SAS has set a maximum on the number of nested LINK statements. Therefore, you can have up to ten LINK statements with no intervening RETURN statements. When more than one LINK statement has been executed, a RETURN statement tells SAS to return to the statement that follows the last LINK statement that was executed.
Comparisons |
When your program executes a group of statements at several points in the program, using the LINK statement simplifies coding and makes program logic easier to follow. If your program executes a group of statements at only one point in the program, using DO-group logic rather than LINK-RETURN logic is simpler.
Examples |
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... ;
See Also |
Statements:
|
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.