DATA Step, Macro, Functions and more

datetime20.

Reply
Contributor
Posts: 45

datetime20.

I have a data set which is like below

startdatetime enddatetime
12/11/201010:20:30 12/11/201013:20:40
29/12/201010:30:30 30/12/201015:20:40
14/10/201008:40:20 14/10/201017:30:49

now I want difference between startdatetime and enddatetime .
Thanks in advance.
Valued Guide
Posts: 2,177

Re: datetime20.

how about
duration = enddatetime - startdatetime ;
the result is in seconds
Contributor
Posts: 45

Re: datetime20.

this is not working

I want in time10. format
Super Contributor
Super Contributor
Posts: 3,174

Re: datetime20.

Possibly, you want to assign a SAS FORMAT statement to the "duration" variable/column result.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

format statement time site:sas.com
Contributor
Posts: 45

Re: datetime20.

go through google but i could not find .

Please help me I am trying so many time but i can't get it

Thanks in advance
Super Contributor
Super Contributor
Posts: 365

Re: datetime20.

Hello Arpit,

I did the following code and got expected result (I only add a blank in input data separating date and time part):
[pre]
data i;
input s anydtdtm19. e anydtdtm19.;
format s e datetime20. dur time8.;
dur=e-s;
datalines;
12/11/2010 10:20:30 12/11/2010 13:20:40
29/12/2010 10:30:30 30/12/2010 15:20:40
14/10/2010 08:40:20 14/10/2010 17:30:49
;
run;
Dataset i:
s e dur
11DEC2010:10:20:30 11DEC2010:13:20:04 2:59:34
29DEC2010:10:30:30 30DEC2010:15:20:04 28:49:34
14OCT2010:08:40:20 14OCT2010:17:30:04 8:49:44
[/pre]
Sincerely,
SPR
Valued Guide
Posts: 634

Re: datetime20.

What exactly is not working? When you apply Peter's solution, what error are you getting? Are your two datetime variables correctly holding SAS datetime values?
SAS Super FREQ
Posts: 8,864

Re: datetime20.

Hi:
Have you tried using the TIME format with your calculated duration???

Are you certain that all your durations are going to "fit" in TIME10?? What if your duration is more than 9999 hours??? More than 2 years (which is approx 17,000 hours)??

cynthia
Regular Contributor
Posts: 171

Re: datetime20.

How do you want the result to be formatted?
Ask a Question
Discussion stats
  • 8 replies
  • 439 views
  • 0 likes
  • 7 in conversation