楼主: Imasasor
4509 26

如何找重复的id号 [推广有奖]

  • 1关注
  • 64粉丝

VIP

已卖:215份资源

学科带头人

33%

还不是VIP/贵宾

-

TA的文库  其他...

超哥喜欢的文章

威望
1
论坛币
47033 个
通用积分
3.1376
学术水平
238 点
热心指数
246 点
信用等级
231 点
经验
37132 点
帖子
849
精华
3
在线时间
2235 小时
注册时间
2012-7-4
最后登录
2024-10-10

初级学术勋章 初级热心勋章 初级信用勋章 中级热心勋章 中级学术勋章

楼主
Imasasor 发表于 2013-10-29 11:00:58 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
data tem;
input id1 id2;
cards;
1 2
2 1
4 7
5 8
6 9
8 5
;

要求结果是
1 2
4 7
5 86 9

也就是说:
如果id1的号码在id2的某个观测存在的话,就把对应的id2的那条观测删掉,只保留当前观测,如果id1的号码在id2中不存在的话,就保留下来
比如id1=1的号码,在第二条观测id2也等于1,就把第二条观测删掉,只保留第一条观测

悬赏100论坛币



二维码

扫码加我 拉你入群

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

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

关键词:100论坛币 悬赏100 Input cards Data 如何

本帖被以下文库推荐

欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

沙发
yongyitian 发表于 2013-10-29 12:28:42
  1. /* the code works for the given data, not try for other data */

  2. data tem;
  3. input id1 id2;
  4. cards;
  5. 1 2
  6. 2 1
  7. 4 7
  8. 5 8
  9. 6 9
  10. 8 5
  11. ; run;
  12. proc print data=tem; title 'tem'; run;

  13. data repeated_id;
  14.      set tem (rename=(id2=id3));
  15.        n = _n_;
  16.      do i = n+1 to nobs;
  17.        set tem nobs=nobs point=i;
  18.         if id1 = id3 then output;
  19.      end;
  20.     keep id1 id2;
  21. run;

  22. proc sql;
  23.   create table want as
  24.       select *
  25.       from tem
  26.       except select * from repeated_id;
  27. quit;
  28. proc print data=want; title 'want'; run;
复制代码
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 100 + 100 + 5 + 5 + 5 精彩帖子,非常感谢

总评分: 经验 + 100  论坛币 + 100  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

藤椅
邓贵大 发表于 2013-10-29 12:43:42
Come on, your rule is incomplete. How do you break cycles, for example, delete which one from (a,b), (b,c), (c,a)?
Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

板凳
yongyitian 发表于 2013-10-29 12:47:48
邓贵大 发表于 2013-10-29 12:43
Come on, your rule is incomplete. How do you break cycles, for example, delete which one from (a,b), ...
sorry, missing a THEN after id1=id3.
It was add.

报纸
pobel 在职认证  发表于 2013-10-29 12:49:40
data wanted(keep=id1 id2);
   set tem;
   length _id1 $100;
   retain _id1 ;
   if index(_id1,quote(cats(id2))) then flag=0;
   else do;
        flag=1;
        _id1=catx(",",_id1,quote(cats(id1)));
        end;
        if flag;
run;
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 100 + 100 + 5 + 5 + 5 观点有启发,看来只有版主的贴子pobel大神才.

总评分: 经验 + 100  论坛币 + 100  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

和谐拯救危机

地板
oneoneagain 发表于 2013-10-29 13:30:59
好厉害!

7
可~乐 发表于 2013-10-29 14:03:53
  1. data tem;
  2. input id1 id2;
  3. cards;
  4. 1 2
  5. 2 1
  6. 4 7
  7. 5 8
  8. 6 9
  9. 8 5
  10. ;

  11. proc sql noprint;
  12.         select id1 into :id1 separated by "" from tem;
  13. quit;

  14. %put &id1.;

  15. data test;
  16.         set tem;;
  17.         if index("&id1.",scan(compress(put(id2,best12.)),1))>_n_ or index("&id1.",scan(compress(put(id2,best12.)),1))=0;
  18.         keep id1 id2;
  19. run;
复制代码
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 100 + 100 + 2 + 1 + 4 分析的有道理,蝈蝈come back

总评分: 经验 + 100  论坛币 + 100  学术水平 + 2  热心指数 + 1  信用等级 + 4   查看全部评分

8
Imasasor 发表于 2013-10-29 16:01:09
yongyitian 发表于 2013-10-29 12:28
哥们data 步的应用太娴熟了,你学多久SAS了
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

9
Imasasor 发表于 2013-10-29 16:09:26
yongyitian 发表于 2013-10-29 12:28
请问两个set是几个指针,几个pdv
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

10
邓贵大 发表于 2013-10-29 22:12:14
yongyitian 发表于 2013-10-29 12:47
sorry, missing a THEN after id1=id3.
It was add.
No, your code is OK.
I was just saying the solution may not be unique based on Imasasor's description. The solution you get will depend on the order of data.
For example, your code returns (1,2) when the order is
  1. 1 2
  2. 2 3
  3. 3 1
复制代码
but it yields (1,2), (2,3) if the order is
  1. 2 3
  2. 1 2
  3. 3 1
复制代码
Another example, given a path like (1,2), (2,3), (3,4). If you delete (2,3) first, you'll end up with two records; or if you erase (3,4) first, you'll still get a chance to delete (2,3) and return only 1 record. Both solutions are correct but they are different.
I'm just not sure in which order one should break a loop, a cycle, or a path.
Imasasor has to define a complete set of rules for others to work on a program.
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
webgu + 80 + 80 + 3 + 3 + 3 NICE QUESTION

总评分: 经验 + 80  论坛币 + 80  学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

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

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