为什么我的宏中出现不平衡的报价?

Joe*_*Joe 2 sas sas-macro

我有一个包含一些注释的宏,因为我很擅长记录我的代码.出于某种原因,当我运行这个宏时,我得到一个悬挂的引用.为什么?

测试复制此宏的宏:

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

%mend testme;

%testme;
Run Code Online (Sandbox Code Playgroud)

在第一次执行时,它完全失败,在第二次执行时它给了我消息 ERROR: No matching %MACRO statement for this %MEND statement.

Joe*_*Joe 5

在SAS Macro语言中,单行注释与基本SAS语言的处理方式不完全相同.特别:

*something;
Run Code Online (Sandbox Code Playgroud)

不是SAS宏语言的评论!它将被提交给常规SAS,并将成为评论...但SAS宏解析器不会忽略它,这是一个问题所在.它标记它,导致它不忽略引号字符.

您需要使用"PL/1"样式注释(即阻止注释)才能使其正常工作; 或者只是不使用撇号(即do not代替don't评论).

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

%mend testme;

%testme;
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅有关在宏中使用注释的SAS支持文章.