Evaluating time increments between records for same phone number

Solved
Frequent Contributor
Posts: 94

Evaluating time increments between records for same phone number

I need some help, not even sure where to start.

I have transactional data, I need to read through the records for each phone number and determine the time increment between each call to make sure it is outside allowable minimum number of minutes.

Each phone number could only have one call or multiple.

I have no idea how to do this, any assistance will be greatly appreciated.

thank you,

Accepted Solutions
Solution
‎03-04-2015 08:24 PM
PROC Star
Posts: 8,164

Re: Evaluating time increments between records for same phone number

The dif function, based on a numeric variable that has a time format, will provide the number of seconds between two times.  e.g.:

data have;

informat time time5.;

format time time5.;

input phonenum time;

cards;

123 9:35

123 10:15

123 14:50

321 9:55

321 10:45

321 14:10

;

data want;

set have;

by phonenum;

dif=dif(time);

if first.phonenum then call missing(dif);

run;

All Replies
Super User
Posts: 23,724

Re: Evaluating time increments between records for same phone number

You need to post sample data.

In general use the dif function and then First/Last processing.

Use the First.phone_number to set the difference to missing.

PROC Star
Posts: 8,164

Re: Evaluating time increments between records for same phone number

It would be helpful to know what your data looks like (i.e., fields, field types, and how they're formatted), and what you want to achieve.  e.g., are you looking for the average time between phone calls for each number, and do you just want to ignore phone numbers that only have one call?

Frequent Contributor
Posts: 94

Re: Evaluating time increments between records for same phone number

The data is transactional, there is an ID, \$18.; phone_num \$20.; call_time in a time format looks like 08:46 AM in the data set

I need to evaluate each record that has the same phone number to see if the calls were placed within a 15 minutes period.  if so then I have to throw and error.

I do not need to worry about phone numbers that only have 1 record call.

Thanks

PROC Star
Posts: 8,164

Re: Evaluating time increments between records for same phone number

Do you have a date variable as well?

Frequent Contributor
Posts: 94

Re: Evaluating time increments between records for same phone number

all records are for the same date

Solution
‎03-04-2015 08:24 PM
PROC Star
Posts: 8,164

Re: Evaluating time increments between records for same phone number

The dif function, based on a numeric variable that has a time format, will provide the number of seconds between two times.  e.g.:

data have;

informat time time5.;

format time time5.;

input phonenum time;

cards;

123 9:35

123 10:15

123 14:50

321 9:55

321 10:45

321 14:10

;

data want;

set have;

by phonenum;

dif=dif(time);

if first.phonenum then call missing(dif);

run;

Frequent Contributor
Posts: 94

Re: Evaluating time increments between records for same phone number

Thank you very much Arthur, that is exactly what I needed.

Cindy

🔒 This topic is solved and locked.

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

Discussion stats
• 7 replies
• 290 views
• 0 likes
• 3 in conversation