Hello All,
I am stuck and seeking help. I have a dataset which has prescription claims and I want to include claims after 180 days of washout period for each patient. The first claim I have is from 1st Jan 2020. So I don't want to include any claim which is within 180 days from 1st Jan 2020 and don't want to include the subsequent claims if the first claim of the patient is within 180 days from 1st Jan 2020 and the next claim is within 180 days until the day difference between the subsequent claims are 180 days or more.
Dataset I want:
PT_ID PRES_DATE Include
1 5Jan2020 0
1 8Feb2020 0
1 10Jan2021 1
1 8Feb2021 1
2 15Aug2020 1
2 19Sep2020 1
2 18Oct2020 1
3 9Jan2020 0
3 10Oct2020 1
3 15Oct2020 1
4 10Jul2020 1
4 15Jul2020 1
4 20Mar2021 1
Thank you
Hi @abhi309 . I believe this sounds like a question I asked recently. See this post and see if the concepts work for your dataset.
Solved: Re: Creating new variables based on most recent date - SAS Support Communities
Hello @sasgorilla,
Thank you for your help but the output I am looking for is a little different. The problem I am having is I have 2 different decisions based on the first prescription. If the first prescription is within 180 days from 1st Jan 2020 then I don't want to include any subsequent prescriptions until the day difference between the consecutive prescriptions are more than 180 days and including all the prescriptions thereafter. But if the first prescription is after 180 days from 1st Jan 2020 then I can include all the prescriptions without bothering about the day difference.
Abhi
You want to find the first observation following a date gap of 180 days or more. All obs starting with that obs have INCLUDE=1. All obs prior to it have INCLUDE=0. For the first obs of each PT_ID the gap is the number of days from 01jan2020 to PRES_DATE:
This is an untested program in the absence of sample data in the form of a working DATA step. Assuming data are sorted by PT_ID/PRES_DATE, then:
data want (drop=_:);
set have;
by pt_id;
retain include 0;
if first.pt_id then include=0;
_prior_date=ifn(first.pt_id,'01jan2020'd,lag(pres_date));
if pres_date-_prior_date>180 then include=1;
run;
Hi abhi309,
For your requirement of "if the first prescription is within 180 days from 1st Jan 2020 then I don't want to include any subsequent prescriptions until the day difference between the consecutive prescriptions are more than 180 days and including all the prescriptions thereafter. But if the first prescription is after 180 days from 1st Jan 2020 then I can include all the prescriptions without bothering about the day difference", it can be simplified as: "do not include any prescription within 180 days from 01JAN2020". And thus my answer is created like this.
I also created a data set which calculate the days between two consecutive prescriptions for one subject(or participant, or patient whatever term you use) for possible further usage. The reference code for using LAG function to calculate numeric difference of any consecutive values for one subject is from SAS Programming 3: Advanced Techniques, course notes PDF, on page 32, no.4.
data preclaim;
input PT_ID PRES_DATE date9.;
format pres_date date9.;
datalines;
1 5Jan2020
1 8Feb2020
1 10Jan2021
1 8Feb2021
2 15Aug2020
2 19Sep2020
2 18Oct2020
3 9Jan2020
3 10Oct2020
3 15Oct2020
4 10Jul2020
4 15Jul2020
4 20Mar2021
;
run;
proc print data=preclaim;run;
/*add include flag as 0 or 1*/
data preclaim1;
set preclaim;
if pres_date<'01jan2020'd+179
then include=0;
else include=1;
run;
proc print data=preclaim1;run;
/*calculate the number of days between
any two consecutive prescription claims
for one subject, for futher usage*/
data preclaim2;
set preclaim;
by pt_id;
presdlag=lag1(pres_date);
if first.pt_id then presdlag=.;
diffdays=pres_date-presdlag;
format presdlag date9.;
run;
proc print data=preclaim2;run;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.