BookmarkSubscribeRSS Feed
JDonovan
Calcite | Level 5

I am looking for some help on creating a macro that will identify continuous enrollment with a given gap. For example, we will allow a month gap and still allow continuous enrollment. The data structure I have is....

 

Memb_id enroll_yrmo (number - not date) 

1 201701

1 201702

1 201703

1 201704

1 201705

...

1 201712

 

I have done this before but it was with from and thru dates with a single record per member. Now, I have a record for every month and it isn't even a date. It is a number. I would love your help and input. 

 

1 REPLY 1
Astounding
PROC Star

Here's one approach, assuming your data set is already sorted:

 

data want;

set have;

by memb_id;

dif_date = dif(enroll_yrmo);

month = mod(enroll_yrmo, 100);

if first.memb_id then do;

   group=1;

   return;

end;

if month > 1 and dif_date=1 then return;

if month=1 and dif_date=89 then return;

group + 1;

run;

 

Since you described the result, but didn't illustrate it, here's what this is doing.  It assumes that a "gap" means that a year/month is missing from the sequence (for the same value of MEMB_ID).  It creates a new variable (GROUP) that is 1 for the first set of sequential observations, but increases whenever a gap is found.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 830 views
  • 0 likes
  • 2 in conversation