Hi,
I have a dataset with clients who had certain procedure performed over the 3 year time period. I need to flag those instances where 4 or more procedures took place outside the 180 day period for each client ID (status=flagged). Here is a sample data set.
ID | serv_dt | lag | PROCCD | proccdcnt | status |
217207401 | 3/22/2017 | 0 | 95951 | 4 | |
217207401 | 4/2/2018 | 376 | 95951 | 4 | |
217207401 | 4/3/2018 | 1 | 95951 | 4 | |
217207401 | 5/23/2018 | 50 | 95951 | 4 | |
220135502 | 11/4/2016 | 0 | 95951 | 4 | |
220135502 | 11/13/2016 | 9 | 95951 | 4 | |
220135502 | 11/14/2016 | 1 | 95951 | 4 | |
220135502 | 11/15/2016 | 1 | 95951 | 4 | flagged |
237287806 | 11/17/2017 | 0 | 95951 | 6 | |
237287806 | 11/18/2017 | 1 | 95951 | 6 | |
237287806 | 11/19/2017 | 1 | 95951 | 6 | |
237287806 | 10/28/2018 | 343 | 95951 | 6 | |
237287806 | 10/29/2018 | 1 | 95951 | 6 | |
237287806 | 10/30/2018 | 1 | 95951 | 6 | |
220462501 | 10/17/2018 | 0 | 95951 | 5 | |
220462501 | 10/18/2018 | 1 | 95951 | 5 | |
220462501 | 10/19/2018 | 1 | 95951 | 5 | |
220462501 | 10/20/2018 | 1 | 95951 | 5 | |
220462501 | 10/21/2018 | 1 | 95951 | 5 | flagged |
249892003 | 12/7/2016 | 0 | 95951 | 4 | |
249892003 | 12/8/2016 | 1 | 95951 | 4 | |
249892003 | 12/9/2016 | 1 | 95951 | 4 | |
249892003 | 12/10/2016 | 1 | 95951 | 4 | flagged |
257527503 | 4/14/2017 | 0 | 95951 | 6 | |
257527503 | 4/15/2017 | 1 | 95951 | 6 | |
257527503 | 5/28/2017 | 43 | 95951 | 6 | |
257527503 | 7/18/2018 | 416 | 95951 | 6 | |
257527503 | 7/19/2018 | 1 | 95951 | 6 | |
257527503 | 7/20/2018 | 1 | 95951 | 6 | |
219482501 | 8/30/2016 | 0 | 95951 | 11 | |
219482501 | 8/31/2016 | 1 | 95951 | 11 | |
219482501 | 9/1/2016 | 1 | 95951 | 11 | |
219482501 | 9/2/2016 | 1 | 95951 | 11 | flagged |
219482501 | 9/3/2016 | 1 | 95951 | 11 | flagged |
219482501 | 9/4/2016 | 1 | 95951 | 11 | flagged |
219482501 | 9/5/2016 | 1 | 95951 | 11 | flagged |
219482501 | 9/6/2016 | 1 | 95951 | 11 | flagged |
219482501 | 9/7/2016 | 1 | 95951 | 11 | flagged |
219482501 | 9/8/2016 | 1 | 95951 | 11 | flagged |
219482501 | 9/9/2016 | 1 | 95951 | 11 | flagged |
So, for example, the first ID=217207401 will not be flagged. But the second, id=220135502 will be flagged as there were 4 procedures done in less than 180 days.
I understand that there should probably be some way of using a macro to count within each ID group the number of days for the consequitive 4 observations, and flag them when it's more than 180. But I'm not sure how to do that as teh number of rows for each ID is different. Any help or advice would be appreciated.
Thank you!
Macros and macro variables are most definitely not needed, and not worth the complication.
Just sort by ID and serv_dt and then (assuming serv_dt is really a SAS date and not a character string).
data want;
set have;
prev_id=lag3(id);
prev_dt=lag3(serv_dt);
if prev_id=id and serv_dt-prev_dt<180 then status='flagged';
run;
Macros and macro variables are most definitely not needed, and not worth the complication.
Just sort by ID and serv_dt and then (assuming serv_dt is really a SAS date and not a character string).
data want;
set have;
prev_id=lag3(id);
prev_dt=lag3(serv_dt);
if prev_id=id and serv_dt-prev_dt<180 then status='flagged';
run;
Thank you so much!! It worked great and I understand the logic behind it. Thank you!!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.