是否可以传递带有宏触发器的字符串作为宏参数? 请参阅下面的示例代码:
options mprint;
%let string5='%abc%def%';
%macro test(string);
data _null_;
call execute('%test2('||&string.||')');
run;
%mend;
%macro test2(string2);
data test3;
a=%str(%')&string2.%str(%');
run;
%mend;
%test(&string5);
此代码成功运行,但它尝试调用宏 %abc 和 %def,这导致了警告。
如果我尝试将其放入引号中以屏蔽字符串,则会出现语法错误,如下所示:
options mprint;
%let string5='%abc%def%';
%macro test(string);
data _null_;
call execute('%test2('||%superQ(string)||')');
run;
%mend;
%macro test2(string2);
data test3;
a=%str(%')&string2.%str(%');
run;
%mend;
%test(&string5);
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, arrayname, (, +, -, INPUT, NOT, PUT, ^, _NEW_, ~.
有没有办法在不发出警告的情况下解决这个问题? 提前致谢!
最佳答案
试试这个:
%let string5='%abc%def%';
%macro test(string);
data _null_;
call execute('%test2('||%nrstr("&string.")||')');
run;
%mend;
%macro test2(string2);
data test3;
a=%nrquote(&string2.);
run;
%mend;
%test(&string5);
关于macros - SAS MACRO 引用问题 : passing string with macro trigger as macro parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43510024/