我一直试图使用数组执行sas代码。奇怪的是,它并没有像我预期的那样工作。所以我使用了另一种方法,第二种方法可以很好地运行代码。但我还是想知道第一种方法是错误的。以下是我的代码:
data have;
input free_m prevention substitution oth;
datalines;
. . . .
. 0 0 0
1 1 0 0
;
run;
data test;
set have;
/*method1*/
array a1(*) prevention substitution oth;
do i=1 to dim(a1);
if free_m=. and prevention=0 and substitution=0 and oth=0 then a1(i)=.;
end;
/*method2*/
/*
if free_m=. and prevention=0 and substitution=0 and oth=0 then
do;
prevention=.;
substitution=.;
oth=.;
end;
*/
drop i;
run;
proc sql;
select * from test;
quit;使用/方法2/的结果是正确的,这正是我想要的:

但是,通过使用/method1 1/,我得到了以下输出:

method1有什么问题吗?帮帮忙!非常感谢。
发布于 2019-02-21 20:49:07
你正在切断你所坐的肢体。
第一种方法对于I=1和I=2很好,但是当您到达I=3和I=4时,prevention的值已经从0更改为do循环的早期迭代所缺少的值。prevention和a1(2)指的是同一件事。
https://stackoverflow.com/questions/54815772
复制相似问题