Building Drug Therapy Episodes
The following SAS code provides a simple approach to building basic drug therapy episodes from prescription claims or drug records. The idea is to take many drug prescriptions per patient, order them by prescription date and output non-overlapping drug episodes or therapy periods. The ouput is intended to represent the start and end dates that each patient starts and ends drug therapy. This particular program handles a single drug compound or class of drugs. If the input data set contains multiple drug names or classes that need to be evaluated individually, the program needs to be adjusted to output episodes for each drug name/class.
—————————————–
* Macro to Build Drug Therapy Episodes;
%macro episodes(&DrugRecordTable, &PatID, &PrscFillDt, &DaysSupp, &Buffer);
proc sort data = &DrugRecordTable;
by &PatID &PrscFillDt;
run;
data DRUG_EPISODES;
set &DrugRecordTable;
by &PatID &PrscFillDt;
retain EPISODE_ST_DT EPISODE_END_DT COUNTER;
if first.&PatID then do;
EPISODE_ST_DT = &PrscFillDt;
EPISODE_END_DT = &PrscFillDt + &DaysSupp + &Buffer;
COUNTER = 0;
end;
if &PrscFillDt <= EPISODE_END_DT and
(&PrscFillDt + &DaysSupp + &Buffer) >= EPISODE_END_DT then do;
EPISODE_END_DT = (&PrscFillDt + &DaysSupp + &Buffer);
COUNTER = COUNTER + 1;
end;
if &PrscFillDt <= EPISODE_END_DT and
(&PrscFillDt + &DaysSupp + &Buffer) < EPISODE_END_DT then do;
COUNTER = COUNTER + 1;
end;
if &PrscFillDt > EPISODE_END_DT then do;
output;
EPISODE_ST_DT = &PrscFillDt;
EPISODE_END_DT = &PrscFillDt + &DaysSupp + &Buffer;
COUNTER = 1;
end;
if last.&PatID then output;
format EPISODE_ST_DT EPISODE_END_DT mmddyy10.;
keep SUBJID EPISODE_ST_DT EPISODE_END_DT COUNTER;
run;
proc print data = DRUG_EPISODES (obs=200); run;
proc sql;
select sum(COUNTER) from DRUG_EPISODES;
quit;
%mend;
%episodes(“Drug record table name”, “Patient ID variable”, “Prescription fill date variable”, “Days supplied variable”, “Buffer/bridge days constant”)
—————————————–
The last line of code executes the macro “%episodes” and will build the drug episodes into the table DRUG_EPISODES. The input table needs to have the following variables: patient identifier, prescription fill date and variable for days supplied. If the table doesn’t have a days supplied but has a prescription end date, the macro can easily be adjusted to use the variable for prescription end date instead of the days supplied. Before running this program:
1. Replace the “Drug record table name” with the path and name of the SAS table containing the drug records
2. Replace the “Patient ID variable” with the variable name for the patient identifier
3. Replace the “Prescription fill date variable” with the variable name for the fill date of the prescription
4. Replace the “Days supplied variable” with the variable name for the prescription days supplied (this can also be entered as a constant, ie. “30″ if all prescriptions set to 30-days supplied)
5. Replace the “Buffer/bridge days constant” with the constant value used for the buffer between the previous drug end date and the current prescription fill date. This is typically 30-days - allowing a patient 30 days to refill a precription and stay current on drug therapy.
The first 200 records of the episodes will be printed to the SAS output window for review. The sum of the “COUNTER” variable is also listed in the output window. This sum will equal the number of drug records in the input data set “Drug record table name“. If it doesn’t match to the total number of records in the input data set, then there may be error in the running of the program.
One Response to “Building Drug Therapy Episodes”
Leave a Reply
You must be logged in to post a comment.
[…] >>Building Drug Therapy Episodes […]
15 Mar 2008 at 4:50 am