BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Steelers_In_DC
Barite | Level 11

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.

View solution in original post

5 REPLIES 5
M_Maldonado
Barite | Level 11

google about intck and intcx functions

hih!

-Miguel

mlogan
Lapis Lazuli | Level 10

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

Steelers_In_DC
Barite | Level 11

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;

Steelers_In_DC
Barite | Level 11

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.

mlogan
Lapis Lazuli | Level 10

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

It works now...thanks

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 5114 views
  • 0 likes
  • 3 in conversation