楼主: chenwen1129
1178 4

[学科前沿] 关于数据归类的一个难题 [推广有奖]

  • 0关注
  • 0粉丝

初中生

95%

还不是VIP/贵宾

-

威望
0
论坛币
2 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
205 点
帖子
15
精华
0
在线时间
17 小时
注册时间
2009-2-28
最后登录
2021-7-17

楼主
chenwen1129 发表于 2011-4-15 00:33:09 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
现有一问题急需解决,n个观测值是一组(在此以n=10为例,实际可能上百),每个观测值对应一个code,理论上同一组的code应该是相同的,但实际数据中每组均有部分观测值的code与其他值不一致。怎样才能将这些code错误的观测值与其他观测值纳入同一组?
数据格式示意如下:
obs   code
1       1000     
2       1000
3       1000
4       1020
5       1000
6       1000
7       1110
8       1000
9       1000
10     1000
11     1001
12     1001
13     1001
14     1023
15     1001
16     1001
17     1001
18     1024
19     1222
20     1001   
;
如第一组的obs4和obs7的code发生了错误,第二组的obs14、obs18、obs19发生了错误,若按code值对数据进行分组,obs4和obs7就不能分到第一组,obs14、obs18、obs19不能分到第二组。但我需要将其分别纳入第一、二组,求高人指点,应该怎么办?
二维码

扫码加我 拉你入群

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

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

关键词:求高人指点 code 急需解决 实际数据 高人指点

回帖推荐

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

Here is a solution. Hope it helps. Note: 1. If sample size are the same for each of the group, just replace the number in n= 2. If sample size varies, then there must be some flag indicating the group number, you can skip the part of "Define Group Indicator" 3. The program assumes the correct code value appears most so it is the "Mode" of each group %let n=10; data ds; input obs cod ...

本帖被以下文库推荐

沙发
chenwen1129 发表于 2011-4-15 01:17:09
忘记说明了一点问题,实际数据中每组的样本量是不同的,并不都是10例。由于实际数据太庞大,故无法进行详细展示。去高手支招啊!

藤椅
kunkunred 发表于 2011-4-15 05:38:52
Here is a solution. Hope it helps.

Note:
1. If sample size are the same for each of the group, just replace the number in n=
2. If sample size varies, then there must be some flag indicating the group number, you can skip the part of "Define Group Indicator"
3. The program assumes the correct code value appears most so it is the "Mode" of each group

%let n=10;
data ds;
input obs   code ;
cards;
1      1000
2      1000
3      1000
4      1020
5      1000
6      1000
7      1110
8      1000
9      1000
10     1000
11     1001
12     1001
13     1001
14     1023
15     1001
16     1001
17     1001
18     1024
19     1222
20     1001
;
run;
/* Define Group Indicator*/
data ds;
set ds;
grp=floor((obs-1)/&n)+1;
run;
/* End Define Group Indicator*/

proc means data=ds mode noprint;
by grp;
output out=dsmode(keep=grp code rename=(code=mode)) mode=;
run;

data ds3;
merge ds dsmode;
by grp;
run;

data ds4;
set ds3;
Error=(code ne mode);
code_correct=mode;
run;
已有 2 人评分经验 论坛币 热心指数 收起 理由
胖胖小龟宝 + 10 + 10 热心帮助其他会员
crackman + 1 鼓励积极发帖讨论

总评分: 经验 + 10  论坛币 + 10  热心指数 + 1   查看全部评分

板凳
soporaeternus 发表于 2011-4-15 09:12:28
多组之后一个异常的code与之前某组的code相同,是该code异常还是之间所有code异常?
Let them be hard, but never unjust

报纸
chenwen1129 发表于 2011-4-15 10:06:51
回复soporaeternus 的问题,实际数据中每组异常的code仅出现一次,不存在“多组之后一个异常的code与之前某组的code相同”的情况。如果有,根据我的目的,也只是算这一个code异常。

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-2-2 10:52