调用symputx会抛出宏变量的错误

时间:2018-02-16 09:38:42

标签: macros sas

我正在尝试使用

将varialbe中的值保存到宏变量中
 call symputx

然而SAS抛出错误

我写的程序是这样的

data want; 
set have;
array SR(*) &orde; 
bb=dim(SR);

call symputx('D',bb);

array M(symget('D'));
do i=1 to dim(SR);
M(i)=SR(i);
end; 

run;

它给出错误

array MXY_A(symget(D));
                        -
                        79
                        76
ERROR 79-322: Expecting a ).

ERROR 76-322: Syntax error, statement will be ignored.

这里可能出现什么问题?

2 个答案:

答案 0 :(得分:2)

在编译数据步骤之前,在开始执行之前设置数组的维度。在数据步骤开始执行之前,不会通过call symput定义宏变量。如果要使用宏变量来设置这样的数组大小,则需要在数据步骤之前定义它。

答案 1 :(得分:0)

下面的代码遍历数组的每个值,然后在WANT数据集的新行中输出:

代码:

data want(keep=id new);
      array score{3} s1-s3;
/*array values: 99,60,82 */
      input id score{*};
         do i=1 to dim(score);
         new=score{i};
            output;
         end;
      datalines;
   1234  99 60 82
   ;
run;

输出:

enter image description here

相关问题