Solved
New Contributor
Posts: 3

# 3 month continuous eligibilities

Hi everyone, need help coding whether the individual has been there 3 months back to back(jan-mar or feb-apr) for the year. If there are gaps, dont pull include this individuals.  Example below: Individual AA is there from jan-mar contionously so we include him, individual BB has gap so dont include him. Could someone provide any ideas which may help

Individual  Date
AA  1/1/2016
AA  2/1/2016
AA  3/1/2016
AA  4/1/2016
AA  7/1/2016
AA  8/1/2016
AA  12/1/2016
BB  2/1/2016
BB  4/1/2016
BB  5/1/2016
BB  7/1/2016
BB  8/1/2016
CC 6/1/2016
CC 7/1/2016
CC 8/1/2016

Accepted Solutions
Solution
‎01-06-2017 06:29 PM
Super Contributor
Posts: 268

## Re: 3 month continuous eligibilities

If your requirement is that the individual should have had three contiguous months, ever, then this will work:

``````data source;
infile cards;
attrib individual length=\$ 2;
attrib date informat=mmddyy10. format=monyy7.;
input individual
date;
cards;
AA  1/1/2016
AA  2/1/2016
AA  3/1/2016
AA  4/1/2016
AA  7/1/2016
AA  8/1/2016
AA  12/1/2016
BB  2/1/2016
BB  4/1/2016
BB  5/1/2016
BB  7/1/2016
BB  8/1/2016
CC 6/1/2016
CC 7/1/2016
CC 8/1/2016
;
run;

data result;
set source;
by individual;
attrib save_date length=4 format=monyy7.;
retain count save_date;
if first.individual
then do;
count = 1;                               /* On the first time, there will always be one! */
call missing(save_date);
end;
else do;
if intck('month', save_date, date) = 1   /* Is there a one-month gap? */
then count + 1;                       /* Increment */
else count = 1;                       /* Otherwise reset */
end;
save_date = date;                                /* Save the current observation's date */
if last.individual or count ge 3;                /* Last in the group, or continuous */
if count < 3
then status = 0;
else status = 1;
keep individual status;
run;

proc sql;
create table result_summ as
select individual,
ifc(max(status) = 1, 'continuous', 'non-continuous') as status_text length=14
from result
group by individual;
quit;``````

Note that it requires two passes - one to flag any three continuous months as 1 (or 0 if they're not contiguous), then the sql pass to get the maximum value of the status. The ifc function returns either of the two text strings, depending on the truth of the condition.

Looking at AA: there are three sets of months, Jan/Mar, Feb/Apr and the last three (non-continuous). This creates three observations in result, the first pass, with respective values in status of 11 and 0.

All Replies
Super User
Posts: 13,583

## Re: 3 month continuous eligibilities

It helps to show what the expected output would look like.

New Contributor
Posts: 3

## Re: 3 month continuous eligibilities

If the desired output could be similiar to this, that would be awesome.

Individual Type

AA continuous

BB not_continuous

CC continuous

Solution
‎01-06-2017 06:29 PM
Super Contributor
Posts: 268

## Re: 3 month continuous eligibilities

If your requirement is that the individual should have had three contiguous months, ever, then this will work:

``````data source;
infile cards;
attrib individual length=\$ 2;
attrib date informat=mmddyy10. format=monyy7.;
input individual
date;
cards;
AA  1/1/2016
AA  2/1/2016
AA  3/1/2016
AA  4/1/2016
AA  7/1/2016
AA  8/1/2016
AA  12/1/2016
BB  2/1/2016
BB  4/1/2016
BB  5/1/2016
BB  7/1/2016
BB  8/1/2016
CC 6/1/2016
CC 7/1/2016
CC 8/1/2016
;
run;

data result;
set source;
by individual;
attrib save_date length=4 format=monyy7.;
retain count save_date;
if first.individual
then do;
count = 1;                               /* On the first time, there will always be one! */
call missing(save_date);
end;
else do;
if intck('month', save_date, date) = 1   /* Is there a one-month gap? */
then count + 1;                       /* Increment */
else count = 1;                       /* Otherwise reset */
end;
save_date = date;                                /* Save the current observation's date */
if last.individual or count ge 3;                /* Last in the group, or continuous */
if count < 3
then status = 0;
else status = 1;
keep individual status;
run;

proc sql;
create table result_summ as
select individual,
ifc(max(status) = 1, 'continuous', 'non-continuous') as status_text length=14
from result
group by individual;
quit;``````

Note that it requires two passes - one to flag any three continuous months as 1 (or 0 if they're not contiguous), then the sql pass to get the maximum value of the status. The ifc function returns either of the two text strings, depending on the truth of the condition.

Looking at AA: there are three sets of months, Jan/Mar, Feb/Apr and the last three (non-continuous). This creates three observations in result, the first pass, with respective values in status of 11 and 0.

New Contributor
Posts: 3

## Re: 3 month continuous eligibilities

@LaurieF:
Thank you so much, this works perfectly
☑ This topic is solved.