Hello All,
I have a data set which is as follows:
ID | psy_vst | rx | drug | days | disp_date |
123 | . | 1 | 12 | 90 | 15141 |
123 | 1 | . | 12 | 30 | 15153 |
123 | 1 | . | 12 | 30 | 15195 |
123 | 1 | . | 12 | 30 | 15225 |
123 | 1 | . | 3 | 2 | 15227 |
123 | 1 | . | 12 | 30 | 15266 |
123 | . | 1 | 1 | 60 | 15271 |
123 | 1 | . | 7 | 30 | 15278 |
123 | 1 | . | 7 | 30 | 15311 |
123 | 1 | . | 7 | 30 | 15341 |
ID is the patient ID number, psy_vst =1 indicates that the event was a physician visit, rx=1 indicates that the event was a pharmacy visit, each drug is represented by a particular number so the same number under the drug column indicates the same drug,, a different number indicates a different drug, the days variable indicates the days supply for the particular drug and the disp_date indicates the day the drug was given. I want to delete (and create a new dataset of these deleted values) when there is a physician visit associated with the same drug days supply +30 days after the dispense date of the drug from the pharmacy. So in the above example for patient 123, rows 2,3,4 should be deleted from this dataset (and put into a new one) and rows 1, 5, 6, 7, 8, 9, 10 will remain in the dataset as the visits in rows 8, 9, 10 are not for the same drug that was dispensed in the pharmacy on date 15271.
Please could somebody help me write such a code?
Thanks a lot!
Pooja Desai