- 阅读权限
- 255
- 威望
- 2 级
- 论坛币
- 14705 个
- 通用积分
- 1865.9937
- 学术水平
- 932 点
- 热心指数
- 930 点
- 信用等级
- 730 点
- 经验
- 113854 点
- 帖子
- 1287
- 精华
- 4
- 在线时间
- 3654 小时
- 注册时间
- 2008-12-10
- 最后登录
- 2025-11-1
|
沙发
pobel
发表于 2011-7-13 22:51:40
有点繁琐,不知是不是你想要的结果。 - data test;
- input ID $ A $ B $;
- odr=_n_;
- cards;
- 1001 a1 b1
- 1001 a1 b2
- 1001 a1 b1
- 1001 a1 b2
- 1002 a1 b1
- 1003 a1 b3
- 1004 a2 b3
- 1004 a2 b4
- 1004 a3 b3
- 1004 a3 b4
- ;
- proc sql;
- create table test1 as
- select x.a,x.b,x1
- ,(x_a-x1) as x2
- ,(x_b-x1) as x3
- ,(N-x_a-x_b+x1) as x4
- ,N
- from
- (select distinct a,b,count(distinct id) as N from test) as w
- left join
- (select distinct a,b,count(distinct id) as x_a from test group by a) as x
- on w.a=x.a and w.b=x.b
- left join
- (select distinct a,b,count(distinct id) as x_b from test group by b) as y
- on w.a=y.a and w.b=y.b
- left join
- (select distinct a,b,count(distinct id) as x1 from test group by a,b) as z
- on w.a=z.a and w.b=z.b;
- quit;
- proc sql;
- create table wanted as
- select l.id, l.a,l.b,x1,x2,x3,x4,n
- from test as l
- left join test1 as r
- on l.a=r.a and l.b=r.b
- order by odr;
- quit;
复制代码
|
-
总评分: 经验 + 100
论坛币 + 60
学术水平 + 1
热心指数 + 2
查看全部评分
|