如何在编译时获取数组大小?
How to get array size during compile time?
我有一个数据集包含这样的参数
Parameters
year threshold1 threshold2
1 100 200
2 150 300
....
7 200 390
我能做到
data output;
set input;
if 0 then set set parameters;
array thresholds [2] thresholds:;
%do year = 1 %to 7;
year = &year.;
set parameters point=year;
array my_thresholds&year. [2] _temporary_;
do i = 1 to 2;
my_thresholds&year.[i] = thresholds[i];
end;
%end;
这将为 INPUT 中的每个观察值,每年的 threshold1 threshold2 作为变量,并为 my_thresholds&year
设置一个数组。拿着每个。
然而,问题在于阈值的数量是否未知。我做不到 dim(thresholds)
也做不到 *
。
如何让 SAS 在编译时知道如何设置数组?
据我所知,您不能在编译时动态设置数组的大小。
完成此操作的一种可能性是使用 proc contents 和 proc sql 来计算参数数据集中有多少阈值参数,然后通过宏变量将该信息传递给数据步骤.
data parameters;
do year=1 to 7;
threshold1 = 1;
threshold2 = 2;
threshold3 = 3;
output;
end;
run;
proc contents data=parameters out=cont noprint;
run;
proc sql noprint;
select count(*) into :thr_count
from cont
where name like "threshold%";
quit;
%put &thr_count.;
我有一个数据集包含这样的参数
Parameters
year threshold1 threshold2
1 100 200
2 150 300
....
7 200 390
我能做到
data output;
set input;
if 0 then set set parameters;
array thresholds [2] thresholds:;
%do year = 1 %to 7;
year = &year.;
set parameters point=year;
array my_thresholds&year. [2] _temporary_;
do i = 1 to 2;
my_thresholds&year.[i] = thresholds[i];
end;
%end;
这将为 INPUT 中的每个观察值,每年的 threshold1 threshold2 作为变量,并为 my_thresholds&year
设置一个数组。拿着每个。
然而,问题在于阈值的数量是否未知。我做不到 dim(thresholds)
也做不到 *
。
如何让 SAS 在编译时知道如何设置数组?
据我所知,您不能在编译时动态设置数组的大小。
完成此操作的一种可能性是使用 proc contents 和 proc sql 来计算参数数据集中有多少阈值参数,然后通过宏变量将该信息传递给数据步骤.
data parameters;
do year=1 to 7;
threshold1 = 1;
threshold2 = 2;
threshold3 = 3;
output;
end;
run;
proc contents data=parameters out=cont noprint;
run;
proc sql noprint;
select count(*) into :thr_count
from cont
where name like "threshold%";
quit;
%put &thr_count.;