Hello all,
I’m a new sas user and I’m stuck.
I have a patient dataset with one line per patient and a dummy variable for each of 12 days. 1 is for when the patient has medication on hand and 0 when they do not.
What I would like is to identify patients who have a medication gap of 4 days or more, along with the starting date of this gap.
For example, patient A has such a gap that starts on day 4. Patient B has a gap of 2 days on days 2-3 but I’m only interested in their longer gap starting on day 8.
The only code I managed to come up with counted the total number of gap days per ID but that was inappropriate because I need to indentify patients who have a distinct gap >=4 days, and not patients who overall have missed medication more than 4 days over the period.
Any insight would be warmly appreciated ! Thank you
data have;
input ID $ day1 day2 day3 day4 day5 day6 day7 day8 day9 day10 day11 day12;
datalines ;
a 1 1 1 0 0 0 0 0 0 0 0 1
b 1 1 0 0 1 1 1 0 0 0 0 0
c 1 0 1 1 1 1 1 1 0 0 0 0
d 1 1 1 0 0 1 1 0 0 0 1 1
run;
data want;
input ID $ gap gap_date $;
datalines ;
a 1 day4
b 1 day8
c 1 day9
d 0
run;
data want;
set have;
start = index(cats(of day1-day12), '0000');
drop day1-day12;
run;
@Ju_Fr wrote:
Hello all,
I’m a new sas user and I’m stuck.
I have a patient dataset with one line per patient and a dummy variable for each of 12 days. 1 is for when the patient has medication on hand and 0 when they do not.
What I would like is to identify patients who have a medication gap of 4 days or more, along with the starting date of this gap.
For example, patient A has such a gap that starts on day 4. Patient B has a gap of 2 days on days 2-3 but I’m only interested in their longer gap starting on day 8.
The only code I managed to come up with counted the total number of gap days per ID but that was inappropriate because I need to indentify patients who have a distinct gap >=4 days, and not patients who overall have missed medication more than 4 days over the period.
Any insight would be warmly appreciated ! Thank you
data have;
input ID $ day1 day2 day3 day4 day5 day6 day7 day8 day9 day10 day11 day12;
datalines ;
a 1 1 1 0 0 0 0 0 0 0 0 1
b 1 1 0 0 1 1 1 0 0 0 0 0
c 1 0 1 1 1 1 1 1 0 0 0 0
d 1 1 1 0 0 1 1 0 0 0 1 1
run;
data want;
input ID $ gap gap_date $;
datalines ;
a 1 day4
b 1 day8
c 1 day9
d 0
run;
data want;
set have;
start = index(cats(of day1-day12), '0000');
drop day1-day12;
run;
@Ju_Fr wrote:
Hello all,
I’m a new sas user and I’m stuck.
I have a patient dataset with one line per patient and a dummy variable for each of 12 days. 1 is for when the patient has medication on hand and 0 when they do not.
What I would like is to identify patients who have a medication gap of 4 days or more, along with the starting date of this gap.
For example, patient A has such a gap that starts on day 4. Patient B has a gap of 2 days on days 2-3 but I’m only interested in their longer gap starting on day 8.
The only code I managed to come up with counted the total number of gap days per ID but that was inappropriate because I need to indentify patients who have a distinct gap >=4 days, and not patients who overall have missed medication more than 4 days over the period.
Any insight would be warmly appreciated ! Thank you
data have;
input ID $ day1 day2 day3 day4 day5 day6 day7 day8 day9 day10 day11 day12;
datalines ;
a 1 1 1 0 0 0 0 0 0 0 0 1
b 1 1 0 0 1 1 1 0 0 0 0 0
c 1 0 1 1 1 1 1 1 0 0 0 0
d 1 1 1 0 0 1 1 0 0 0 1 1
run;
data want;
input ID $ gap gap_date $;
datalines ;
a 1 day4
b 1 day8
c 1 day9
d 0
run;
Thank you @Reeza I did not know this function it works perfectly!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.