<?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: How to split date range with startdate / enddate and combine program? in Advanced Programming</title>
    <link>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901999#M240</link>
    <description>&lt;P&gt;The solution is fine for the overlap dates. If we have dates without overlap like for New York, we got the start date as 01/01/2010 and the end date as 03/01/2011. But we do not have any program from 03/02/2010 to 12/31/2010 and there should be a separate line for this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have added one more line for New York on the previous dataset.&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input State $ city $ (Stdt endt)(:mmddyy10.) Treatment $;&lt;/P&gt;&lt;P&gt;format Stdt endt mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;NY NeyYork 01/01/2010 03/01/2010 Dialysis&lt;/P&gt;&lt;P&gt;NY NeyYork 01/01/2011 03/01/2011 Dialysis&lt;BR /&gt;MD Baltimore 01/01/2011 08/01/2011 Dialysis&lt;BR /&gt;MD Baltimore 02/01/2011 12/01/2011 Heart&lt;BR /&gt;MD Baltimore 03/02/2011 02/14/2015 Urine&lt;BR /&gt;MD Baltimore 04/15/2011 01/14/2015 Dialysis&lt;BR /&gt;MD Baltimore 02/01/2011 05/01/2011 Knee&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to split the data by start date/ end date and group treatment based on the date range.&lt;/P&gt;&lt;P&gt;Expected output are as follows.&lt;/P&gt;&lt;P&gt;State City Stdt endt treatment&lt;BR /&gt;NY NeyYork 1/1/2010 3/1/2010 Dialysis&lt;BR /&gt;NY NeyYork 1/1/2011 3/1/2011 Dialysis&lt;BR /&gt;MD Baltimore 1/1/2011 1/31/2011 Dialysis&lt;BR /&gt;MD Baltimore 2/1/2011 3/1/2011 Dialysis/Heart/Knee&lt;BR /&gt;MD Baltimore 3/2/2011 5/1/2011 Dialysis/Heart/Knee/Urine&lt;BR /&gt;MD Baltimore&amp;nbsp;5/2/2011 12/1/2011 Dialysis/Heart/Urine&lt;BR /&gt;MD Baltimore 12/2/2011 1/14/2015 Dialysis/Urine&lt;BR /&gt;MD Baltimore 1/15/2015 2/14/2015 Urine&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic is group all the treatment within that date range. First date range for Baltimore is 01/01/2011 to 08/01/2011 and treatment is Dialysis. Between 01/01/2011 to 08/01/2011 date range there are other start dates with different end dates and treatment like 02/01/2011, 03/02/2011, 04/15/2011, 02/01/2011.&lt;/P&gt;&lt;P&gt;Main logic is to group the treatment on specific date:- if we pick the random date 07/03/2011 for Baltimore then we have the Dialysis/Heart/Knee as treatment.&lt;/P&gt;&lt;P&gt;if we pick the random date as 09/01/2011 for Baltimore then we have the Heart/Urine/Dialysis as treatment.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2023 03:14:57 GMT</pubDate>
    <dc:creator>AnimaCh44</dc:creator>
    <dc:date>2023-11-08T03:14:57Z</dc:date>
    <item>
      <title>How to split date range with startdate / enddate and combine program?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901551#M235</link>
      <description>&lt;P&gt;I have the following dataset.&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input State $ city $ (Stdt endt)(:mmddyy10.) Treatment $;&lt;/P&gt;&lt;P&gt;format Stdt endt mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;NY NeyYork 01/01/2010 03/01/2010 Dialysis&lt;BR /&gt;MD Baltimore 01/01/2011 08/01/2011 Dialysis&lt;BR /&gt;MD Baltimore 02/01/2011 12/01/2011 Heart&lt;BR /&gt;MD Baltimore 03/02/2011 02/14/2015 Urine&lt;BR /&gt;MD Baltimore 04/15/2011 01/14/2015 Dialysis&lt;BR /&gt;MD Baltimore 02/01/2011 05/01/2011 Knee&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to split the data by start date/ end date and group treatment based on the date range.&lt;/P&gt;&lt;P&gt;Expected output are as follows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;State City&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Stdt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; endt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; treatment&lt;BR /&gt;NY&amp;nbsp; &amp;nbsp; &amp;nbsp;NeyYork&amp;nbsp; &amp;nbsp;1/1/2010 3/1/2010 Dialysis&lt;BR /&gt;MD&amp;nbsp; &amp;nbsp; Baltimore 1/1/2011 1/31/2011 Dialysis&lt;BR /&gt;MD&amp;nbsp; &amp;nbsp; Baltimore 2/1/2011 3/1/2011 Dialysis/Heart/Knee&lt;BR /&gt;MD&amp;nbsp; &amp;nbsp; Baltimore 3/2/2011 5/1/2011 Dialysis/Heart/Knee/Urine&lt;BR /&gt;MD&amp;nbsp; &amp;nbsp; Baltimore 5/2/2011 8/1/2011 Dialysis/Heart/Urine&lt;BR /&gt;MD&amp;nbsp; &amp;nbsp; Baltimore 8/2/2011 12/1/2011 Dialysis/Heart/Urine&lt;BR /&gt;MD&amp;nbsp; &amp;nbsp; Baltimore 12/2/2011 1/14/2015 Dialysis/Urine&lt;BR /&gt;MD&amp;nbsp; &amp;nbsp; Baltimore 1/15/2015 2/14/2015 Urine&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic is group all the treatment within that date range. First date range for Baltimore is&amp;nbsp;01/01/2011 to 08/01/2011 and treatment is Dialysis. Between&amp;nbsp;01/01/2011 to 08/01/2011 date range there are other start dates with different end dates and treatment like&amp;nbsp;02/01/2011,&amp;nbsp;03/02/2011,&amp;nbsp;04/15/2011,&amp;nbsp;02/01/2011.&lt;/P&gt;&lt;P&gt;Main logic is to group the treatment on specific date:- if we pick the random date 07/03/2011 for Baltimore then we have the&amp;nbsp;Dialysis/Heart/Knee as treatment.&lt;/P&gt;&lt;P&gt;if we pick the random date as 09/01/2011 for Baltimore then we have the Heart/Urine/Dialysis as treatment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Nov 2023 15:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901551#M235</guid>
      <dc:creator>AnimaCh44</dc:creator>
      <dc:date>2023-11-04T15:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to split date range with startdate / enddate and combine program?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901556#M236</link>
      <description>&lt;P&gt;Please explain the logic here. What are the steps that take you from the input data to the output data?&lt;/P&gt;</description>
      <pubDate>Sat, 04 Nov 2023 14:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901556#M236</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-04T14:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to split date range with startdate / enddate and combine program?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901558#M237</link>
      <description>&lt;P&gt;I have added the logic on main post.&lt;BR /&gt;The logic is group all the treatment within that date range. First date range for Baltimore is 01/01/2011 to 08/01/2011 and treatment is Dialysis. Between 01/01/2011 to 08/01/2011 date range there are other start dates with different end dates and treatment like 02/01/2011, 03/02/2011, 04/15/2011, 02/01/2011.&lt;BR /&gt;&lt;BR /&gt;Main logic is to group the treatment on specific date:- if we pick the random date 07/03/2011 for Baltimore then we have the Dialysis/Heart/Knee as treatment.&lt;BR /&gt;&lt;BR /&gt;if we pick the random date as 09/01/2011 for Baltimore then we have the Heart/Urine/Dialysis as treatment.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Nov 2023 15:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901558#M237</guid>
      <dc:creator>AnimaCh44</dc:creator>
      <dc:date>2023-11-04T15:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to split date range with startdate / enddate and combine program?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901663#M238</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input State $ city $ (Stdt endt)(:mmddyy10.) Treatment $;

