manso.andre
manso.andre

Reputation: 45

How to subtract date/time values from different rows in the same column in sas

I got this values in my table and I need to know how can I subtract them creating another column with the results.

19FEB2018:14:24:43.00
23MAR2018:12:57:58.00
28MAR2018:15:37:37.00
29JUN2018:10:30:33.00
29JUN2018:13:43:07.00

What I need is:

1- 0h
2- (23MAR2018:12:57:58.00 - 19FEB2018:14:24:43.00)
3- (...)

Upvotes: 0

Views: 210

Answers (1)

Tom
Tom

Reputation: 51611

Just use the DIF() function.

data have;
 input dt datetime.;
 format dt datetime22.2 ;
cards;
19FEB2018:14:24:43.00
23MAR2018:12:57:58.00
28MAR2018:15:37:37.00
29JUN2018:10:30:33.00
29JUN2018:13:43:07.00
;

data want;
  set have ;
  diff = dif(dt);
  format diff hhmm12.2 ;
run;

enter image description here

Upvotes: 3

Related Questions