SAS:我如何测试一个值的稳定性

SAS: How can I test the stability of a value among time

我有这个数据库:

data temp;
input ID monitoring_date score ;
  datalines;
 1 10/11/2006   0      
 1 10/12/2006   0      
 1 15/01/2007   1      
 1 20/01/2007   1
 1 20/04/2007   1

 2 10/08/2008   0        
 2 11/09/2008   0        
 2 17/10/2008   1        
 2 12/11/2008   0 

 3 10/12/2008   0 
 3 10/08/2008   0        
 3 11/09/2008   0        
 3 17/10/2009   1        
 3 12/12/2009   1    
 3 05/01/2010   0  

 4 10/12/2006   0 
 4 10/08/2006   0        
 4 11/09/2006   0        
 4 17/10/2007   0        
 4 12/12/2007   0    
 4 09/04/2008   1  
 4 05/08/2008   1

 5 10/12/2013   0 
 5 03/09/2013   0        
 5 11/09/2013   0        
 5 19/10/2014   0        
 5 10/12/2014   1    
 5 14/01/2015   1  

 6 10/12/2017   0 
 6 10/08/2018   0        
 6 11/09/2018   0        
 6 17/10/2018   1        
 6 12/12/2018   1    
 6 09/04/2019   1  
 6 25/07/2019   0
 6 05/08/2019   1
 6 15/09/2019   0
 ;

我想创建一个新数据库,其中包含一个新列,我在其中记录每个 ID 分数从 0 到 1 的第一次进展的日期,如果此进展至少稳定 3 个月,直到监控结束 else date_progresion = . :

data want;
input ID   date_progression;
  datalines;
 1            15/01/2007
 2            .
 3            .
 4            09/04/2008
 5            .
 6            .
 ;

我真的不知道要对此进行编码,我想获得所需的数据来生成一个 cox 模型,其中进展 (Yes/No) 是我的事件。 我真的卡住了!

提前感谢您的帮助!

一个 DOW 循环可以处理 ID 个组,跟踪 1s 的单个活动 运行。 运行 有开始日期和持续时间。

示例:

data want;
  do _n_ = 1 by 1 until (last.id);
    set have;
    by id;

    select;
      when (pscore = 0 and score = 1) do; state = 1; start = date; dur = 1; end;
      when (pscore = 1 and score = 1) do; state = 2;               dur + 1; end;
      when (pscore = 1 and score = 0) do; state = 3; start = .;    dur = .; end;
      when (pscore = 0 and score = 0) do; state = 4;                        end;
      otherwise;
    end;

    pscore = score;
  end;

  if state = 2 and dur >= 3 then progression_date = start;

  keep ID progression_date;
  format progression_date yymmdd10.;
run;