BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AlexeyS
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Not quite.

Duration_Seconds = End_Time - Start_Time;
Duration_Milliseconds = Duration_Seconds*1000;

Format Duration_Seconds Duration_Milliseconds 12.;

The duration variable will be in seconds so you need to subtract and multiply by 1000. Don't overthink it 😉

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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.

 

AlexeyS
Pyrite | Level 9

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

 

 

 

 

 

Reeza
Super User
Not quite.

Duration_Seconds = End_Time - Start_Time;
Duration_Milliseconds = Duration_Seconds*1000;

Format Duration_Seconds Duration_Milliseconds 12.;

The duration variable will be in seconds so you need to subtract and multiply by 1000. Don't overthink it 😉
Tom
Super User Tom
Super User

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

 

 

ballardw
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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