i have a variable of time, such as 08:25:46.87. i need to find difference between two times and want to know total milliseconds.
i found function INTCK, but i don't have there milliseconds.
what i should do?
what do you thins about the next solution : if i got that difference between two times is : 00:02:37.44, i can convert minutes to seconds and get total seconds 157 and to multiply it by 1000(1 seconds=1000milliseconds), and then add 440 seconds(44*1000/100)?
thank you
Time is stored as the number of seconds since midnight. If you have milliseconds or other fractions of a second then they will be there as the fractional part of the number. To find the difference between two times just subtract them.
A-B
To express the result in millisecond just mulitple by 1,000.
thank you. as i understand you, the number after dot, is number of seconds and not milliseconds and the maximum can be 100.(i never see more than 100). i have to substract only two numbers, and the result multiply by 1000?
for example :
1. 08:20:41.87
1. 08:20:40.47
08:20:41.87-08:20:40.47=00:00:01.40(one seconds and 41 number of seconds)
(40/100+01)*1000? right?
thank you
If you did not collect milliseconds then you probably do not have them. But perhaps you are just seeing two decimal places because of the format attached to the variable.
data _null_;
t1= '08:20:41.87't ;
t2= '08:20:40.47't ;
s = t1-t2 ;
ms = s*1000;
put (t1 t2 s) (= time12.3 /);
put (t1 t2 s ms) (= /);
run;
t1=8:20:41.870
t2=8:20:40.470
s=0:00:01.400
t1=30041.87
t2=30040.47
s=1.4
ms=1400
Displayed values really depend on the format. If you use a datetime with no decimal part you won't see any fraction of a second.
Look in the log at the results of this example with different formats.
data _null_;
x = "10JAN2015:10:15:23.123456"dt;
put x datetime22.;
put x datetime22.1;
put x datetime22.2;
put x datetime22.3;
put x datetime22.4;
put x datetime22.5;
run;
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.
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.