Joe
Joe

Reputation: 63424

Why am I getting unbalanced quotes in my macro?

I've got a macro which includes some comments, since I'm good about documenting my code. For some reason, when I run this macro, I get a hanging quote. Why?

Test macro that replicates this:

%macro testme;
* Comment that is in my macro that doesn't work;
proc freq data=sashelp.class;
run;

%mend testme;

%testme;

On the first execution it fails entirely, and on the second it gives me the message ERROR: No matching %MACRO statement for this %MEND statement.

Upvotes: 2

Views: 592

Answers (1)

Joe
Joe

Reputation: 63424

In the SAS Macro language, single line comments aren't treated quite the same as in the base SAS language. Specifically:

*something;

Is not a comment in the SAS macro language! It will be submitted to regular SAS, and will become a comment... but it won't be ignored by the SAS Macro parser, which is where this is a problem. It tokenizes it, which causes it to not ignore the quotation character.

You need to use "PL/1" style comments (ie, block comments) to make this work properly; or just don't use apostrophes (ie, do not instead of don't in comments).

%macro testme;
/* Comment won't break things now!*/
proc freq data=sashelp.class;
run;

%mend testme;

%testme;

See the SAS support article on Using Comments In Macros for more information.

Upvotes: 5

Related Questions