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

Hello,

Below is resultant table with just the first and last records for each application.  How can I get the time difference between the first record (Start Time) and the last record (EndTime) for the same application id?

For example - AppID 1001 time difference is 0 hours, 2 minutes, 24 seconds.

Thanks!

AppIDOprIDStartTimeEndTime
1001109OCT2013:11:24:51.00000009OCT2013:11:27:15.000000
1001109OCT2013:11:26:16.00000009OCT2013:11:27:15.000000
1002209OCT2013:09:15:49.00000009OCT2013:09:34:33.000000
1002209OCT2013:09:24:16.00000009OCT2013:09:34:33.000000
1003309OCT2013:11:19:43.00000009OCT2013:11:19:57.000000
1003310OCT2013:14:50:47.00000010OCT2013:14:51:16.000000
1 ACCEPTED SOLUTION

Accepted Solutions
snoopy369
Barite | Level 11

DATETIMEs in SAS are stored as an integer number of seconds since 1/1/1960 0:00:00.  So, you can simply subtract the two values.  You can then format the result with a TIME format.

Data want;
set have;
by appID;
retain starting_time;
if first.appID then starting_time=starttime;
if last.appID then do;
duration=endtime-starting_time;
output;
end;
format duration TIME8.;
run;

View solution in original post

2 REPLIES 2
snoopy369
Barite | Level 11

DATETIMEs in SAS are stored as an integer number of seconds since 1/1/1960 0:00:00.  So, you can simply subtract the two values.  You can then format the result with a TIME format.

Data want;
set have;
by appID;
retain starting_time;
if first.appID then starting_time=starttime;
if last.appID then do;
duration=endtime-starting_time;
output;
end;
format duration TIME8.;
run;
jen123
Fluorite | Level 6

Thank you very much Snoopy369!

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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