<?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: Break a Date Range Into Multiple Lines in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635372#M188643</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;:). You are correct, I missed that. This looks to be doing exactly what I want it to. Thank you so much. I'm just going to break out the active calculation I was referring to in the previous thread into a different step in my process, this was the part I was struggling with. Appreciate you sticking with me despite some of my example problem issues.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Mar 2020 15:55:11 GMT</pubDate>
    <dc:creator>A_SAS_Man</dc:creator>
    <dc:date>2020-03-27T15:55:11Z</dc:date>
    <item>
      <title>Break a Date Range Into Multiple Lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635324#M188633</link>
      <description>&lt;P&gt;I am asking a question related to a previous question I asked here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Convert-Monthly-Data-set-to-Weekly-and-Check-for-Active-Status/m-p/635155#M188561" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Convert-Monthly-Data-set-to-Weekly-and-Check-for-Active-Status/m-p/635155#M188561&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I am trying to make the question clearer and easier to answer. Let me first start with the example data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input person $1. start_date:mmddyy10. end_date:mmddyy10.;
 format start_date date9. end_date date9.;
 datalines;
1 01/13/2019 01/19/2019
1 02/02/2019 02/28/2019
1 03/01/2019 03/28/2019
2 02/01/2019 02/28/2019
 ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I would like to do is break out every line into every week that date range touches. See below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data want;
 input person $1. start_date:mmddyy10. end_date:mmddyy10. week_start:mmddyy10. week_number 2.0;
 format start_date date9. end_date date9.;
 datalines;
1 01/13/2019 01/19/2019 01/13/2019 2
1 02/02/2019 02/28/2019 01/27/2019 4
1 02/02/2019 02/28/2019 02/03/2019 5
1 02/02/2019 02/28/2019 02/10/2019 6
1 02/02/2019 02/28/2019 02/17/2019 7
1 02/02/2019 02/28/2019 02/24/2019 8
1 03/01/2019 03/06/2019 02/24/2019 8
1 03/01/2019 03/06/2019 03/03/2019 9
2 02/02/2019 02/28/2019 01/27/2019 4
2 02/02/2019 02/28/2019 02/03/2019 5
2 02/02/2019 02/28/2019 02/10/2019 6
2 02/02/2019 02/28/2019 02/17/2019 7
2 02/02/2019 02/28/2019 02/24/2019 8
 ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The date ranges should be consistent across people, i.e., the same start dates should have the same week numbers. The week_start field should be consistent with what you would get if you put the a date from that week into the week formula. See below for how I derived week_number&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table week_number_check as
	select *,
		   week(week_start) as Week_Number_Check
	from want
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The week start dates should be consistent with how intx would calculate a the first day of the week for a given date, with the week starting on Sunday. Please let me know if this clarification.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a summary, it seems like some looping logic is needed with the following steps.&lt;/P&gt;&lt;P&gt;1. Check the start_date, derive the first day of the week for that date&lt;/P&gt;&lt;P&gt;2. Check the end_date, derive the first day of the week for that date&lt;/P&gt;&lt;P&gt;3. Calculate how many weeks are included in the start_date end_date range (inclusive) and break out the single data line into that many lines, i.e, one for each week.&lt;/P&gt;&lt;P&gt;4. Use week() to calculate week number for each element.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if this needs clarification.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 14:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635324#M188633</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2020-03-27T14:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Break a Date Range Into Multiple Lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635369#M188642</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/234586"&gt;@A_SAS_Man&lt;/a&gt;&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; It seems you didn't account for&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;1 03/01/2019 03/28/2019&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in your WANT for Person1 output?&lt;/P&gt;
&lt;P&gt;Though this seems much too easy&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
 input person $1. start_date:mmddyy10. end_date:mmddyy10.;
 format start_date date9. end_date date9.;
 datalines;
1 01/13/2019 01/19/2019
1 02/02/2019 02/28/2019
1 03/01/2019 03/28/2019
2 02/01/2019 02/28/2019
 ;
 run;


data want;
 do until(last.person);
  set have;
  by person;
  week_start=intnx('week',start_date,0,'b');
  do while(week_start&amp;lt;end_date);
   week_number=week(week_start);
   output;
   week_start=intnx('week',week_start,1);
  end;
 end;
 format week_start date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 15:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635369#M188642</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-27T15:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Break a Date Range Into Multiple Lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635372#M188643</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;:). You are correct, I missed that. This looks to be doing exactly what I want it to. Thank you so much. I'm just going to break out the active calculation I was referring to in the previous thread into a different step in my process, this was the part I was struggling with. Appreciate you sticking with me despite some of my example problem issues.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 15:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635372#M188643</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2020-03-27T15:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Break a Date Range Into Multiple Lines</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635381#M188649</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/234586"&gt;@A_SAS_Man&lt;/a&gt;&amp;nbsp; You know what. It seemingly appears that the hardest part of the solution is actually getting the requirement or understanding the problem statement or communicating the problem statement effectively. The challenge is the communication. Now I really have begun to understand the importance of soft skills especially communication skills.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Technical skills can be acquired through perseverance. The rest that mentioned above is very difficult as there is no clear path/sequence to achieve that. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 16:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Break-a-Date-Range-Into-Multiple-Lines/m-p/635381#M188649</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-27T16:20:03Z</dc:date>
    </item>
  </channel>
</rss>

