<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Roll up monthly enrollment data and create continuous enrollment segment in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491449#M128884</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;Yes, the code needed some minor changes, to reflect the difference in the input data. Also it needed a change to cope with multiple patient_id&amp;nbsp;&lt;BR /&gt;Here's updated code, I think this should do what you are looking for&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source ;
	infile cards ;
	input pid $ start :mmddyy. end :mmddyy. ;
	format start date9. end date9. ;
cards ;
00001      01/01/2018      01/31/2018       
00001      02/01/2018      02/28/2018         
00001      04/01/2018      04/30/2018      
00001      05/01/2018      05/21/2018    
00001      05/15/2018      05/31/2018   
00002      01/01/2018      01/31/2018       
00002      02/01/2018      02/28/2018         
00002      04/01/2018      04/30/2018      
00002      05/01/2018      05/31/2018    
00002      05/15/2018      05/20/2018   
;
run ;

proc sort ;
	by pid start end ;
run ;

data output ;
	retain start_date end_date ;
	format start_date date9. end_date date9. ;
	set source ;
	by pid start end ;
	if first.pid=1 then do ;
		start_date=start ;
		end_date=end ;
	end ;
	else do ;
		if start&amp;gt;end_date+1 then do ;
			output ;
			start_date=start ;
			end_date=end ;
		end ;
		else if end&amp;gt;end_date then do ;
			end_date=end ;
		end ;
	end ;
	if last.pid then
		output ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Aug 2018 22:01:37 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2018-08-30T22:01:37Z</dc:date>
    <item>
      <title>Roll up monthly enrollment data and create continuous enrollment segment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491241#M128774</link>
      <description>&lt;DIV class="lia-message-heading lia-component-message-header"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="messagebodydisplay_0" class="lia-message-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have monthly enrollment data and would like to roll them up into continuous enrollment segments. Note that some overlap in monthly enrollment data can happen because they are from different sources. I tried to create a date variable, that is, do date=start to end (30&amp;nbsp;lines if monthly enrollment is Sep01 to Sep30) and check if dif(date)&amp;gt;1 for triggering discontinuation of&amp;nbsp;current enrollment. However, my data set gets extremely large (300B obs) and run time is several hours. I would appreciate if anyone could provide a much efficient approach to tackle this. An example of data input and desired output are shown below. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data input&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PatientID&amp;nbsp; Start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;00001&amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; 01/31/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;00001&amp;nbsp; &amp;nbsp; &amp;nbsp; 02/01/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; 02/28/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;00001&amp;nbsp; &amp;nbsp; &amp;nbsp; 04/01/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; 04/30/2018&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;00001&amp;nbsp; &amp;nbsp; &amp;nbsp; 05/01/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; 05/20/2018&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;00001&amp;nbsp; &amp;nbsp; &amp;nbsp; 05/&lt;FONT color="#FF0000"&gt;15&lt;/FONT&gt;/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; 05/31/2018&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Output&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PatientID&amp;nbsp; Start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;00001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2018&amp;nbsp; &amp;nbsp; 02/28/2018&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;00001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;04/01/2018&amp;nbsp; &amp;nbsp; 05/31/2018&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 30 Aug 2018 13:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491241#M128774</guid>
      <dc:creator>buszhangsy</dc:creator>
      <dc:date>2018-08-30T13:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Roll up monthly enrollment data and create continuous enrollment segment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491341#M128833</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;This can be achieved by using the retain statement and&amp;nbsp;only outputting when there's a gap in the dates&lt;BR /&gt;&lt;BR /&gt;Here's an example using your sample data:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;data source ;
	infile cards ;
	input pid $ start :mmddyy. end :mmddyy. ;
	format start date9. end date9. ;
cards ;
00001      01/01/2018      01/31/2018       
00001      02/01/2018      02/28/2018         
00001      04/01/2018      04/30/2018      
00001      05/01/2018      05/20/2018    
00001      05/15/2018      05/31/2018   
;
run ;

data output ;
	retain start_date end_date ;
	format start_date date9. end_date date9. ;
	set source end=eof ;
	if _n_=1 then do ;
		start_date=start ;
		end_date=end ;
	end ;
	else do ;
		if start&amp;gt;end_date+1 then do ;
			output ;
			start_date=start ;
			end_date=end ;
		end ;
		else do ;
			end_date=end ;
		end ;
	end ;
	if eof then
		output ;
run ;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Aug 2018 17:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491341#M128833</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2018-08-30T17:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Roll up monthly enrollment data and create continuous enrollment segment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491371#M128842</link>
      <description>&lt;P&gt;Thanks AMSAS! I do have a question. There will be some time periods with overlaps (see below for another example), how should I sort the dataset in order to use the code you provided? As you can see, when SAS processes the last record, it will keep the start_date previously stored but reassign end_date to be 05/20/2018, which is supposed to be 05/31/2018.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;00001      01/01/2018      01/31/2018       
00001      02/01/2018      02/28/2018         
00001      04/01/2018      04/30/2018      
00001      05/01/2018      05/31/2018    
00001      &lt;FONT color="#FF0000"&gt;05/15/2018      05/20/2018   &lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 18:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491371#M128842</guid>
      <dc:creator>buszhangsy</dc:creator>
      <dc:date>2018-08-30T18:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: Roll up monthly enrollment data and create continuous enrollment segment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491449#M128884</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;Yes, the code needed some minor changes, to reflect the difference in the input data. Also it needed a change to cope with multiple patient_id&amp;nbsp;&lt;BR /&gt;Here's updated code, I think this should do what you are looking for&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source ;
	infile cards ;
	input pid $ start :mmddyy. end :mmddyy. ;
	format start date9. end date9. ;
cards ;
00001      01/01/2018      01/31/2018       
00001      02/01/2018      02/28/2018         
00001      04/01/2018      04/30/2018      
00001      05/01/2018      05/21/2018    
00001      05/15/2018      05/31/2018   
00002      01/01/2018      01/31/2018       
00002      02/01/2018      02/28/2018         
00002      04/01/2018      04/30/2018      
00002      05/01/2018      05/31/2018    
00002      05/15/2018      05/20/2018   
;
run ;

proc sort ;
	by pid start end ;
run ;

data output ;
	retain start_date end_date ;
	format start_date date9. end_date date9. ;
	set source ;
	by pid start end ;
	if first.pid=1 then do ;
		start_date=start ;
		end_date=end ;
	end ;
	else do ;
		if start&amp;gt;end_date+1 then do ;
			output ;
			start_date=start ;
			end_date=end ;
		end ;
		else if end&amp;gt;end_date then do ;
			end_date=end ;
		end ;
	end ;
	if last.pid then
		output ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 22:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Roll-up-monthly-enrollment-data-and-create-continuous-enrollment/m-p/491449#M128884</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2018-08-30T22:01:37Z</dc:date>
    </item>
  </channel>
</rss>

