|
板凳

楼主 |
发表于 2012-4-18 03:37:43
|
只看该作者
Re: 请教大虾,怎么把qssj(起始时间)至zzsj(终止时间),用rq(日期)的形式表现出来,一天就是一条记录?
[code:wwv7ackc]data temp(drop=qs zz);
input blh $12. xm $4. ksdm :$10. qssj yymmdd10. qs :$12. zzsj yymmdd10. zz :$12. bch $3. ;
format qssj zzsj yymmdd10.;
d=zzsj-qssj+1;
pk=_n_;
cards;
PID000534075 CJL 8F 2012-03-24 15:47:15:496 2012-04-05 08:46:39:64 2
PID000534075 CJL ICU 2012-04-05 13:14:19:183 2012-04-06 10:54:49:23 32
PID000534075 CJL ICU 2012-04-06 10:54:49:23 2012-04-10 09:16:13:653 52
PID000534075 CJL ICU 2012-04-10 11:14:53:526 2012-04-10 13:54:10:323 52
PID000534075 CJL ICU 2012-04-10 13:54:10:323 2012-04-11 09:17:09:203 51
PID000534075 CJL PICU 2012-04-11 11:17:09:253 2012-04-11 18:17:09:203 16
;
data a;
set temp;
do i=1 to d;
qs=qssj+i;
output;
format qs yymmdd10.;
end;
run;
data b(drop=i qs lag_qs d pk); set a; by pk notsorted;
lag_qs=lag(qs);
if first.pk then lag_qs=.;
else qssj=lag_qs;
format lag_qs yymmdd10.;
run;[/code:wwv7ackc]
the target dataset and your requirment(statement) is somehow confused, hard to follow.Please give us your target dataset exact the same as what you wanted.
i.e. qssj=2012-04-05, there are 2 records with the same qssj, however, qssj=2012-04-06, there is only 1 record, and the other was deleted in your target dataset. |
|