BookmarkSubscribeRSS Feed
arpit
Calcite | Level 5
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.
8 REPLIES 8
Peter_C
Rhodochrosite | Level 12
how about
duration = enddatetime - startdatetime ;
the result is in seconds
arpit
Calcite | Level 5
this is not working

I want in time10. format
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
arpit
Calcite | Level 5
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
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
ArtC
Rhodochrosite | Level 12
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?
Cynthia_sas
SAS Super FREQ
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
polingjw
Quartz | Level 8
How do you want the result to be formatted?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1439 views
  • 0 likes
  • 7 in conversation