BookmarkSubscribeRSS Feed
frisco
Calcite | Level 5


Is there an easy and straightforward way to express a datetime value as a fraction? For example 1:15PM would be 1.25

4 REPLIES 4
art297
Opal | Level 21

Since time is just the number of seconds since midnight, you just have to divide by 60*60.  Although, doing that would give you 13.25 rather than 1.25, but would allow you to differentiate between 1:15am and 1:15pm.

e.g.:

data have;

  informat dt anydtdtm21.;

  input dt;

  fraction=timepart(dt)/(60*60);

  cards;

28nov2012:01:15:00

28nov2012:13:30:00

;

jsasusr
Fluorite | Level 6

This worked closer to my problem without the formatting:

NOTE.  My field "Hours" was formatted as time5.

 

So....

data crsefile;

set crsefile;

hoursdec=timepart(hours)/(60*60);

run;

 

So hours 1:55 became 1.9166666667

 

ballardw
Super User

or fractiontime = hour(datetimevariable) + minute(datetimevariable)/60;

if you don't want hour 13 to 23, ignoring AM/Pm

    fractiontime = mod(hour(datetimevariable),12) + minute(datetimevariable)/60;

data_null__
Jade | Level 19

Perhaps you want HOUR format http://support.sas.com/documentation/cdl/en/leforinforref/63324/HTML/default/viewer.htm#p1ajv0kbaa42...

you will need to separate the time from the datetime.

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
  • 4 replies
  • 976 views
  • 0 likes
  • 5 in conversation