-1

我有来自单个患者的多次记录的以下数据。

ID                       date           day     result
BELF000000084785    20111110    1   164
BELF000000084785    20111202    2   172
BELF000016833470    20070122    2   226
BELF000016833470    20070522    3   398
BELF000016959442    20080429    1   242
BELF000016959442    20080820    1   126
BELF000016959442    20090225    2   302
BELF000016959442    20090424    2   320
BELF000017061714    20080626    1   152
BELF000017801424    20110803    1   298
BELF000017801424    20110913    2   252
BELF000017801424    20111022    3   234
BELF000024405407    20080218    1   232
BELF000024405407    20080318    2   190
BELF000024405410    20070122    3   380
BELF000024405410    20070218    1   506
BELF000024405410    20070320    2   480
BELF000024405410    20070626    3   346
BELF000024408114    20070423    1   296
BELF000024408114    20070711    3   294

我想提取第 1 天有记录的患者;如果第 1 天和第 2 天都可用,第 1 天第 2 天和第 3 天都可用。并通过其他。任何 sas 帮助。

4

2 回答 2

0

如果没有重复 ID - 日级别,您可以跳过最近的一天:

proc sort data=sample;
by ID day;
run;

data result;
set sample;
by ID;
if not last.ID then output;
run;

您想如何处理重复的 ID - 不同日期的日记录?

于 2012-09-25T10:50:45.460 回答
0

我认为这正是 OP 中所要求的。我不知道这是否真的是你想要的,但这需要进一步澄清。

data have;
informat date YYMMDD8.;
format ID $17.;
input ID $ date day result ;
datalines;
BELF000000084785    20111110    1   164
BELF000000084785    20111202    2   172
BELF000016833470    20070122    2   226
BELF000016833470    20070522    3   398
BELF000016959442    20080429    1   242
BELF000016959442    20080820    1   126
BELF000016959442    20090225    2   302
BELF000016959442    20090424    2   320
BELF000017061714    20080626    1   152
BELF000017801424    20110803    1   298
BELF000017801424    20110913    2   252
BELF000017801424    20111022    3   234
BELF000024405407    20080218    1   232
BELF000024405407    20080318    2   190
BELF000024405410    20070122    3   380
BELF000024405410    20070218    1   506
BELF000024405410    20070320    2   480
BELF000024405410    20070626    3   346
BELF000024408114    20070423    1   296
BELF000024408114    20070711    3   294
;;;;
run;

data want;
do _n_ = 1 by 1 until (last.ID);
 set have;
 by ID notsorted;
 if first.ID then do; 
    lastday=0; 
    done=0; 
 end;
 if (first.ID) and (day ne 1) then lastday=-99;
 else if day ne lastday+1 then done=1;
 else if not done then lastday=day;
end;
do _n_ = 1 by 1 until (last.ID);
 set have;
 by ID notsorted;
 if first.ID then curday=0;
 curday+1;
 if curday le lastday then output;
end;
run;

结果:

Obs      ID        date day result 
1 BELF000000084785  18941 1 164 
2 BELF000000084785  18963 2 172 
3 BELF000016959442  17651 1 242 
4 BELF000017061714  17709 1 152 
5 BELF000017801424  18842 1 298 
6 BELF000017801424  18883 2 252 
7 BELF000017801424  18922 3 234 
8 BELF000024405407  17580 1 232 
9 BELF000024405407  17609 2 190 
10 BELF000024408114  17279 1 296 
于 2012-09-25T13:49:12.280 回答