楼主: dxystata
1175 2

统计每个个体出现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-27 22:56:02 |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 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为个体 trt为组别
希望得到的数据集为
id trt x1
1  1  0
2  1  2
3  2  4
4  2  1
谢谢!

关键词:cards Input card Data RDS 统计

沙发
cwzkevin 发表于 2016-11-28 04:52:02
  1. proc sort data=aaa; by id; run;
  2. data x1; set aaa;
  3. by id;
  4. retain x1;
  5. if first.id then x1=0;
  6. if x in (3,4) then x1=x1+1;
  7. if last.id then output;
  8. drop x;
  9. run;
复制代码
已有 1 人评分经验 收起 理由
李会超 + 80 精彩帖子

总评分: 经验 + 80   查看全部评分

藤椅
wwang111 发表于 2016-11-29 11:27:54
proc sql;
create table wanted as
select id, trt, sum(x=3 or x=4) as x1
from aaa
group by 1,2;
quit;

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

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