SAS 数组定义错误

SAS array define error

%let ng = 4;

data a1;
set a2;
array cur{&ng} cur1-cur&ng.;
do i = 1 to &ng.;
if (_n_ = (i-1)*5 + 1) then cur[i] = Val; 
end;
run;

错误消息

ERROR: Missing numeric suffix on a numbered variable list (cur1-cur).
ERROR: Too few variables defined for the dimension(s) specified for the array cur.

ERROR 22-322: Syntax error, expecting one of the following: a name, (, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.  

ERROR 200-322: The symbol is not recognized and will be ignored.

为什么 do i = 1 to &ng.cur{&ng} 工作但 cur1-cur&ng. 产生错误?

该代码对我来说工作正常,但是我遇到了这个问题,我使用 proc sql into:call symput 方法创建了一个宏变量(在本例中为 ng),因为这些设置默认长度为 8,并用空格填充该值。我怀疑在您的实际代码中,宏变量 ng 是以这些方式之一创建的。

要解决此问题,请尝试添加 %trim,如下所示。

array cur[&ng.] cur1-cur%trim(&ng.);

您还需要添加一个 end 语句来关闭 do 循环。