BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Brickinnit
Fluorite | Level 6

Dear All,

Sorry for the question - I did search the site and found a few bits but nothing that solved my problem (or maybe I'm just a bit slow.. :-)).

Essentially, I have two date/time fields in character format ($19) displayed as, for example, '2013-10-15T12:33'.  I want to find the time difference in minutes between the two fields, e.g., one field is '2013-10-15T12:33', the other is '2013-10-15T12:35' = difference of 2 minutes.  Any idea how to do this? I think part of the problem is that the variables are in char format and I can't seem to convert...

Any help is greatly appreciated Smiley Happy

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use E8601DT informat.

data have ;

  ct1='2013-10-15T12:33' ;

  ct2='2013-10-15T12:35' ;

  t1 = input(ct1,e8601dt.);

  t2 = input(ct2,e8601dt.);

  format t1 t2 e8601dt. ;

  diff = (t2-t1) / 60 ;

  put (_all_) (=/);

run;

ct1=2013-10-15T12:33

ct2=2013-10-15T12:35

t1=2013-10-15T12:33:00

t2=2013-10-15T12:35:00

diff=2

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Use E8601DT informat.

data have ;

  ct1='2013-10-15T12:33' ;

  ct2='2013-10-15T12:35' ;

  t1 = input(ct1,e8601dt.);

  t2 = input(ct2,e8601dt.);

  format t1 t2 e8601dt. ;

  diff = (t2-t1) / 60 ;

  put (_all_) (=/);

run;

ct1=2013-10-15T12:33

ct2=2013-10-15T12:35

t1=2013-10-15T12:33:00

t2=2013-10-15T12:35:00

diff=2

Brickinnit
Fluorite | Level 6

Thanks Tom - perfect - I owe you one...Smiley Happy

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
  • 2 replies
  • 833 views
  • 0 likes
  • 2 in conversation