SAS宏中此代码的逻辑是什么?

时间:2015-06-30 06:11:26

标签: sas sas-macro

%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;

我需要知道宏定义之外的测试值是什么?

1 个答案:

答案 0 :(得分:6)

如果在全局范围中定义了一个宏变量,即%LET X = 15;,则宏中该宏变量的任何更改都会影响全局值,除非您使用{{1}在宏中明确覆盖它}。

%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 X;

%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 */