Calculating intervals between multiple dates

Reply
Contributor
Posts: 28

Calculating intervals between multiple dates

Hi, I have data like this (all of the dates are in SAS date format):

Study IDDiagnosisDate1DiagnosisDate2RxFillDate1RxFillDate2ProcedureDate1ProcedureDate2
1Jan 1 2010June 30 2010Jan 1 2009Feb 1 2010..
2Jan 1 2011Jan 30 2011Jan 1 2012June 1 2012Jan 1 2013.
3Jan 1 2012June 30 2012Jan 1 2013June 1 2013June 1 2013.

I'm interested in finding the shortest interval between any of the diagnosis dates and any of the Rx fill dates OR procedure dates. I want to identify everyone who had an Rx or procedure 6 months AFTER a diagnosis and I don't care whether it was the first diagnosis or not (for example, patient 1 had a prescription fill date on Feb 1, 2010, a month after their Jan 1, 2010 diagnosis, so I would like to flag them for inclusion. Patient 2 did not have any prescriptions or procedures within 6 months of either diagnosis date, so I don't want to include him). Some people have 20+ diagnosis dates and 20+ Rx and procedure dates, so it's not very efficient to calculate the differences between all those dates by hand. Is there code I can use to calculate the differences between all of the diagnosis dates and each of the RxfillDates and ProcedureDates? Then, once the differences in dates have been calculated, I could identify everyone who at least one date differences of 180 days or less for inclusion in my analysis?

Thanks so much in advance.

Super User
Posts: 19,157

Re: Calculating intervals between multiple dates

Have you looked into arrays?

Trusted Advisor
Posts: 1,789

Re: Calculating intervals between multiple dates

Use arrays to loop over all of the appropriate dates, and INTCK to compute the number of days between the different dates.

Contributor
Posts: 28

Re: Calculating intervals between multiple dates

Can you be more specific? Here's what I've tried:

DATA want;

set have;

*These are variables I have;

ARRAY DXDATE (175) DIAGNOSISDATE1-DIAGNOSISDATE175;

ARRAY PROCEDUREDATE (23) PROCEDUREDATE1-PROCEDUREDATE23;

*this is a new variable I'm creating, figuring at most there are 175*23=4025 different intervals between diagnosis and procedures;

array procduredays(4025) procduredays1-procduredays4025;

DO i=1 TO 4025 ;

procduredays(i)=((PROCEDUREDATE1-PROCEDUREDATE23)-(DIAGNOSISDATE1-DIAGNOSISDATE175));

end;

RUN;

I know the last 4 lines of code are incorrect but I'm hoping they clarify what I'm trying to calculate: all the (up to 4025) different time intervals between each of the diagnosis dates and each of the procedure dates. Then I want to choose the smallest time interval from those.

Thanks again for any help.

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