BookmarkSubscribeRSS Feed
stellapersis7
Obsidian | Level 7

Hi all

I have a dataset like this 

ID    startdate         enddate

AA.  01/01/2014   01/31/2014

AA.   02/01/2014 02/28/2014

AA.    03/01/2014   03/31/2014

AA.     09/01/2014.    09/30/2014

AA.     10/01/2014.      10/31/2014

AA.     11/01/2014.       11/30/2014

AA.     12/01/2014.       12/31/2014

 

I am evaluating continuous eligibility for patients in a dataset

 

I want the results like this

ID    startdate         enddate

AA.  01/01/2014    01/31/2014

AA.   09/01/2014    12/31/2014

 

how do i do this.

Thank you

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Please explain in words (and also provide examples) of what is considered "continuous enrollment" and what is not considered "continuous enrollment". Why are January and February and March not considered "continuous enrollment"?

--
Paige Miller
ballardw
Super User

Are you sure that your "want" isn't more like:

ID    startdate         enddate
AA.  01/01/2014    03/31/2014
AA.   09/01/2014    12/31/2014

If there are any other variables in the data set you need to tell us what to do with them.

 

You should provide example data as a working data step so we don't have to ask questions like are startdate and enddate actual date values with what appears to be the MMDDYY10 format assigned or are they character values?

 

 


@stellapersis7 wrote:

Hi all

I have a dataset like this 

ID    startdate         enddate

AA.  01/01/2014   01/31/2014

AA.   02/01/2014 02/28/2014

AA.    03/01/2014   03/31/2014

AA.     09/01/2014.    09/30/2014

AA.     10/01/2014.      10/31/2014

AA.     11/01/2014.       11/30/2014

AA.     12/01/2014.       12/31/2014

 

I am evaluating continuous eligibility for patients in a dataset

 

I want the results like this

ID    startdate         enddate

AA.  01/01/2014    01/31/2014

AA.   09/01/2014    12/31/2014

 

how do i do this.

Thank you


 

stellapersis7
Obsidian | Level 7

Screen Shot 2023-10-11 at 10.20.56.png

So these are the variables, all the dates are in SAS dates. This is an example data set. so the patients start and end variables are first date and last date of respective month. CP variable is-  if they are enrolled for that month, its coded as 1 and 0 if not enrolled. I need to combine all the months they are eligible into single start and end date. For example if a person is eligible from jan1 to april 1 and again between august first and dec 31, i need that to be captured in a seperate variables like new_start and new_end showing the  2 new start dates and end dates for each member id. if a person is continuously enrolled from jan  to dec then he will have a single new_start as 01jan and new_end as 31dec.

Thank you

mkeintz
PROC Star

@stellapersis7 wrote:

Hi all

I have a dataset like this 

ID    startdate         enddate

AA.  01/01/2014   01/31/2014

AA.   02/01/2014 02/28/2014

AA.    03/01/2014   03/31/2014

AA.     09/01/2014.    09/30/2014

AA.     10/01/2014.      10/31/2014

AA.     11/01/2014.       11/30/2014

AA.     12/01/2014.       12/31/2014

 

I am evaluating continuous eligibility for patients in a dataset

 

I want the results like this

ID    startdate         enddate

AA.  01/01/2014    01/31/2014

AA.   09/01/2014    12/31/2014

 

how do i do this.

Thank you


Assuming you really want enddate=03/31/2014 for the first observation in your expected output, then:

 

data want (drop=nxt_:);
  merge have 
        have (firstobs=2 keep=id startdate rename=(id=nxt_id startdate=nxt_start));

  retain new_start;
format new_start new_end mmddyy10. ; if id^=lag(id) or startdate-1 > lag(enddate) then new_start=startdate; if id^=nxt_id or enddate+1 < nxt_start; new_end=enddate; run;

This code compares the current start to the preceding end (and current ID to preceding ID), to establish whether a new continuous period is starting. 

 

Then, using the firstobs=2 option in one of the MERGE datasets, it compares the current end to the next start, and current id vs next id, to establish whether the end of a continuous period has been reached.

 

The program is untested in the absence of sample data in the form of a working data step.  It assumes that startdate and enddate are stored as SAS date values.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

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
  • 4 replies
  • 830 views
  • 0 likes
  • 4 in conversation