It’s World Statistics Day! To honor the theme of the day, the JMP User Community is having conversations about the importance of trust in statistics and data. And we want to hear from you! Tell us the steps you take to ensure that your data is trustworthy.
Choose Language Hide Translation Bar
Highlighted
sweetycha
Level III

Extract hours to the nearest hours from duration ( hour:min) format

Hi Guys

how to extract hours from the duration ( hr:min) formant and round the min into the hours

example:

15:26 : 15 hours and 26 min

I want : 15

16:38: 16 hours and 38 mins

I want :17 as 38 min is over 30 mins

 

Appreciate your help

3 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
sweetycha
Level III

Re: Extract hours to the nearest hours from duration ( hour:min) format

Thank you.

How to re format the round into  hour only  value i.e for 12 hours  we want 12 not 12:00:00 to make it numeric value

View solution in original post

Highlighted
txnelson
Super User

Re: Extract hours to the nearest hours from duration ( hour:min) format

Go to the Column Info for the formula column and select a Format to use.  Since there is not a direct format that will just display the Hour component of a time based column, you need to select a "Custom" format.  The value you need to specify for the custom format is

Hour( value )
Jim

View solution in original post

Highlighted

Re: Extract hours to the nearest hours from duration ( hour:min) format

I took a different approach. I abandoned time and directly obtained hours. Here is the resulting table:

 

table.JPG

 

Here is the formula that I used.

 

formula.JPG

 

I attached the modified data table for you.

Learn it once, use it forever!

View solution in original post

6 REPLIES 6
Highlighted
txnelson
Super User

Re: Extract hours to the nearest hours from duration ( hour:min) format

Here is how I do it

Names Default To Here( 1 );

time=informat("15:22:00","h:m:s");
show(format(round(time/inhours(1))*3600,"h:m:s"));

time=informat("10:49:00","h:m:s");
show(format(round(time/inhours(1))*3600,"h:m:s"));
Jim
Highlighted
sweetycha
Level III

Re: Extract hours to the nearest hours from duration ( hour:min) format

Thank you

Is there a way to do this without a script? I am not familiar with JMP programming but I run sas programming.

Is not then how to recode this with my actual variable name that is called "hours" and is in duration ( hr:min) formant. I would like to create a col hours1 and extract the hours and do the rounding?

Highlighted
txnelson
Super User

Re: Extract hours to the nearest hours from duration ( hour:min) format

Attached is a data table with a time column and a formula column called Rounded that rounds the hours using the formula

Round( :Time / In Hours( 1 ) ) * 3600

rounded.PNG

 

Jim
Highlighted
sweetycha
Level III

Re: Extract hours to the nearest hours from duration ( hour:min) format

Thank you.

How to re format the round into  hour only  value i.e for 12 hours  we want 12 not 12:00:00 to make it numeric value

View solution in original post

Highlighted
txnelson
Super User

Re: Extract hours to the nearest hours from duration ( hour:min) format

Go to the Column Info for the formula column and select a Format to use.  Since there is not a direct format that will just display the Hour component of a time based column, you need to select a "Custom" format.  The value you need to specify for the custom format is

Hour( value )
Jim

View solution in original post

Highlighted

Re: Extract hours to the nearest hours from duration ( hour:min) format

I took a different approach. I abandoned time and directly obtained hours. Here is the resulting table:

 

table.JPG

 

Here is the formula that I used.

 

formula.JPG

 

I attached the modified data table for you.

Learn it once, use it forever!

View solution in original post