LINK Statement


Jumps to a statement label

Valid: in a DATA step

Category: Control

Type: Executable

Syntax

LINK label ;

Arguments

label

  • specifies a statement label that identifies the LINK destination. You must specify the label argument.

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

The difference between the LINK statement and the GO TO statement is in the action of a subsequent RETURN statement. A RETURN statement after a LINK statement returns execution to the statement that follows LINK. A RETURN statement after a GO TO statement returns execution to the beginning of the DATA step, unless a LINK statement precedes GO TO, in which case execution continues with the first statement after LINK. In addition, a LINK statement is usually used with an explicit RETURN statement, whereas a GO TO statement is often used without a RETURN statement.

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:

  • DO Statement on page 1143

    GO TO Statement on page 1210

    Labels, Statement on page 1279

    RETURN Statement on page 1386




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net