我正在尝试将数值变量传递给此宏。我可以通过KEEP和SET语句传递它,但当它到达RENAME语句时,我得到这些错误:
错误:变量'2013'n不存档WORK.'2013'n。
错误:文件WORK.'2013'n上的DROP,KEEP或RENAME选项无效。
%macro step2(year,cwyear);
TITLE; FOOTNOTE;
DATA WORK._EG_CFMT;
LENGTH label $ 9;
SET WORK."&year."n (KEEP="&year."n "&cwyear."n RENAME=("&year."n =start "&year."n =label)) END=__last;
RETAIN fmtname "cw&year."n type "C";
end=start;
RUN;
%mend step2;
当我更改& year的双引号时。单引号,如下:
SET WORK.'&year.'n (KEEP="&year."n "&cwyear."n RENAME=("&year."n =start "&year."n =label))
我收到此错误:
错误:文件工作。'& YEAR.'n.DATA不存在。
当我改回所有双引号并删除n时,我收到以下错误:
ERROR 22-322:语法错误,需要以下其中一项:名称,带引号的字符串,;,CUROBS,END,INDSNAME,KEY,KEYRESET,KEYS, NOBS,OPEN,POINT, DATA , LAST , NULL 。
我如何使这项工作?
感谢您的帮助!
答案 0 :(得分:5)
你需要有双引号和n。名称文字可以像任何其他字符串一样使用单引号或双引号。单引号不会解决它们内部的宏变量,会加倍。
示例:
options validvarname=any;
options validmemname=extend;
data '2015'n;
'2015'n = 5;
run;
%macro do_something(year=);
data work.want;
set "&year."n(rename="&year."n = start);
run;
%mend do_something;
%do_something(year=2015);