我一直以为%let
创建一个 local
如果在 %macro . . . %mend
内使用,则变量
但是当我运行此代码时,SAS 日志显示 GLOBAL TESTVAR value1
%let testVar = value2;
%macro test;
%let testVar = value1;
%mend;
%test
%put _all_;
所以,我不明白为什么全局变量
testVar
的值改为 value1
.我原以为它会保持不变 value2
. %let
%macro
里面的声明应该只影响本地符号表。SAS documentation says :
When the macro processor executes a macro program statement that can create a macro variable, the macro processor creates the variable in the local symbol table if no macro variable with the same name is available to it
最佳答案
关键是“如果没有同名的宏变量可用” - 在这种情况下,可以使用同名的宏变量,因为您已经将 testVar 定义为全局变量。
您可以为其指定一个不与全局共享的名称,也可以将其显式声明为本地:
%let testVar = value2;
%macro test;
%local testVar;
%let testVar = value1;
%mend;
%test
关于sas - 为什么不 %let 创建一个局部宏变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27532849/