I think I need to be more specific, apologies. I have a dataset of 10million records, where the structure looks more like this: Date Date
ID registration admission Echo
A 01JAN2001 01JAN2001 1
A 07JAN2001 . 0
A 15JAN2001 01JAN2001 0
A 15JAN2001 01JAN2001 0
A 15JAN2001 . 1
A 15MAR2001 . 1
A 18MAR2001 18MAR2001 0
A 18MAR2001 18MAR2001 0
A 19MAR2001 18MAR2001 1
A 20MAR2001 . 0
A 22MAR2001 18MAR2001 1
B 07MAR2005 . 1
B 10MAR2005 10MAR2005 0
B 21MAR2005 21MAR2005 1
B 23MAR2005 . 0 This is offcourse just an example, because 10million would be a bit much. Roughly each ID has over 1000 records, of which there can be several admissions. I only want to count the occurence of echo when it is within the 42 days of the last date of admission. Both codes provided here do not seem to work.
... View more