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

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,

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

7 REPLIES 7
Reeza
Super User

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.

art297
Opal | Level 21

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?

Elliott
Obsidian | Level 7

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

art297
Opal | Level 21

Do you have a date variable as well?

Elliott
Obsidian | Level 7

all records are for the same date

art297
Opal | Level 21

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;

Elliott
Obsidian | Level 7

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

Cindy

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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