Macro Statements |
Type: | Macro statement |
Alias: | %GO TO |
Restriction: | Allowed in macro definitions only |
See also: | %label Statement |
Syntax | |
Details | |
Example | |
Providing Exits in a Large Macro |
Syntax |
%GOTO 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 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.
Details |
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.
Example |
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: A computed %GOTO contains % or & and resolves to a label.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.