Convert decimal time to minutes in SAS - time

I am having trouble converting a 9.3 decimal variable to minutes. The variable is showing as a fraction of an hour and I need that to show as minutes.
Here is an example below of what needs to be converted.
DECSNTIME
0.039
1.279
6.801

Convert the decimal hours to seconds, and format the value for time display.
data have;
input decsntime ##;
cards;
0.039 1.279 6.801
run;
data want;
set have;
minutes = decsntime * 60; * plain minutes might be enough, depends on analysis;
time = decsntime * 3600; * sas time value;
format time time5.;
run;
proc report data=want;
columns decsntime minutes time time=timehms time=timehmsd;
define decsntime / 'Time/(hours)' display;
define time / 'Time/(H:M)';
define timehms / format=time8. 'Time/(H:M:S)';
define timehmsd / format=time11.2 'Time/(H:M:S.D)';
run;

As mentioned in the comment by #Richard are you looking for something as simple as the following? If not then please edit your question to give more explanation and examples of data before and after the conversion from hours to minutes.
data have;
input hours;
datalines;
9.3
0.039
1.279
6.801
1
1.5
2
;
data want;
set have;
minutes = hours * 60;
run;

Related

How to convert a hex TimeDateStamp DWORD value into human readable format?

Can anyone explain how to convert a Hex TimeDateStamp DWORD value into human readable format?
I'm just curious as to how a value such as 0x62444DB4 is converted into
"Wednesday, 30 March 2022 10:31:48 PM"
I tried googling of course and could not find any explanation. But there are online converters available.
But I'm just interested in converting these values for myself.
Your value is a 32-bit Timestamp.
Your datetime value is a 32-bit Unix Timestamp: The number of seconds since 1/1/1970.
See https://unixtime.org/
In most programming languages you can work with the hexadecimal notation directly.
Implementation should not be done by one person alone, since a lot of engineering goes into it. Leap years, even leap seconds, timezones, daylight savings time, UTC... all these things need to be addressed when working with a timestamp.
I have added my rough calculation below as a demonstration. Definitely use an existing package or library to work with timestamps.
See the JavaScript code below for demonstration.
There I multiply your value by 1000 because JavaScript works in Milliseconds. But otherwise this applies the same to other systems.
let timestamp = 0x62444DB4;
let dateTime = new Date(timestamp * 1000);
console.log('Timestamp in seconds:', timestamp);
console.log('Human-Readable:', dateTime.toDateString() + ' ' + dateTime.toTimeString());
// Rough output, just for the time.
// Year month and day get really messy with timezones, leap years, etc.
let hours = Math.floor(timestamp/3600) % 24;
let minutes = Math.floor(timestamp/60) % 60;
let seconds = Math.floor(timestamp) % 60;
console.log('Using our own time calculation:', hours + ':' + minutes + ':' + seconds);

Round millseconds timestamp to nearest 30 seconds

I have following ruby code to get current time in "milliseconds", for example: 1648059542287 which is equivalent to Wed Mar 23 2022 18:19:02
What I need is timestamp rounded to nearest 30 seconds, for above example, I need it rounded to 1648059540000. Any suggestions?
#ctime = Time.now.to_f
(#ctime * 1000).to_i
Using the time you provided, I think this will do what you want:
Take your time, convert it to an integer
divide by floating point value 30 the number of half minutes
round that value and multiple by 30 to get back to the number of seconds
Create a new time object based on the rounded value.
input = Time.at(1648059542,287000)
Time.at((input.to_i / 30.0).round * 30)

How to format time in SAS

I have a dataset with three columns : Start, Stop and Date
Observations in my Start and Stop are time type.
I have the following two values in my Start and Stop columns:
24:49:00 and 25:16:00
As there are both over 24 hours format.
I would like to convert those two values to the following:
24:49:00 to 00:49:00
and
25:16:00 to 01:16:00
How to do this in both SAS and proc sql ?
Thank you !
Do you need to convert them? Use the TIMEPART() function.
start_day=datepart(start);
start_time=timepart(start);
format start_time tod8.;
Or do you just want to display them that way?
format start stop tod8.;
Start/Stop time-24:00:00 like this:
data _null_;
start='25:16:14't;
point='24:00:00't;
_start=start-point;
put _start;
format _start time8.;
run;
SAS Time and DateTime values use seconds as their fundamental unit.
Thus you can use either modulus arithmetic or TIMEPART function to extract the less than 24 hour part of a > 24 hour time value.
data have;
start = '24:49:00't;
stop = '25:16:00't;
start_remainder = mod(start, '24:00't); * modulus arithmetic;
stop_remainder = mod(stop, '24:00't);
start_timepart = timepart(start); * TIMEPART function;
stop_timepart = timepart(stop);
format start: stop: time10.;
run;
After the computation do not expect start_remainder is less than stop_remainder to be always true.

Decimal minutes into time format (Tabular Cube)

I would like to change decimal minutes into HH:mm:ss (DAX, Tabular Cube).
When I use this :
measure = FORMAT(TIME(0;minutes;0);"HH:mm:ss")
I get hours and minutes but without seconds. Minutes are rounded.
When I use this :
measure = FORMAT(TIME(0;0;minutes*60);"HH:mm:ss")
I have an error that value is too big or too small.
Thanks in advance.
DAX understands decimal time in units of days, so all that you need to do is convert decimal minutes to decimal days and format:
FORMAT ( [Minutes] / 60 / 24, "HH:mm:ss" )

How Can I Round All Time Using SAS?

I have a little problem and appreciate if anyone could help me.
What I'm trying to do is basically round the time part to the nearest 30 minute.
My question is how can I do rounding data using SAS.
This is my command:
DATA sampledata;
INFORMAT TRD_EVENT_TM time10.;
FORMAT TRD_EVENT_TM TRD_TMR time14.;
INPUT TRD_EVENT_TM;
TRD_TMR = round(TRD_EVENT_TM, 1800);
INFILE;
00:14:12
00:16:12
09:01:23
09:46:32
15:59:45
;
PROC PRINT; RUN;
But I want to round all time, Not five of them.I am using big data.
Thanks for your attention.
assuming you are asking how to do this rounding on other data, not just your datalines in the example above I suggest you separate these two tasks into two different data steps.
First you create your sample data (this you can exchange for your main data later)
DATA sampledata;
infile datalines;
INPUT TRD_EVENT_TM hhmmss8.;
datalines;
00:14:12
00:16:12
09:01:23
09:46:32
15:59:45
;
RUN;
Then you perform the rounding of the time variables.
data test;
set sampledata;
format TRD_EVENT_TM TRD_TMR time.;
TRD_TMR = round(TRD_EVENT_TM, 1800);
run;
Hope this is the answer to the question you had.
data Sampledata_RT;
set Sampledata04;
TRD_EVENT_ROUNDED = intnx('minute30',TRD_EVENT_TM,1,'b');
TRD_EVENT_ROUFOR = put(TRD_EVENT_ROUNDED,hhmm.);
CountedVOLUME = TRD_PR*TRD_TUROVR;
run;

Resources