楼主: qwqwqw
5746 20

[原创博文] 一个比较集合大小的问题 [推广有奖]

  • 1关注
  • 1粉丝

不知居士

已卖:19份资源

讲师

72%

还不是VIP/贵宾

-

威望
0
论坛币
98533 个
通用积分
7.3500
学术水平
5 点
热心指数
14 点
信用等级
3 点
经验
9920 点
帖子
323
精华
0
在线时间
842 小时
注册时间
2005-2-14
最后登录
2024-6-22

楼主
qwqwqw 发表于 2011-1-13 04:21:51 |AI写论文
100论坛币
比如说数据如下
1 A B C D E
2 A B R
3 B G
4 B C D
5 C E
我是想删除第4,5行,因为第1行已经有了这样的组合了;但是要保留2,3行,因为他们有其他行没有的值
我现在想出来的方法就是把所有可能的值写成变量,再用类似tag的方法,ie
   A B C D E F G ... R
1 1  1 1  1 1
2 1  1                      1
3     1              1
4     1 1 1
5        1    1
多谢多谢

最佳答案

关键词:tag

回帖推荐

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

抛个砖

本帖被以下文库推荐

沙发
soporaeternus 发表于 2011-1-13 04:21:52
  1. data source;
  2.         input str:$20.;
  3.         datalines;
  4.         ABCDE
  5.         ABR
  6.         BG
  7.         BCD
  8.         CE
  9.         BR
  10.         DR
  11.         EFGR
  12.         ER
  13.         CD
  14.         AK
  15.         ;
  16. run;

  17. data t1;
  18.         set source;
  19.         id+1;
  20.         do i=1 to length(str) by 1;
  21.                 kw=substr(str,i,1);
  22.                 output;
  23.         end;
  24.         drop i;
  25. run;

  26. proc sql;
  27.         create table R(drop=id) as
  28.         select
  29.                 id
  30.                 ,str
  31.         from (
  32.                 select
  33.                         a.id
  34.                         ,a.str
  35.                         ,b.id as id1
  36.                         ,sum(case when missing(b.kw) then 0 else 1 end) as sum
  37.                         ,length(a.str) as len
  38.                 from t1 a
  39.                 left join t1 b
  40.                 on a.kw=b.kw
  41.                 and a.id>b.id
  42.                 group by
  43.                         a.id
  44.                         ,a.str
  45.                         ,b.id
  46.                 ) c
  47.                 group by id,str
  48.                 having sum(case when sum=len then 1 else 0 end)=0
  49.         ;
  50. quit;
复制代码
抛个砖
已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
论坛数据分析 + 100 + 2 观点有启发
hopewell + 1 + 1 + 1 我很赞同

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

Let them be hard, but never unjust

藤椅
junuylia 发表于 2011-1-13 05:22:54
You just need to keep the combination, or just the letters? Since you don't have the combination C E in the first row.

板凳
qwqwqw 发表于 2011-1-13 08:56:10
2# junuylia

thanks! i need to keep entire row, whichever is not contained by any other rows, like raw 4 and raw 5. but i will delete the raw 2 and raw 3, since raw 1 contains them.

报纸
junuylia 发表于 2011-1-13 09:03:53
能不能详细解释一下?第1行没有包含第2、3行的整个内容啊。另外第4行删除我可以理解,但第1行并没有包含第5行为什么也要删除?只因为C和E在第一行出现过吗?

地板
论坛数据分析 发表于 2011-1-13 09:04:02
这个问题很有意思,期待好的答案
老夫聊发少年狂

7
qwqwqw 发表于 2011-1-13 09:20:54
4# junuylia

不好意思,数数错了,应该是保留2,3行,删除4,5行

8
soporaeternus 发表于 2011-1-13 09:26:00
如果第6行为BR是删除还是保留
即后面行的元素是否可以添加至你的匹配集合
还是匹配集合永远以第一行为准
Let them be hard, but never unjust

9
qwqwqw 发表于 2011-1-13 09:34:39
7# soporaeternus

多谢多谢,第6行是BR就删除,如果是DR就保留,按有没有包含关系为准

10
hopewell 发表于 2011-1-13 11:03:15
  1. data raw;
  2.     infile datalines missover;
  3.     input id (var1-var5) ($);
  4. datalines;
  5. 3 B G
  6. 4 B C D
  7. 1 A B C D E
  8. 2 A B R
  9. 5 C E
  10. ;
  11. data temp(keep=h_id h_text);
  12.     length h_text $10;
  13.     set raw;
  14.     rename id=h_id;
  15.     h_text=cats(of var1-var5);
  16. run;
  17. data _null_;
  18.     length h_text $10;
  19.     if _n_=1 then do;
  20.         declare hash h(hashexp:8,dataset:'temp',ordered:'yes');
  21.         declare hiter hi('h');
  22.         h.definekey('h_id');
  23.         h.definedata('h_id','h_text');
  24.         h.definedone();
  25.         call missing(h_id,h_text);
  26.     end;
  27.     set raw end=last;
  28.     array arr(i) var1-var5;
  29.     do while(hi.next()=0);
  30.         if id ne h_id then do;
  31.             if flag ne 0 then rc=h.remove(key:del_id);
  32.             do over arr;  
  33.                 if not missing(arr) then do;
  34.                     flag=min(flag,findc(h_text,arr,'it'));
  35.                     del_id=id;
  36.                 end;
  37.                 else leave;
  38.             end;
  39.         end;
  40.     end;
  41.     if last then rc=h.output(dataset:'out');
  42. run;
复制代码
已有 1 人评分论坛币 学术水平 收起 理由
论坛数据分析 + 100 + 2 精彩帖子

总评分: 论坛币 + 100  学术水平 + 2   查看全部评分

观钓颇逾垂钓趣 种花何问看花谁

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

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