楼主: henryyhl
2760 3

[问答] 如何计算随访记录中每个人每种药的使用时间? [推广有奖]

  • 67关注
  • 5粉丝

已卖:2份资源

副教授

56%

还不是VIP/贵宾

-

威望
0
论坛币
26 个
通用积分
17.7240
学术水平
18 点
热心指数
17 点
信用等级
11 点
经验
47974 点
帖子
504
精华
0
在线时间
1102 小时
注册时间
2011-11-4
最后登录
2025-6-21

楼主
henryyhl 发表于 2013-8-19 15:07:04 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
有这样一个类似的数据集,id代表患者编号,n代表随访次数,treat是用药方案,v_date 是随访日期。
怎么统计每个人用每种方案的分别的使用时间呢?
比如第一个人用a方案的时间应该为第3次减去第1次的时间,即(2012-5-3) -(2012-1-1)谢谢!
three是原始数据集。
data three;
input id n treat$ v_date : yymmdd10.;
format v_date yymmdd10.;
cards;
1        1        a        2012-1-1
1        2        a        2012-3-1
1        3        c        2012-5-3
1        4        c        2012-7-28
1        5        a        2012-10-1
1        6        a        2013-1-3
2        1        a        2009-3-9
2        2        a        2009-7-3
2        3        c        2009-12-1
2        4        a        2010-2-3
2        5        c        2010-5-4
2        6        c        2010-8-26
2        7        c        2010-12-3

;
run;
想得到每个人的这些观测

1

1

a

2012-1-1

1

3

c

2012-5-3

1

5

a

2012-10-1

1

6

a

2013-1-3

2

1

a

2009-3-9

2

3

c

2009-12-1

2

4

a

2010-2-3

2

5

c

2010-5-4

2

7

c

2010-12-3

或者更好的就是产生新变量,每个人只有一条记录,如:
idntreatv_datetreat_1v_date_1treat_2v_date_2treat_3v_date_3treat_4v_date_4treat_5v_date_5treat_6v_date_6

1

1

a

2012-1-1

a

2012-1-1

c

2012-5-3

a

2012-10-1

a

2013-1-3

2

1

a

2009-3-9

a2009-3-9c

2009-12-1

a

2010-2-3

c

2010-5-4

c

2010-12-3


非常感谢!


二维码

扫码加我 拉你入群

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

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

关键词:使用时间 format treat Three Input treat 记录 如何 统计

It's not going to be easy, but it is going to be worth it.

沙发
henryyhl 发表于 2013-8-20 11:10:21
有人能帮忙看看吗?是说的不够清楚吗?就是想算随访中的暴露的时间。
谢谢各位啊!
It's not going to be easy, but it is going to be worth it.

藤椅
yongyitian 发表于 2013-8-20 11:15:31
  1. data three;
  2. input id n treat $ v_date : yymmdd10.;
  3. format v_date yymmdd10.;
  4. cards;
  5. 1        1        a        2012-1-1
  6. 1        2        a        2012-3-1
  7. 1        3        c        2012-5-3
  8. 1        4        c        2012-7-28
  9. 1        5        a        2012-10-1
  10. 1        6        a        2013-1-3
  11. 2        1        a        2009-3-9
  12. 2        2        a        2009-7-3
  13. 2        3        c        2009-12-1
  14. 2        4        a        2010-2-3
  15. 2        5        c        2010-5-4
  16. 2        6        c        2010-8-26
  17. 2        7        c        2010-12-3
  18. ;run;

  19. proc sort data=three out=three_sort;
  20.     by id n treat;
  21. run;

  22. data three_a;
  23.     set three_sort;
  24.        by id;
  25.        retain tg;
  26.        treat_lag = lag(treat);
  27.        if first.id then tg=0;  
  28.        if treat ^=treat_lag then tg+1;
  29.    drop treat_lag;
  30. run;

  31. data three_b;
  32.     set three_a;
  33.        by id tg;
  34.        if first.tg or last.id;
  35.    drop tg;
  36. run;
  37. proc print data=three_b; title 'three_b'; run;
复制代码
results_1.PNG
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
henryyhl + 1 + 1 + 1 热心帮助其他会员

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

板凳
henryyhl 发表于 2013-8-20 11:25:05
yongyitian 发表于 2013-8-20 11:15
非常感谢楼上。
It's not going to be easy, but it is going to be worth it.

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-4 12:30