宏变量作为数据步骤中的数字

macro variable as numeric inside data step

我需要一点帮助。 在上面的 post 中,我设置动态变量的问题不大,我将计算使用的列。我该怎么做?

data want;
  set have;
  array V varr1-varr3;
 call SYMPUTN('countxxx',dim(V)) /* here I try set numeric*/
  array L[&countxxx.] _temporary_;/* here input numeric*/

  * save first rows values in temporary array for use in other rows;
  if _n_ = 1 then 
    do index = 1 to dim(V);
      L[index] = V[index];
    end;

  * … for example … ;

  array delta_from_1st [&countxxx.];  * array statement implicitly creates three new variables that become part of PDV and get output;
  do index = 1 to dim(V);
    delta_from_1st[index] = V[index] - L[index];
  end;      
run;

这不是字符与数字的问题。所有宏变量都是字符,但由于您的值都是数字,SAS 编译器会将其生成的文本解释为数字,因为您没有将其括在引号中。

真正的问题是您试图在创建宏变量 COUNTXXX 之前引用它。在数据步骤开始之前解析宏引用 运行。将您的步骤分成两步。

data _null_;
  set have;
  array V varr:;
  call SYMPUTX('countxxx',dim(V)) ;
  stop;
run;

data want;
  set have;
  array L[&countxxx.] _temporary_;
...