Sas 功能是如何工作的?

Sas 功能是如何工作的?,sas,Sas,我认为symexist用于检查宏变量(本地变量)。我做了一个测试,但是输出超出了我的预期。代码是: %macro test(t1,t2); %if %symexist(t1) %then %put &t1. is exist; %if %symexist(t2) %then %put &t2. is exist; %mend; %test(test1,); 输出为: test1 is exist is exist 如果条件%symexist(t2)为真,请查看逻辑:%s。 t

我认为symexist用于检查宏变量(本地变量)。我做了一个测试,但是输出超出了我的预期。代码是:

%macro test(t1,t2);
%if %symexist(t1) %then %put &t1. is exist;
%if %symexist(t2) %then %put &t2. is exist;
%mend;
%test(test1,);
输出为:

test1 is exist
is exist
如果条件%symexist(t2)为真,请查看逻辑:%s。 t2没有宏变量。它是如何实现的?有人来解释symexist的工作原理吗?我找了一下,但没找到

谢谢,
Andrea

您需要使用&t1而不是t1,因为您想要测试test1的存在,而不是t1的存在

但它仍然会出错,因为宏变量t2不存在

%let test1 = Yes;

%macro test(t1, t2);
    %if %symexist(&t1) %then
        %put &t1. is exist;

    %if %symexist(&t2) %then
        %put &t2. is exist;
    %else
        %put &t2. does not exist;
%mend;

%test(test1, test2);
输出将是:

test1不存在

test2不存在


存在名为T1和T2的宏变量,因为您通过将它们作为宏的参数来定义它们。所有宏参数都是宏的本地宏变量