Different events within a given time period

Reply
Frequent Contributor
Posts: 138

Different events within a given time period

Hi,

I am creating a dataset where each participant will have a value for Event1, which occurred on a given date. I need to see whether/for whom Event2 occurred within a given time period of Event1.

Any help is much appreciated!

Super User
Posts: 17,743

Re: Different events within a given time period

What does your data look like and what do you want the output to look like.

Frequent Contributor
Posts: 138

Re: Different events within a given time period

There are a few hundred thousand participants, each of whom has one row. Each different event has one column with dates for those who participated in the event, ie:

Participant     Event 1             Event 2         Event 3

1                   10/12/11                              11/11/12

2                   09/01/10           05/08/99   

3                   10/10/10            09/05/07       10/02/05

So for example, I'd like to have a column where a value of 1 signifies that a participant experienced Event 2 within a year after Event 1, and a value of 0 signifies either that they never experienced Event 2 or that it was not within the designated time period.

Super User
Posts: 17,743

Re: Different events within a given time period

Katie has the correct solution then, using 365 as your boundary rather than the number she used.

Contributor
Posts: 21

Re: Different events within a given time period

It sounds like some IF-THEN statements might work but it would be useful to see an example of what the data should look like.

Contributor
Posts: 30

Re: Different events within a given time period

Try this:


DATA have;

INPUT subject $ event1 : MMDDYY8. event2 : MMDDYY8.;

difference = event2 - event1; *This calculates the number of days between event1 and event2;

IF difference >= 1460 and difference <= 2190 THEN within4_6years = 1;  *This determins whether event2 occurs within 4 to 6 years after event1 (4 years = 1460 days, 6 years = 2190 days);

ELSE within4_6years = 0;

FORMAT event1 DATE9. event2 DATE9.;

CARDS;

1     11-24-04     05-12-05

2     12-28-99     03-26-05   

3     01-03-01     10-20-10   

4     10-25-12     01-01-13

;

run;

Contributor
Posts: 30

Re: Different events within a given time period

I've adjusted my previous code to the specifications of your data that you provided.

DATA have; 

INPUT subject $ event1 : MMDDYY8. event2 : MMDDYY8.;

IF event2 ne '' THEN DO;

     difference = event2 - event1;

END;

ELSE DO;

     difference = .;

END:

IF difference <= 365 and difference ne . THEN within1yr= 1;

ELSE within1yr = 0;

FORMAT event1 DATE9. event2 DATE9.;

CARDS;

1     11-24-04     05-12-05

2     12-28-99     03-26-05   

3     01-03-01     10-20-10   

4     10-25-12     01-01-13

;

run;

Ask a Question
Discussion stats
  • 6 replies
  • 240 views
  • 0 likes
  • 4 in conversation