Time Difference in hours

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Time Difference in hours

Hello All I have these two datetime variables and I would like to know the time difference in hours.

Var1 - looks like this 22FEB2009:06:48:00

Var2 -looks this 22FEB2009:08:19:00

i used following program

data dates;

set work.t;

time_differ = (var2)-(var1);

put time_differ time8.;

run;

Log shows exact time difference but when i open the dataset it looks like this.

time_differ = 5840

Please help me...


Accepted Solutions
Solution
‎05-29-2015 12:31 PM
New Contributor
Posts: 3

Re: Time Difference in hours

This does the trick. define the format of the variable before filling it.

data dates;

set work.test;

format time_differ time8.;

time_differ = (var2)-(var1);

run;

View solution in original post


All Replies
Super User
Posts: 17,836

Re: Time Difference in hours

You haven't formatted your variable so that's the number of seconds.

Apply the time8 format to your variable as well, which you did in the put statement.

Solution
‎05-29-2015 12:31 PM
New Contributor
Posts: 3

Re: Time Difference in hours

This does the trick. define the format of the variable before filling it.

data dates;

set work.test;

format time_differ time8.;

time_differ = (var2)-(var1);

run;

Super User
Posts: 17,836

Re: Time Difference in hours

It doesn't matter where the format statement is (before/after) but it does need to be there.

Occasional Contributor
Posts: 7

Re: Time Difference in hours

Thanks a lot everyone it worked!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 214 views
  • 6 likes
  • 3 in conversation