%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;
Run Code Online (Sandbox Code Playgroud)
我需要知道宏定义之外的测试值是多少?
如果在全局范围中定义了宏变量,即您的%LET X = 15;,则宏中宏变量的任何更改都会影响全局值,除非您在宏中使用显式覆盖它%LOCAL X;.
%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 */