🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Calcite | Level 5

## Identifying patients with gaps in medication longer than a set length of days

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Identifying patients with gaps in medication longer than a set length of days

``````
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;

2 REPLIES 2
Super User

## Re: Identifying patients with gaps in medication longer than a set length of days

``````
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;

Calcite | Level 5

## Re: Identifying patients with gaps in medication longer than a set length of days

Thank you @Reeza I did not know this function it works perfectly!

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