SAS-连续工作几个月?

SAS-连续工作几个月?,sas,datastep,Sas,Datastep,从下面的示例数据中,我试图识别至少连续3个月出现状态_日期的账户(按ID和SEQ)。这件事我已经搞了一段时间了,我根本不知道该怎么处理 样本数据: ID SEQ STATUS_DATE 11111 1 01/01/2014 11111 1 02/10/2014 11111 1 03/15/2014 11111 1 05/01/2014 11111 2 01/30/2014 22222 1 06/20/2014 22222

从下面的示例数据中,我试图识别至少连续3个月出现状态_日期的账户(按ID和SEQ)。这件事我已经搞了一段时间了,我根本不知道该怎么处理

样本数据:

ID     SEQ   STATUS_DATE
11111    1   01/01/2014
11111    1   02/10/2014
11111    1   03/15/2014
11111    1   05/01/2014
11111    2   01/30/2014
22222    1   06/20/2014
22222    1   07/15/2014
22222    1   07/16/2014
22222    1   08/01/2014
22222    2   02/01/2014
22222    2   09/10/2014
我需要返回的内容:

ID      SEQ   STATUS_DATE
11111    1    01/01/2014
11111    1    02/10/2014
11111    1    03/15/2014
22222    1    06/20/2014
22222    1    07/15/2014
22222    1    07/16/2014
22222    1    08/01/2014

任何帮助都将不胜感激

接下来呢。但是,如果您想要的话,您可能希望每月对进行排序

data want;
    do _n_ = 1 by 1 until(last.id);
    set survey;
    by id;
    if _n_ <=3 then output;
    end;
run;
需要数据;
do _n_=1乘以1直到(last.id);
集合测量;
按身份证;
如果这里有一种方法:

data have;
input ID     SEQ   STATUS_DATE $12.;
datalines;
11111    1   01/01/2014
11111    1   02/10/2014
11111    1   03/15/2014
11111    1   05/01/2014
11111    2   01/30/2014
22222    1   06/20/2014
22222    1   07/15/2014
22222    1   07/16/2014
22222    1   08/01/2014
22222    2   02/01/2014
22222    2   09/10/2014
;
run;

data grouped (keep = id seq status_date group) groups (keep = group2);
    set have;
    sasdate = input(status_date, mmddyy12.);
    month = month(sasdate);
    year = year(sasdate);
    pdate = intnx('month', sasdate, -1);
    if lag(year) = year(sasdate) and lag(month) = month(sasdate) then group+0;
    else if lag(year) = year(pdate) and lag(month) = month(pdate) then count+1;
    else do;
        group+1;
        count = 0;
    end;
    if count = 0 and lag(count) > 1 then do;
        group2 = group-1;
        output groups;
    end;
    output grouped;
run;

data want (keep = id seq status_date);
    merge grouped groups (in=a rename=(group2=group));
    by group;
    if a;
run;

基本上,如果观察是连续几个月的,我会给他们相同的组号,然后也会创建一个包含超过2个观察组组号的数据集。然后我合并这两个数据集,只保留第二个数据集中的观察值,即那些观察值超过2个的数据集。

这与问题有什么关系?它根本无法识别连续的几个月。不幸的是,正如Joe已经说过的,这并不能真正解决我要做的事情。为什么不发布你迄今为止尝试过的代码/方法呢?太棒了。那很好用。谢谢你的帮助!