## How to do calculations with 24 hour HH:MM variable

Solved
Occasional Contributor
Posts: 6

# How to do calculations with 24 hour HH:MM variable

Hi

I have a dataset containing time variables in the 24 hour HH:MM. (e.g., 07:00, 18:30). I'm not sure how to do calculations with such variables. I try to get the difference between two such variables (like the date variable), but it didn't work out. Also, I'd like to add certain time to these variables (e.g., add 600 seconds to 07:00).

Maybe I can convert all these time variables to their SAS numeric values (seconds from midnight), but I don't know how.

Can anyone help with this?

Thanks a lot.

Terry

Accepted Solutions
Solution
‎06-28-2016 11:00 AM
Super User
Posts: 10,244

## Re: How to do calculations with 24 hour HH:MM variable

``````data have;
input time_in \$;
cards;
07:00
15:00
;
run;

data want;
set have;
format time_out hhmm5.;
time_out = input(time_in,time5.);
time_out = time_out + 700;
run;
``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Solution
‎06-28-2016 11:00 AM
Super User
Posts: 10,244

## Re: How to do calculations with 24 hour HH:MM variable

``````data have;
input time_in \$;
cards;
07:00
15:00
;
run;

data want;
set have;
format time_out hhmm5.;
time_out = input(time_in,time5.);
time_out = time_out + 700;
run;
``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 6

## Re: How to do calculations with 24 hour HH:MM variable

Thank you!

Super Contributor
Posts: 394

## Re: How to do calculations with 24 hour HH:MM variable

Use the time5. informat to read the value and convert it to a SAS time value.

```data;
input time time5.;
put time=;
put time hhmm5.;
time2 = time + 600;
put time2 hhmm5.;
datalines;
07:00
18:30
;;;;```
🔒 This topic is solved and locked.