楼主: dxystata
1105 5

如何得到么个体x取值为3和4的次数 [推广有奖]

版主

已卖:302份资源

大师

37%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

威望
2
论坛币
183395 个
通用积分
15333.1475
学术水平
208 点
热心指数
271 点
信用等级
174 点
经验
298627 点
帖子
5586
精华
1
在线时间
13632 小时
注册时间
2006-6-21
最后登录
2025-12-22

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

楼主
dxystata 发表于 2016-11-23 21:09:05 |AI写论文
20论坛币
  1. data aaa;
  2. input id trt x;
  3. cards;
  4. 1 1 0
  5. 1 1 1
  6. 1 1 .
  7. 1 1 2
  8. 1 1 3
  9. 2 1 0
  10. 2 1 2
  11. 2 1 3
  12. 2 1 4
  13. 2 1 .
  14. 3 2 0
  15. 3 2 3
  16. 3 2 3
  17. 3 2 4
  18. 3 2 4
  19. 4 2 0
  20. 4 2 .
  21. 4 2 .
  22. 4 2 3
  23. 4 2 .
  24. ;
  25. run;
复制代码
id为个体 trt为组别
希望得到的数据集为
id trt x1
1  1  1
2  1  2
3  2  4
4  2  1


关键词:cards Input card Data RDS 如何

沙发
zhangzachary 发表于 2016-11-23 21:09:06
  1. proc sql;
  2.         create table want as
  3.         select id, sum(case when x in (3,4) then 1 else 0 end) as tag
  4.         from aaa
  5.         group by 1;
  6. quit;
复制代码

藤椅
dxystata 发表于 2016-11-23 21:36:15
proc sql noprint;
        create table tmp2 as
        select distinct id,trt,count(x) as x2
        from aaa
        where x in (3 4)
        group by id;
quit;

板凳
dxystata 发表于 2016-11-23 21:45:33
  1. data aaa;
  2. input id trt x;
  3. cards;
  4. 1 1 0
  5. 1 1 1
  6. 1 1 .
  7. 1 1 2
  8. 1 1 2
  9. 2 1 0
  10. 2 1 2
  11. 2 1 3
  12. 2 1 4
  13. 2 1 .
  14. 3 2 0
  15. 3 2 3
  16. 3 2 3
  17. 3 2 4
  18. 3 2 4
  19. 4 2 0
  20. 4 2 .
  21. 4 2 .
  22. 4 2 3
  23. 4 2 .
  24. ;
  25. run;
复制代码

如果数据是这样,id=1 应为0 ,未输出。

报纸
dxystata 发表于 2016-11-23 21:53:12
继续求助

地板
dxystata 发表于 2016-11-23 22:58:55
  1. proc sql noprint;
  2.         create table bbb as
  3.         select distinct id,trt,count(case when x in (3 4) then id else . end) as tag
  4.         from aaa
  5.         group by id;
  6. quit;
复制代码

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

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