Starting with the dataset below, we need to identify the index encounter, which is the encounter_date closest to the start_date.
Encounter_date may be up to two weeks prior to intake survey date(start_Date) through 1 week after it
We also need to apply a washout period. To qualify as an index encounter, there must be no other encounters within 183 days prior to the 2 week grace period, up to two weeks before the index period.
Person_ID Encoured_Date Start_Date
00006A7087 10/7/2021 4/5/2022
00006A7087 11/5/2021 4/5/2022
00006A7087 11/15/2021 4/5/2022
00006A7087 12/2/2021 4/5/2022
00006A7087 12/14/2021 4/5/2022
00006A7087 12/21/2021 4/5/2022
00006A7087 1/3/2022 4/5/2022
00006A7087 1/18/2022 4/5/2022
00006A7087 1/25/2022 4/5/2022
00006A7087 2/4/2022 4/5/2022
00006A7087 2/8/2022 4/5/2022
00006A7087 2/17/2022 4/5/2022
00006A7087 3/2/2022 4/5/2022
00006A7087 3/8/2022 4/5/2022
00006A7087 3/18/2022 4/5/2022
00006A7087 4/5/2022 4/5/2022
00006A7087 4/12/2022 4/5/2022
0000E20E92 1/28/2022 4/5/2022
0000E20E92 3/22/2022 4/5/2022
0000E20E92 4/5/2022 4/5/2022
0000E20E92 5/3/2022 4/5/2022
0000E20E92 5/17/2022 4/5/2022
0000E20E92 5/31/2022 4/5/2022
0000E20E92 7/15/2022 4/5/2022
0000E20E92 8/9/2022 4/5/2022
0000E20E92 10/19/2022 4/5/2022
0000E20E92 11/30/2022 4/5/2022
I know how to go 1 week forward and two weeks backward using the intnx function. I however don'w know about how to construct the washout period part.
Hi,
try this:
data have;
input Person_ID :$10. Encounter_date :mmddyy10. Start_Date :mmddyy10.;
format Encounter_date Start_Date is8601da.;
datalines;
00006A7087 10/7/2021 4/5/2022
00006A7087 11/5/2021 4/5/2022
00006A7087 11/15/2021 4/5/2022
00006A7087 12/2/2021 4/5/2022
00006A7087 12/14/2021 4/5/2022
00006A7087 12/21/2021 4/5/2022
00006A7087 1/3/2022 4/5/2022
00006A7087 1/18/2022 4/5/2022
00006A7087 1/25/2022 4/5/2022
00006A7087 2/4/2022 4/5/2022
00006A7087 2/8/2022 4/5/2022
00006A7087 2/17/2022 4/5/2022
00006A7087 3/2/2022 4/5/2022
00006A7087 3/8/2022 4/5/2022
00006A7087 3/18/2022 4/5/2022
00006A7087 4/5/2022 4/5/2022
00006A7087 4/12/2022 4/5/2022
0000E20E92 1/28/2022 4/5/2022
0000E20E92 3/22/2022 4/5/2022
0000E20E92 4/5/2022 4/5/2022
0000E20E92 5/3/2022 4/5/2022
0000E20E92 5/17/2022 4/5/2022
0000E20E92 5/31/2022 4/5/2022
0000E20E92 7/15/2022 4/5/2022
0000E20E92 8/9/2022 4/5/2022
0000E20E92 10/19/2022 4/5/2022
0000E20E92 11/30/2022 4/5/2022
;
run;
PROC SORT; BY Person_ID Start_Date Encounter_date; RUN;
PROC FORMAT;
value yn
low-<0=' '
0='No'
1-high='Yes';
RUN;
DATA want;
SET have;
BY Person_ID Start_Date Encounter_date;
/*Encounter_date may be up to two weeks prior to intake survey date(start_Date) through 1 week after it*/
Survey_low=Start_Date-7;
Survey_high=Start_Date+7;
valid_encounter=put(ifn(Survey_low<=Encounter_date<=Survey_high,1,0),yn.);
/*We also need to apply a washout period. To qualify as an index encounter,
there must be no other encounters within 183 days prior to the 2 week grace period, up to two weeks before the index period.*/
grace_low=Start_Date-14-183;
grace_high=Start_Date+14;
retain Encounter_started_in_Range 0;
if first.Person_ID then Encounter_started_in_Range=0;
Encounter_started_in_Range=Encounter_started_in_Range+ifn(Survey_low<=Encounter_date<=Survey_high,1,0);
if Encounter_started_in_Range>1 then washout_failed=1;
format Survey: grace: is8601da. Encounter_started_in_Range washout_failed yn.;
RUN;
- Cheers -
Hi,
try this:
data have;
input Person_ID :$10. Encounter_date :mmddyy10. Start_Date :mmddyy10.;
format Encounter_date Start_Date is8601da.;
datalines;
00006A7087 10/7/2021 4/5/2022
00006A7087 11/5/2021 4/5/2022
00006A7087 11/15/2021 4/5/2022
00006A7087 12/2/2021 4/5/2022
00006A7087 12/14/2021 4/5/2022
00006A7087 12/21/2021 4/5/2022
00006A7087 1/3/2022 4/5/2022
00006A7087 1/18/2022 4/5/2022
00006A7087 1/25/2022 4/5/2022
00006A7087 2/4/2022 4/5/2022
00006A7087 2/8/2022 4/5/2022
00006A7087 2/17/2022 4/5/2022
00006A7087 3/2/2022 4/5/2022
00006A7087 3/8/2022 4/5/2022
00006A7087 3/18/2022 4/5/2022
00006A7087 4/5/2022 4/5/2022
00006A7087 4/12/2022 4/5/2022
0000E20E92 1/28/2022 4/5/2022
0000E20E92 3/22/2022 4/5/2022
0000E20E92 4/5/2022 4/5/2022
0000E20E92 5/3/2022 4/5/2022
0000E20E92 5/17/2022 4/5/2022
0000E20E92 5/31/2022 4/5/2022
0000E20E92 7/15/2022 4/5/2022
0000E20E92 8/9/2022 4/5/2022
0000E20E92 10/19/2022 4/5/2022
0000E20E92 11/30/2022 4/5/2022
;
run;
PROC SORT; BY Person_ID Start_Date Encounter_date; RUN;
PROC FORMAT;
value yn
low-<0=' '
0='No'
1-high='Yes';
RUN;
DATA want;
SET have;
BY Person_ID Start_Date Encounter_date;
/*Encounter_date may be up to two weeks prior to intake survey date(start_Date) through 1 week after it*/
Survey_low=Start_Date-7;
Survey_high=Start_Date+7;
valid_encounter=put(ifn(Survey_low<=Encounter_date<=Survey_high,1,0),yn.);
/*We also need to apply a washout period. To qualify as an index encounter,
there must be no other encounters within 183 days prior to the 2 week grace period, up to two weeks before the index period.*/
grace_low=Start_Date-14-183;
grace_high=Start_Date+14;
retain Encounter_started_in_Range 0;
if first.Person_ID then Encounter_started_in_Range=0;
Encounter_started_in_Range=Encounter_started_in_Range+ifn(Survey_low<=Encounter_date<=Survey_high,1,0);
if Encounter_started_in_Range>1 then washout_failed=1;
format Survey: grace: is8601da. Encounter_started_in_Range washout_failed yn.;
RUN;
- Cheers -
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.