我想根据读取数据集获得的值来设置数组的长度:数字,其中一个变量 num ,带有一个数值。但我收到一条错误消息:说我无法启动probs数组。我可以就如何解决这个问题得到任何建议吗? (我真的不想硬编码probs数组的长度)
data test;
if _n_=1 then do;
set work.number;
i = num +1;
end;
array probs{i} _temporary_ .....
答案 0 :(得分:3)
在步骤运行时,无法动态调整SAS数据步长数组。
一种常见的方法是在数据步骤之前将计算出的数据集行数放入宏变量中。
我不确定您使用probs
做了什么。
示例 - 使用nobs
设置选项计算数据 null 中的行计数:
data _null_;
if 0 then set work.number nobs=row_count;
call symputx ('ROW_COUNT', row_count);
stop;
run;
data test;
array probs (&ROW_COUNT.) _temporary_;
* something with probs[index] ;
* maybe fill it ?
do index = 1 by 1 until (last_row);
set work.number;
probs[index] = prob; * prob from ith row;
end;
* do some computation that a procedure isn't able to;
…
result_over_all_data = my_magic; * one result row from processing all prob;
output;
stop;
run;
当然,您对阵列的实际使用会有所不同。
获取row_count的许多其他方法包括dictionary.table
次观看,sql select count(*) into
和各种ATTRN
次调用。