## Creating variables based on DateDiff of multiple categories

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

NinaBrastti
Posts: 2
Joined: Thu Aug 30, 2012 6:05 pm

### Creating variables based on DateDiff of multiple categories

Hi Everyone, I am in such a need of a good, genius solution:

I am trying to calculate the differences in dates of several categories within one variable. I can use the DateDiff function 100s of times manually but time is scarce. My data look like this:

Subject....Service...Service_Date
A..............1.........Date_I
A..............1.........Date_II
A..............1.........Date_III
A..............2.........Date_I
A..............2.........Date_II
B..............1.........Date_I
B..............1.........Date_II
B..............2.........Date_I
B..............3.........Date_I and so on.

I have 700 Subjects, each of them could have received up to 21 different services, and each service can have up to a 100 different Service_Dates. Now, what I need to study is if the subjects are receiving "Different Services" too close in dates. It's ok if they receive the same service too close in dates, but different services could be hazardeous. So I would need to compile the minimum number of days between the dates that a subject has received service 1 and service 2 and service 3, etc., at any point in time. For that, I guess I need to create a variable that has the date differences (in days) for every service for each subject.
For instance, if Subject A received Service 1 on Jan 1 and then on Jan 10, and received service 2 on Jan 7 and on Jan 10, then I would need a variable that would either tell me that the DateDiff between Service I and service II for subject A are: "6 days, 3 days, 9 days, and 0 days". or better yet, just give me the minimum of all those date differences, which in this case would be 0, i.e. the minimum time the subject took between services I and II.
I tried using the loop function that would for each Subject , give me the date differences between the categories, but it just wouldnt run. Would someone please have any suggestions? Thank you so very much in advance, you would be a life-saviour.

### Who is online

Users browsing this forum: No registered users and 4 guests