BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mauri0623
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

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 -

View solution in original post

2 REPLIES 2
Oligolas
Barite | Level 11

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 -

mauri0623
Quartz | Level 8
Thank you. I appreciate your time. Obviously, you are a very versed programmer. If it is OK I would like to contact you about this. I still have other part of this that I also need a little help with. I however do not want to be demanding. Just if you have a few minutes that you can spare. Any day or any time will be fine. Hope you have a blast weekend. Thank you again.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 783 views
  • 0 likes
  • 2 in conversation