I want to get the sum, max, and/or min of a subset of an array.
我想要得到数组子集的和,最大值和/或最小值。
In SAS, you can say:
在SAS中,你可以说:
x = max(of v5-v10);
where v5 through v10 are variables
v5到v10是变量吗
But you cannot say:
但你不能说:
array v[20];
i = 5;
x = max(of v[i]-v[i+5];
It doesn't understand that v[i]-v[i+5] is a range of variables. Is there anyother way to do it what would work?
它不理解v[i]-v[i+5]是一系列变量。还有别的方法吗?
2 个解决方案
#1
5
You can either iterate over the elements of the array:
可以对数组中的元素进行迭代:
data max ; array v{20} ; i = 5 ; vmax = . ; do n = i to i+5 ; vmax = max(vmax,v{n}) ; end ; run ;
Or create a new array which contains just the elements you require:
或者创建一个新数组,其中只包含您需要的元素:
%LET I = 5 ; data max ; array v{*} v&I-v%EVAL(&I+5) ; vmax = max(of v{*}) ; run ;
#2
0
You can use:
您可以使用:
array a(*) _numeric_;
do i=1 to dim(a);
if a(i) = . then a(i) = 0; //this replaces mssing for 0´s but you can implement any logic here
end;
drop i;
#1
5
You can either iterate over the elements of the array:
可以对数组中的元素进行迭代:
data max ; array v{20} ; i = 5 ; vmax = . ; do n = i to i+5 ; vmax = max(vmax,v{n}) ; end ; run ;
Or create a new array which contains just the elements you require:
或者创建一个新数组,其中只包含您需要的元素:
%LET I = 5 ; data max ; array v{*} v&I-v%EVAL(&I+5) ; vmax = max(of v{*}) ; run ;
#2
0
You can use:
您可以使用:
array a(*) _numeric_;
do i=1 to dim(a);
if a(i) = . then a(i) = 0; //this replaces mssing for 0´s but you can implement any logic here
end;
drop i;