format Stdt endt mmddyy10.;
datalines;
NY NeyYork 01/01/2010 03/01/2010 Dialysis
MD Baltimore 01/01/2011 08/01/2011 Dialysis
MD Baltimore 02/01/2011 12/01/2011 Heart
MD Baltimore 03/02/2011 02/14/2015 Urine
MD Baltimore 04/15/2011 01/14/2015 Dialysis
MD Baltimore 02/01/2011 05/01/2011 Knee
;
run;

data temp;
 set have;
 do date=Stdt to endt;
  output;
 end;
 format date mmddyy10.;
 drop Stdt endt;
run;

proc sort data=temp nodupkey;by  State  city date Treatment;run;

data temp2;
 do until(last.date);
   set temp;
   by  State  city date;
   length Treatments $ 100;
   Treatments=catx('/',Treatments,Treatment);
 end;
 drop Treatment;
run;

data want;
 set temp2;
 by State  city Treatments notsorted;
 retain Stdt ;
 if first.Treatments then Stdt=date;
 if last.Treatments then do;endt=date;output;end;
 format Stdt endt mmddyy10.;
 drop date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1699237244927.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89437iBBF1690EC5398423/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1699237244927.png" alt="Ksharp_0-1699237244927.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2023 02:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901663#M238</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-11-06T02:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to split date range with startdate / enddate and combine program?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901879#M239</link>
      <description>&lt;P&gt;Thank you for the solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 13:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901879#M239</guid>
      <dc:creator>AnimaCh44</dc:creator>
      <dc:date>2023-11-07T13:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to split date range with startdate / enddate and combine program?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901999#M240</link>
      <description>&lt;P&gt;The solution is fine for the overlap dates. If we have dates without overlap like for New York, we got the start date as 01/01/2010 and the end date as 03/01/2011. But we do not have any program from 03/02/2010 to 12/31/2010 and there should be a separate line for this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have added one more line for New York on the previous dataset.&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input State $ city $ (Stdt endt)(:mmddyy10.) Treatment $;&lt;/P&gt;&lt;P&gt;format Stdt endt mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;NY NeyYork 01/01/2010 03/01/2010 Dialysis&lt;/P&gt;&lt;P&gt;NY NeyYork 01/01/2011 03/01/2011 Dialysis&lt;BR /&gt;MD Baltimore 01/01/2011 08/01/2011 Dialysis&lt;BR /&gt;MD Baltimore 02/01/2011 12/01/2011 Heart&lt;BR /&gt;MD Baltimore 03/02/2011 02/14/2015 Urine&lt;BR /&gt;MD Baltimore 04/15/2011 01/14/2015 Dialysis&lt;BR /&gt;MD Baltimore 02/01/2011 05/01/2011 Knee&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to split the data by start date/ end date and group treatment based on the date range.&lt;/P&gt;&lt;P&gt;Expected output are as follows.&lt;/P&gt;&lt;P&gt;State City Stdt endt treatment&lt;BR /&gt;NY NeyYork 1/1/2010 3/1/2010 Dialysis&lt;BR /&gt;NY NeyYork 1/1/2011 3/1/2011 Dialysis&lt;BR /&gt;MD Baltimore 1/1/2011 1/31/2011 Dialysis&lt;BR /&gt;MD Baltimore 2/1/2011 3/1/2011 Dialysis/Heart/Knee&lt;BR /&gt;MD Baltimore 3/2/2011 5/1/2011 Dialysis/Heart/Knee/Urine&lt;BR /&gt;MD Baltimore&amp;nbsp;5/2/2011 12/1/2011 Dialysis/Heart/Urine&lt;BR /&gt;MD Baltimore 12/2/2011 1/14/2015 Dialysis/Urine&lt;BR /&gt;MD Baltimore 1/15/2015 2/14/2015 Urine&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic is group all the treatment within that date range. First date range for Baltimore is 01/01/2011 to 08/01/2011 and treatment is Dialysis. Between 01/01/2011 to 08/01/2011 date range there are other start dates with different end dates and treatment like 02/01/2011, 03/02/2011, 04/15/2011, 02/01/2011.&lt;/P&gt;&lt;P&gt;Main logic is to group the treatment on specific date:- if we pick the random date 07/03/2011 for Baltimore then we have the Dialysis/Heart/Knee as treatment.&lt;/P&gt;&lt;P&gt;if we pick the random date as 09/01/2011 for Baltimore then we have the Heart/Urine/Dialysis as treatment.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 03:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/901999#M240</guid>
      <dc:creator>AnimaCh44</dc:creator>
      <dc:date>2023-11-08T03:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to split date range with startdate / enddate and combine program?</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/902007#M241</link>
      <description>&lt;P&gt;OK. I did not take into account of this scenario .&lt;/P&gt;
