macro processor does not stop compiling tokens. Every line of code that you submit
becomes part of the macro.
Resubmitting the macro definition and adding the %MEND statement does not correct
the error. When you submit the corrected definition, the macro processor treats it as a
nested definition in the original macro definition. The macro processor must find a
matching %MEND statement to stop compilation.
Note: It is a good practice to use the %MEND statement with the macro name, so you
can easily match %MACRO and %MEND statements.
If you recognize that SAS is not processing submitted statements and you are not sure
how to recover, submit %MEND statements one at a time until the following message
appears in the SAS log:
ERROR: No matching %MACRO statement for this %MEND statement.
Then recall the original erroneous macro definition, correct the error in the %MEND
statement, and submit the definition for compilation.
There are other syntax errors that can create similar problems, such as unmatched
quotation marks and unclosed parentheses. Often, one of these syntax errors leads to
others. Consider the following example:
%macro rooms;
/* other macro statements& */
%put **** %str(John's office) ****; /* ERROR */
%mend rooms;
%rooms
When you submit these statements, the macro processor begins to compile the macro
definition ROOMS. However, the single quotation mark in the %PUT statement is not
marked by a percent sign. Therefore, during compilation the macro processor interprets
the single quotation mark as the beginning of a literal token. It does not recognize the
closing parenthesis, the semicolon at the end of the statement, or the %MEND statement
at the end of the macro definition.
To recover from this error, you must submit the following:
');
%mend;
If the above methods do not work, try submitting the following string:
*'; *"; *); */; %mend; run;
Continue submitting this string until the following message appears in the SAS log:
ERROR: No matching %MACRO statement for this %MEND statement.
Obviously, it is easier to catch these errors before they occur. You can avoid subtle
syntax errors by carefully checking your macros before submitting them for compilation.
For a syntax checklist, see “Developing Bug-free Macros” on page 123.
Note: Another cause of unexplained and unexpected macro behavior is using a reserved
word as the name of a macro variable or macro. For example, because SAS reserves
names starting with SYS, you should not create macros and macro variables with
names beginning with SYS. Most host environments have reserved words too. For
example, on PC-based platforms, the word CON is reserved for console input. For
Troubleshooting Your Macros 129