微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

根据就诊次数选择疾病的发病日期

如何解决根据就诊次数选择疾病的发病日期

我有因感染就诊的数据。个人可以有 1+ 次访问。如果一个人在一年内就诊超过一次,临床医生就会认为他被感染了。那么,第一次就诊的日期被认为是感染发作。

例如,ids 123 具有以下访问:

Data have;
INPUT row ID date;
CARDS;
1 1 2017-03-22
2 1 2017-04-26
3 1 2018-02-20
4 1 2018-04-07
5 1 2018-04-16
6 2 2014-01-15
7 2 2014-06-23
8 2 2014-07-23
9 2 2015-01-14
10 3 2018-01-22
11 3 2019-05-03
;
run;

根据感染的临床定义,我想要这些日期:

ID 日期
1 1 2017-03-22
4 1 2018-04-07
6 2 2014-01-15

选择ID=1的第一个日期是因为一年内有2次以上的访问。跳过第一次访问后和第一次访问后一年内的所有访问(第 2 行和第 3 行)。第二个日期是第4行,与第一次访问相隔一年多,之后一年内再次访问。

对于 ID=2,我们只选择第一个日期并跳过一年内的所有下一次访问。

对于 ID=3,我们不选择任何日期,因为一年内访问次数不超过一次。

解决方法

尝试以下方法,当您处理实际的完整数据时,您可能需要稍作调整。

  Data have;
  INPUT row:4. ID:4. date yymmdd10.;
  year=year(date);
  format date yymmdd10.;
  CARDS;
  1 1 2017-03-22
  2 1 2017-04-26
  3 1 2018-02-20
  4 1 2018-04-07
  5 1 2018-04-16
  6 2 2014-01-15
  7 2 2014-06-23
  8 2 2014-07-23
  9 2 2015-01-14
  10 3 2018-01-22
  11 3 2019-05-03
  ;
  run;
  
  /*keep the first date per id*/
  data first_visit;
   set have;
    by id;
    if first.id;
  run;
  
  /*find the year difference for each subsequent date with first date*/
  proc sql;
  create table visits1
  as
  select a.*,int(abs(yrdif(b.date,a.date,'ACT/365'))) as date_diff_first
  from have a
  inner join first_visit b
  on a.id=b.id;
  quit;
  
  /*part1 - find the first symptom onset date where we have multiple visits per year*/
  proc sql;
  create table part1_0
  as
  select distinct a.*
  from visits1 a
  inner join visits1 b
  on a.id=b.id
  and a.date<b.date
  and a.row+1=b.row
  and a.year=b.year
  and a.date_diff_first=0 and b.date_diff_first=0;
  quit;
  
  data part1;
   set part1_0;
   by id;
   if first.id;
  run;
  
  /*part2 - Now find other symptom onset date for same id in another year 1 year apart*/
  proc sql;
  create table part2_0
  as
  select distinct a.row,a.id,a.date
  from visits1 a
  inner join part1 b
  on a.id=b.id
  inner join visits1 c
  on a.id=c.id
  and a.date>b.date
  and a.year<>b.year
  and a.date_diff_first=1 and b.date_diff_first=0
  and a.row+1=c.row;
  quit;
  
  data part2;
   set part2_0;
   by id;
   if first.id;
  run;
  
  /*combine both*/
  data final;
   set part1 part2;
   keep row id date;
  run;
  
  proc sort data=final; by row id date; run;
        

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。