全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
13961 10
2006-04-02
<P>从数据库导出的数据,有时候某些观测值因没有数据在excel中就是空白,导入sas后在运算时就无法计算。请问,如何把这些缺失值统一变为0?</P>
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2007-4-10 15:52:00

data test;
input a b c ;
cards;
1 2 3
1 . 3
. 2 3
;
run;
data test1;
set test;
array arr1 _numeric_;
do over arr1;
if arr1=. then arr1=0;end;
run;

data test2(drop=i);
set test;
array arr2 _numeric_;
do i=1 to dim(arr2);
if arr2(i)=. then arr2(i)=0;end;
run;

[此贴子已经被作者于2007-4-10 15:52:29编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-4-11 08:07:00
如果你用累加方法计算,缺失值是自动转为0的。在proc summary等过程中,如果用class分组计算的话,缺失值自动会被剔除出分析过程,除非使用了missing选项。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-4-11 19:42:00
可以用where语句处理吧?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-4-11 22:31:00

Proc means automatically uses nonmissing values in x1 to calculate mean of x1, or sum of x1, you don't need to use where statement.

proc means data=yourdata n mean sum;

var x1 x2;

run;

If you use the following 'where' statement, it is the same as above (SAS default!):

proc means;

var x1 x2;

where x1 ne . or x2 ne .;

run;

But If you use 'And' in where statement:

proc means;

var x1 x2;

where x1 ne . and x2 ne . ;

run;

The data you are using to do proc means will be limited to the only records having both x1 and x2 nonmissing values, say you are missing 5 records in x1 and 100 records in x2, 95 to 100 extra records for x1 will be deleted due to x2 is missing. The means of x1, x2 will be different than previous results.

In general, I am agree with windwater's method by using array in datastep. But if you only need to calculate mean or sum of x1, x2, you don't need to replace the missing values. Sometimes if you replaced a lot of missing values by 0, you pushed your data towards 0.

[此贴子已经被作者于2007-4-11 22:52:47编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-4-12 08:53:00

不同的目的还是有不同的处理方法.比如说观测了三次想看一个平均值.如果不把"."转为0,最后的分母就会是2而不是3.类似的情况还很多.进行数据步转换的好处在于可以预先根据你的分析目的将数据集整理好.

data a;
input x;
cards;
1
.
2
;
proc means data=a;run;
data b;
input y;
cards;
1
0
2
;
proc means data=b;run;

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群