|
On Tue, 20 Jan 2009 18:40:05 -0500, Arthur Tabachneck <art297@NETSCAPE.NET>
wrote:
>I'd like to presume that you got a number of offline responses but, if
>not, you could simply use lag to get what you want. E.g.,:
>
>data have;
> input VISIT SUBVISIT $ DTTM;
> format dttm datetime18.;
> cards;
>1 a 1545548400
>1 b 1545548500
>1 c 1545548600
>2 a 1546164000
>2 b 1546166000
>2 c 1546168000
>3 a 1546246800
>3 b 1546250800
>3 c 1546254800
>4 a 1546858800
>4 b 1546880800
>4 c 1546890800
>;
>
>data want;
> set have;
> format difference time10.;
> by visit;
> difference=dttm-lag(dttm);
> if first.visit then call missing (difference);
>run;
>
>HTH,
>Art
>--------
>On Tue, 20 Jan 2009 14:37:00 -0500, wcw2 <wcw2@CDC.GOV> wrote:
>
>>I have a dataset where I need to subtract datetimes (DTTM). I need to
>>subtract the visit2 DTTM from the visit1 DTTM (for same subvisits), same
>>with visit3-visit2, and same with visit4-visit3, etc. What's the best way
>>to do this?
>>thanks!
>>
>>
>>VISIT SUBVISIT DTTM
>>1 a 1545548400
>>1 b 1545548400
>>1 c 1545548400
>>2 a 1546164000
>>2 b 1546164000
>>2 c 1546164000
>>3 a 1546246800
>>3 b 1546246800
>>3 c 1546246800
>>4 a 1546858800
>>4 b 1546858800
>>4 c 1546858800
The requirements are not completely clear to me. I think something like this
should suffice.
proc sort data=have;
by subvisit descending visit;
run;
data want;
set have;
by subvisit;
difference = ifn( first.subvisit , (.) , dif(dttm) );
format difference time10.;
run;
proc sort data=want;
by visit subvisit;
run;
Result:
VISIT SUBVISIT DTTM difference
1 a 22DEC08:07:00:00 -171:00:00
1 b 22DEC08:07:01:40 -171:31:40
1 c 22DEC08:07:03:20 -172:03:20
2 a 29DEC08:10:00:00 -23:00:00
2 b 29DEC08:10:33:20 -23:33:20
2 c 29DEC08:11:06:40 -24:06:40
3 a 30DEC08:09:00:00 -170:00:00
3 b 30DEC08:10:06:40 -175:00:00
3 c 30DEC08:11:13:20 -176:40:00
4 a 06JAN09:11:00:00 .
4 b 06JAN09:17:06:40 .
4 c 06JAN09:19:53:20 .
|