Branches macro processing to the specified label.
Type: |
Macro statement
|
Alias: |
%GO TO
|
Restriction: |
Allowed in macro definitions only
|
See also: |
%label Statement
|
-
label
-
is either the name of the label that you
want execution to branch to or a text expression that generates the label.
A text expression that generates a label in a %GOTO statement is called a computed %GOTO destination.(footnote 1)
The following examples illustrate how to
use label:
- CAUTION:
- No percent sign (%) precedes the label name in the %GOTO
statement.
The syntax of the %GOTO statement
does not include a % in front of the label name. If you use a %, the macro
processor attempts to call a macro by that name to generate the label. ![[cautionend]](../../../../common/63294/HTML/default/images/cautend.gif)
Branching with the %GOTO statement has
two restrictions. First, the label that is the target of the %GOTO statement
must exist in the current macro; you cannot branch to a label in another macro
with a %GOTO statement. Second, a %GOTO statement cannot cause execution to
branch to a point inside an iterative %DO, %DO %UNTIL, or %DO %WHILE loop
that is not currently executing.
The
%GOTO statement is useful in large macros when you want to provide an exit
if an error occurs.
%macro check(parm);
%local status;
%if &parm= %then %do;
%put ERROR: You must supply a parameter to macro CHECK.;
%goto exit;
%end;
more macro statements that test for error conditions
%if &status > 0 %then %do;
%put ERROR: File is empty.;
%goto exit;
%end;
more macro statements that generate text
%put Check completed successfully.;
%exit: %mend check;
FOOTNOTE 1:
![[arrow]](../../../../common/63294/HTML/default/images/fntarrow.gif)
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.