设置带变量的1d数组的长度

时间:2021-06-10 21:18:08

I would like to set the length of an array depending on what value i obtain from reading a dataset:number which has one variable num with one numeric value. But I am getting an error message: saying that I cannot initiate the probs array. Can i get any suggestion on how to solve this issue? (I really don't want to hardcode the length of the probs array)

我想根据读取数据集得到的值来设置数组的长度:数字有一个变量num和一个数值。但我收到一条错误消息:说我无法启动probs数组。我可以就如何解决这个问题得到任何建议吗? (我真的不想硬编码probs数组的长度)

data test;
 if _n_=1 then do;
 set work.number;
 i =  num +1;
 end;

array probs{i} _temporary_ .....

1 个解决方案

#1


3  

SAS Data step arrays can not be dynamically sized during step run-time.

在步骤运行时,无法动态调整SAS数据步骤数组的大小。

One common approach is to place the computed number of rows of the data set into a macro variable before the data step.

一种常见的方法是在数据步骤之前将计算出的数据集行数放入宏变量中。

I'm not sure what you are doing with probs.

我不确定你在用probs做什么。

  • What values will be going into the array elements ?
  • 将进入数组元素的值是多少?

  • Do you need all prob data while iterating through each row of the data set ?
  • 在迭代数据集的每一行时,您是否需要所有的概率数据?

  • Is a single result computed from the probs data ?
  • 是否从probs数据计算出单个结果?

Example - Compute row count in a data null using nobs set option:

示例 - 使用nobs set选项计算数据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;

Of course your actual use of the array will vary.

当然,您对阵列的实际使用会有所不同。

The many other ways to get row_count include dictionary.table views, sql select count(*) into and a variety of ATTRN invocations.

获取row_count的许多其他方法包括dictionary.table视图,sql select count(*)into和各种ATTRN调用。

#1


3  

SAS Data step arrays can not be dynamically sized during step run-time.

在步骤运行时,无法动态调整SAS数据步骤数组的大小。

One common approach is to place the computed number of rows of the data set into a macro variable before the data step.

一种常见的方法是在数据步骤之前将计算出的数据集行数放入宏变量中。

I'm not sure what you are doing with probs.

我不确定你在用probs做什么。

  • What values will be going into the array elements ?
  • 将进入数组元素的值是多少?

  • Do you need all prob data while iterating through each row of the data set ?
  • 在迭代数据集的每一行时,您是否需要所有的概率数据?

  • Is a single result computed from the probs data ?
  • 是否从probs数据计算出单个结果?

Example - Compute row count in a data null using nobs set option:

示例 - 使用nobs set选项计算数据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;

Of course your actual use of the array will vary.

当然,您对阵列的实际使用会有所不同。

The many other ways to get row_count include dictionary.table views, sql select count(*) into and a variety of ATTRN invocations.

获取row_count的许多其他方法包括dictionary.table视图,sql select count(*)into和各种ATTRN调用。