![]() Chapter Contents |
![]() Previous |
![]() Next |
| %GOTO |
| Type: | Macro statement |
| Alias: | %GO TO |
| Restriction: | Allowed in macro definitions only |
| See also: | %label |
| Syntax | |
| Details | |
| Example | |
| Providing Exits in a Large Macro | |
Syntax |
| %GOTO label; |
The following examples illustrate how to use label:
%goto findit; /* branch to the label FINDIT */
%goto &home; /* branch to the label that is */
/* the value of the macro variable HOME */
![[cautionend]](../common/images/cautend.gif)
| 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 sucessfully.;
%exit: %mend check;
% or
& and resolves to a label.
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.