首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用数组处理我的sas代码。结果不像预期的那样

使用数组处理我的sas代码。结果不像预期的那样
EN

Stack Overflow用户
提问于 2019-02-21 20:34:32
回答 1查看 31关注 0票数 0

我一直试图使用数组执行sas代码。奇怪的是,它并没有像我预期的那样工作。所以我使用了另一种方法,第二种方法可以很好地运行代码。但我还是想知道第一种方法是错误的。以下是我的代码:

代码语言:javascript
复制
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有什么问题吗?帮帮忙!非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-21 20:49:07

你正在切断你所坐的肢体。

第一种方法对于I=1和I=2很好,但是当您到达I=3和I=4时,prevention的值已经从0更改为do循环的早期迭代所缺少的值。preventiona1(2)指的是同一件事。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54815772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档