在 SAS 中解析宏变量

Resolve Macro Variable in SAS

我有一个关于在 SAS 中解析宏变量的问题。我有以下代码,它是一个更大块的简化版本。出于实际原因,我无法更改代码结构。

%let a = x1 x2 x3;
%let b = y1 y2 y3;
%let c = a b;


%macro test (input);
    %local i;
    %let string_c = %str(&input);
    %do i=1 %to 2;
        %put &%qscan(&string_c, &i);  /* ? */
    %end;
%mend test;

%test(&c);

步骤中?上面,我想将a和b解析为宏变量并让系统打印出来

x1 x2 x3

然后

y1 y2 y3

但是上面的代码并没有将a和b重新定义为宏变量,系统打印出来

&a
&b

我想知道是否有解决这个问题的方法。

非常感谢!

& 触发器是为了解析一个名称,但是您跟在另一个宏触发器 % 而不是名称。所以它什么都不做。将名称分配给宏变量然后对其进行评估更容易。

%macro test(list);
  %local i varname value;
  %do i=1 %to %sysfunc(countw(&list,%str( )));
    %let varname=%scan(&list,&i,%str( ));
    %let value=&&&varname ;
    %put The value of "&varname" is "&value" ;
  %end;
%mend test;
%let a=One ;
%let b=Two ;
%test(a b);

这导致:

The value of "a" is "One"
The value of "b" is "Two"

试试这个:

%let a = x1 x2 x3;
%let b = y1 y2 y3;
%let c = a b;

%macro test (input);
    %local i;
    %let string_c =%str(&input);
    %do i=1 %to 2;
        %put %unquote(&&%qscan(&string_c, &i));
    %end;
%mend test;

%test(&c);