宏变量不会用下划线解析

时间:2015-04-03 20:50:02

标签: sas sas-macro

在使用下划线时尝试获取宏变量以解析宏定义时出现问题。我想保留我在这里的命名约定,但需要宏变量来解决这个问题。我错过了什么?

%macro mymacro(dd=,mm=,yy=,dnr=,dma=);
.
.
.

%if dnr = 1 %then %let dnrname=est;
%if dnr = 2 %then %let dnrname=cen;
%if dnr = 3 %then %let dnrname=mtec;
%if dnr = 4 %then %let dnrname=pac;
%if dnr = 5 %then %let dnrname=mtwp;

data setoff_&dnrname._&dma._&mm.&dd.&yy.;
    set restart_no retimed one_min_durations;
run;
.
.
.
%mend mymacro;

错误如下:

NOTE: Line generated by the invoked macro "SETOFF".
89      data setoff_&dnrname._&dma._&mm.&dd.&yy.;     set restart_no retimed one_min_durations;
                    -
                    22
                    200
89  ! run;  proc sort data = setoff_&dnrname._&dma._&mm.&dd.&yy.;     by &dims_list. sid; run;

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;,
              _DATA_, _LAST_, _NULL_.

1 个答案:

答案 0 :(得分:4)

%if dnr = 1 %then %let dnrname=est;

这就是问题所在。 dnr永远不等于1。你错过了&符号。