在SAS中重置临时阵列 [英] Reset a temporary array in SAS
问题描述
在声明数组之后,我想为其余代码重置其值。
After I declares an array, I'd like to reset its values for the rest of the code.
array cutoffs[4] _temporary_ (1 2 3 4); /*works well*/
... use of the array
array cutoffs[3] _temporary_ (3.5 5 7.5); /*Error*/
... use of the updated array
错误为以下:
错误124-185:变量临界值已定义。
ERROR 124-185: The variable cutoffs has already been defined.
此错误非常明显,但我想知道如何在不更改其名称的情况下重新分配数组(这会很繁琐)。
This error is very clear but I wonder how could I reattribute the array without changing its name (which would be most tedious).
我尝试了一些语法,但我自己找不到,而且我在Google或stackoverflow上都没有看到资源。
I tried some syntaxes but couldn't find by myself, and I saw no ressources on google, nor on stackoverflow.
我该怎么办?
编辑:主要目的是我创建了一个函数(使用 proc fcmp
),该函数将数组作为参数并削减了值(例如R的 cut
函数)。该函数将在许多列上使用,但具有不同的截止值,我不想为每个列创建繁琐的数组。
EDIT : the main purpose is that I created a function (with proc fcmp
) that take arrays as parameter and cut the value (like R's cut
function). The function is to be used on a lot of columns but with different cutoffs, and I don't want to tediously create an array for each and every column.
推荐答案
您可以一个一个地更改截止值
数组的值。
You can change the values of the cutoffs
array one by one.
array cutoffs{4} _temporary_ (1 2 3 4); /*works well*/
... use of the array
cutoffs[1]=3.5;
cutoffs{2}=5;
cutoffs{3}=7.5;
cutoffs{4}=.;
或者您可以第二次使用另一个名称作为数组。
or you could just use another name for the array the second time.
话虽如此,您使用它的方式似乎有些奇怪。
With that said, the way you are using this seems a bit strange.
编辑:您可以考虑重写您的 proc fcmp
函数期望值列表作为字符串(例如'3.5,5,7.5'
)而不是数组,并执行完全删除数组。
you could consider rewriting your proc fcmp
function to expect the list of values as a character string (e.g. '3.5,5,7.5'
) instead of an array and do away with arrays entirely.
您的 proc fcmp
可能会与
do i=1 to dim(array);
val=array{i};
...
end;
类似;
do i=1 to countw(array,',');
val=input(scan(array,i,','),best32.);
...
end;
这篇关于在SAS中重置临时阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!