BookmarkSubscribeRSS Feed
bluegin
Calcite | Level 5

Hi,

I would like to use SAS to calculate the time elapsed in minutes between two time series, start_time and end_time and store it in a third column, time_elapsed. The data looks as such and is stored in an excel spreadsheet in the following hour-minute format:

start_time     end_time

02:20             02:45

03:00             03:45

04:02             04:17

...                    ...

Is there anyone with an idea as to how to proceed?

Thank you

2 REPLIES 2
ballardw
Super User

If you read it into SAS correctly you will get time values.

The SAS function INTCK can calculate many different intervals between times, dates or datetimes.

Also in SAS

End_time - Start_time would equal the number of seconds. So ElapsedMinutes = (end_time - start_time)/60;

Orsini
Fluorite | Level 6

Something like this... 

data gotcha;                                    

   format start_time end_time time_elapsed time5.;

   infile datalines4;                            

   input @1 start_time time5. @7 end_time time5.;

   time_elapsed = end_time - start_time;         

   datalines4;                                   

02:20 02:45                                      

03:00 03:45                                      

04:02 04:17                                      

;;;;                                             

run;                                           

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
  • 1085 views
  • 1 like
  • 3 in conversation