SAS 宏中这段代码的逻辑是什么?
what is the logic of this code in SAS Macros?
%let x = 15;
%macro test;
%let x = 10;
%put x inside macro test = &x;
%mend test;
%test;
%put x outside the macro test =&x;
%put x inside the macro test =&x;
我想知道宏定义之外的test值是多少?
如果宏变量是在全局范围内定义的,即您的 %LET X = 15;
,那么宏中对该宏变量的任何更改都会影响全局值,除非您在宏中使用 [= 显式覆盖它11=].
%let x = 15; /* Global X = 15 */
%macro test;
%let x = 10; /* Global X = 10 */
%put x inside macro test = &x; /* 10 */
%mend test;
%test;
%put x outside the macro test =&x; /* 10 */
但是 %LOCAL
%let x = 15; /* Global X = 15 */
%macro test;
%local x;
%let x = 10; /* Local X = 10 */
%put x inside macro test = &x; /* 10 */
%mend test;
%test;
%put x outside the macro test =&x; /* 15 */
%let x = 15;
%macro test;
%let x = 10;
%put x inside macro test = &x;
%mend test;
%test;
%put x outside the macro test =&x;
%put x inside the macro test =&x;
我想知道宏定义之外的test值是多少?
如果宏变量是在全局范围内定义的,即您的 %LET X = 15;
,那么宏中对该宏变量的任何更改都会影响全局值,除非您在宏中使用 [= 显式覆盖它11=].
%let x = 15; /* Global X = 15 */ %macro test; %let x = 10; /* Global X = 10 */ %put x inside macro test = &x; /* 10 */ %mend test; %test; %put x outside the macro test =&x; /* 10 */
但是 %LOCAL
%let x = 15; /* Global X = 15 */ %macro test; %local x; %let x = 10; /* Local X = 10 */ %put x inside macro test = &x; /* 10 */ %mend test; %test; %put x outside the macro test =&x; /* 15 */