&lt;P&gt;Try this one :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input State $ city $ (Stdt endt)(:mmddyy10.) Treatment $;
format Stdt endt mmddyy10.;
datalines;
NY NeyYork 01/01/2010 03/01/2010 Dialysis
NY NeyYork 01/01/2011 03/01/2011 Dialysis
MD Baltimore 01/01/2011 08/01/2011 Dialysis
MD Baltimore 02/01/2011 12/01/2011 Heart
MD Baltimore 03/02/2011 02/14/2015 Urine
MD Baltimore 04/15/2011 01/14/2015 Dialysis
MD Baltimore 02/01/2011 05/01/2011 Knee
;
run;

data temp;
 set have;
 do date=Stdt to endt;
  output;
 end;
 format date mmddyy10.;
 drop Stdt endt;
run;

proc sort data=temp nodupkey;by  State  city date Treatment;run;

data temp2;
 do until(last.date);
   set temp;
   by  State  city date;
   length Treatments $ 100;
   Treatments=catx('/',Treatments,Treatment);
 end;
 drop Treatment;
run;

data temp3;
 set temp2;
 by State  city Treatments notsorted;
 if first.Treatments or dif(date) ne 1 then group+1;
run;
data want;
 set temp3;
 by group;
 retain Stdt ;
 if first.group then Stdt=date;
 if last.group then do;endt=date;output;end;
 format Stdt endt mmddyy10.;
 drop date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 05:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-split-date-range-with-startdate-enddate-and-combine/m-p/902007#M241</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-11-08T05:39:16Z</dc:date>
    </item>
  </channel>
</rss>

