macros - SAS MACRO 引用问题 : passing string with macro trigger as macro parameter

标签 macros sas quoting

是否可以传递带有宏触发器的字符串作为宏参数? 请参阅下面的示例代码:

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/

相关文章:

java - 导入 freemarker 宏

function - 如何在SAS中找到子串的最后位置(索引函数的反面)

sas - 压缩动态变量的换行符

makefile - 在带有空格的路径上使用 Make $(dir) 或 $(notdir)

c - 使用循环定义的宏

dictionary - 如何以 map 作为参数调用Freemarker宏?

macros - 在 Common Lisp 中,如何定义一个扩展为空的宏(而不是 `nil` )?

excel - SAS DDE excel另存为无警告

bash - cd wslpath as bash function shell 引用问题

vim - 哪些 Vim 命令可用于引用/取消引用单词?