楼主: fdyn317
14057 10

[原创博文] 求教: sas数据集中的缺失值处理问题 [推广有奖]

  • 0关注
  • 0粉丝

已卖:36份资源

初中生

19%

还不是VIP/贵宾

-

威望
0
论坛币
743 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
140 点
帖子
15
精华
0
在线时间
4 小时
注册时间
2006-3-31
最后登录
2016-4-16

楼主
fdyn317 发表于 2006-4-2 17:25:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
<P>从数据库导出的数据,有时候某些观测值因没有数据在excel中就是空白,导入sas后在运算时就无法计算。请问,如何把这些缺失值统一变为0?</P>
二维码

扫码加我 拉你入群

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

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

关键词:sas数据集 缺失值处理 数据集 缺失值 EXCEL excel 数据库 如何

回帖推荐

windwater 发表于6楼  查看完整内容

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

zzheng722 发表于7楼  查看完整内容

类似的情况还很多.进行数据步转换的好处在于可以预先根据你的分析目的将数据集整理好? Yes, I agree. 但是将数据集整理好时,不能加入个人的assumption,如果x 是顾客满意度得分1-5分, 你将missing value 转换成0就不好,因为你的assumption是所有没填调查表的顾客的满意度是0?其它的办法是将missing value 转换所有nonmissing value 的平均数(mean), 中位数(median), 或着复杂方法得出的替代。 大部分软件default是简 ...

zzheng722 发表于5楼  查看完整内容

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; ...

ltjzzyz 发表于3楼  查看完整内容

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

windwater 发表于2楼  查看完整内容

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编辑过]

本帖被以下文库推荐

沙发
windwater 发表于 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编辑过]

已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 10 热心帮助其他会员

总评分: 经验 + 5  论坛币 + 10   查看全部评分

藤椅
ltjzzyz 发表于 2007-4-11 08:07:00
如果你用累加方法计算,缺失值是自动转为0的。在proc summary等过程中,如果用class分组计算的话,缺失值自动会被剔除出分析过程,除非使用了missing选项。
已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 10 热心帮助其他会员

总评分: 经验 + 5  论坛币 + 10   查看全部评分

板凳
sudoroot 发表于 2007-4-11 19:42:00
可以用where语句处理吧?
化作尘与土!留着要珍惜,抛弃会后悔。

报纸
zzheng722 发表于 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编辑过]

已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 10 热心帮助其他会员

总评分: 经验 + 5  论坛币 + 10   查看全部评分

地板
windwater 发表于 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;

已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 10 热心帮助其他会员

总评分: 经验 + 5  论坛币 + 10   查看全部评分

7
zzheng722 发表于 2007-4-12 22:06:00

类似的情况还很多.进行数据步转换的好处在于可以预先根据你的分析目的将数据集整理好? Yes, I agree.

但是将数据集整理好时,不能加入个人的assumption,如果x 是顾客满意度得分1-5分, 你将missing value 转换成0就不好,因为你的assumption是所有没填调查表的顾客的满意度是0?
其它的办法是将missing value 转换所有nonmissing value 的平均数(mean), 中位数(median), 或着复杂方法得出的替代。

大部分软件default是简单的delete掉missing values,就是基于尊重你的原始数据,不带任何assumption的原则。 如果你需要换成别的数值,只好自己写code了。

已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 10 热心帮助其他会员

总评分: 经验 + 5  论坛币 + 10   查看全部评分

8
潮雅 发表于 2007-7-3 16:48:00
高手~

9
takotako 发表于 2007-7-9 23:50:00
其实都是看情况而定,一般而言,如果那些缺失值的重要性很大,就应该用decision tree去估计那些缺失值,才做分析的

10
踏破铁鞋 发表于 2010-1-28 15:23:26
谢谢! 9# takotako

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 13:48