Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Subtracting time

Reply
Regular Contributor
Posts: 218

Subtracting time

I have to following Excel data with start and end time.

Time task openedTime task completed
07:31:0007:46:00
07:48:0007:52:00
07:55:0007:57:00
08:30:0008:33:00
10:45:0010:52:00
21:15:0021:28:00
19:54:0019:57:00
09:45:0009:48:00
10:52:0010:56:00
11:47:0011:52:00

Calculating the time difference don't return any value in the first observation, can anyone tell me why? Here is the code I wrote.

Data Mylib.time_Final;

Total_Sec =Time_task_completed-Time_task_opened;

set Mylib.time;

run;

Total_SecTime_task_openedTime_task_completed
7:317:46
9007:487:52
2407:557:57
1208:308:33
18010:4510:52
42021:1521:28
78019:5419:57
1809:459:48
18010:5210:56
24011:4711:52

Also how do I make additional column (let's say Total_time) where Total_Sec will show as minute (eg: 00:04:05)

Thanks

Super Contributor
Posts: 337

Re: Subtracting time

google about intck and intcx functions

hih!

-Miguel

Regular Contributor
Posts: 218

Re: Subtracting time

Posted in reply to M_Maldonado

hi Miguel,

I tried INTCK before with the following code, but it doesn't work for me (I get the same output). Do you see in my output how Total_Sec is quite incorrect. Would you be able to answer why this happen if you know of.

Data Mylib.time_Final;

Diff = INTCK('second',Time_task_opened,Time_task_completed);

set Mylib.time;

run;

Thanks

Valued Guide
Posts: 860

Re: Subtracting time

You lines are out of order.  Your set statement has to come before you reference any variables.  It should be like this:

data want;

set have;

Total_Sec=completed-opened;

run;

Valued Guide
Posts: 860

Re: Subtracting time

I have the time so I did it but I agree with Miquel, you should definitely look up intck and intnx:

DATA have;

infile cards dsd;

informat opened completed time.;

format opened completed time.;

input opened completed;

cards;

07:31:00,07:46:00

07:48:00,07:52:00

07:55:00,07:57:00

08:30:00,08:33:00

10:45:00,10:52:00

21:15:00,21:28:00

19:54:00,19:57:00

09:45:00,09:48:00

10:52:00,10:56:00

11:47:00,11:52:00

;

run;

data want;

set have;

total_sec = intck('second',opened,completed);

run;

Although when I run your code I get the same answer.  The reason you want to use intck and intnx is if you are changing the 'second' to minute day or month.

This works for me:

data want;

set have;

Total_Sec=completed-opened;

run;

If it doesn't work for you you might want to check the data quality of that first line.

Regular Contributor
Posts: 218

Re: Subtracting time

Posted in reply to Steelers_In_DC

Thanks Mark for taking your time helping me. I did a silly mistake, put the calculation function before the set commandSmiley Happy

It works now...thanks

Ask a Question
Discussion stats
  • 5 replies
  • 414 views
  • 0 likes
  • 3 in conversation