<?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: Split date range into one row per day in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516394#M16029</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248595"&gt;@davies&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks all for the quick replies! As luck would have it, just after I posted this I adapted this code to account for dates:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Statistical-Procedures/How-to-split-record-into-multiple-rows-one-row-per-month-year/td-p/249306" target="_blank"&gt;https://communities.sas.com/t5/Statistical-Procedures/How-to-split-record-into-multiple-rows-one-row-per-month-year/td-p/249306&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the end, I did this, but your way seems much more efficient, I'll try that!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;data want;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;set have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;date=StartDate;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;if StartDate lt EndDate then do while (date lt EndDate);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;day=day(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;month=month(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;year=year(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;date=intnx('day',date,1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;drop date;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Behavior difference at beginning of the interval if the start = end. With the DO loop the it will execute once. The DO WHILE as shown would not execute.&lt;/P&gt;
&lt;P&gt;I would guess the above code was written by someone either less familiar with SAS DO loop construct using start and end variable&amp;nbsp;values or from a programming language/school that does everything with DO WHILE/UNTIL and not iterated loops for some other reason..&lt;/P&gt;</description>
    <pubDate>Tue, 27 Nov 2018 16:36:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-11-27T16:36:46Z</dc:date>
    <item>
      <title>Split date range into one row per day</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516366#M16024</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've seen posts about splitting date ranges into months, but can't quite figure out how to split a date range into one row per day. For example, I have data that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; StartDate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EndDate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Status&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Jan 28, 2018 &amp;nbsp; &amp;nbsp; Jan 30, 2018 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Jan 30, 2018 &amp;nbsp; &amp;nbsp; Feb 2, 2018 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is this:&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; Date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Status&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Jan 28, 2018 &amp;nbsp; &amp;nbsp;&amp;nbsp; 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Jan 29, 2018 &amp;nbsp; &amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Jan 30, 2018 &amp;nbsp; &amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Jan 31, 2018 &amp;nbsp; &amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Feb 1, 2018 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; Feb 2, 2018 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516366#M16024</guid>
      <dc:creator>davies</dc:creator>
      <dc:date>2018-11-27T16:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Split date range into one row per day</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516371#M16025</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Welcome to SAS Community world.&lt;/P&gt;
&lt;P&gt;Are your date values numeric or character? First you may need to convert them to actual date values if they are in character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id start :date9. enddate :date9. status;
datalines;
1 28JAN2018 30JAN2018 1
1 30JAN2018 02FEB2018 2
;
run;

data want(keep=id date status);
set have;
do i=start to enddate;
date=i;
output;
end;
format date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516371#M16025</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-11-27T16:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Split date range into one row per day</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516372#M16026</link>
      <description>&lt;P&gt;If the values of your StartDate and EndDate are SAS date values the approach is relatively easy, though the disappearance of Jan 30, 2018&amp;nbsp;with status 1 will need some explanation as to the rules involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using mmddyy10 date layout values as the worddate format is uglier to read with datalines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input ID     StartDate :mmddyy10.          EndDate :mmddyy10.    Status;
   format startdate enddate mmddyy10.;
datalines;
1   01/28/2018    01/30/2018    1
1   01/30/2018    02/02/2018    2
;
run;

data want;
   set have;
   do date = startdate to enddate;
      output;
   end;
   drop startdate enddate;
   format date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;Your "have" data would require a processing step with rules to change the enddate fo 01/30/2018 to 01/29/2018 to use this approach but this is demonstrating how to turn the intervals into one observation per date in the interval.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516372#M16026</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-27T16:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Split date range into one row per day</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516373#M16027</link>
      <description>&lt;P&gt;Are your dates SAS numeric dates or char?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516373#M16027</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-27T16:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Split date range into one row per day</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516380#M16028</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks all for the quick replies! As luck would have it, just after I posted this I adapted this code to account for dates:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Statistical-Procedures/How-to-split-record-into-multiple-rows-one-row-per-month-year/td-p/249306" target="_blank"&gt;https://communities.sas.com/t5/Statistical-Procedures/How-to-split-record-into-multiple-rows-one-row-per-month-year/td-p/249306&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the end, I did this, but your way seems much more efficient, I'll try that!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;data want;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;set have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;date=StartDate;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;if StartDate lt EndDate then do while (date lt EndDate);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;day=day(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;month=month(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;year=year(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;date=intnx('day',date,1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;drop date;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516380#M16028</guid>
      <dc:creator>davies</dc:creator>
      <dc:date>2018-11-27T16:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Split date range into one row per day</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516394#M16029</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248595"&gt;@davies&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks all for the quick replies! As luck would have it, just after I posted this I adapted this code to account for dates:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Statistical-Procedures/How-to-split-record-into-multiple-rows-one-row-per-month-year/td-p/249306" target="_blank"&gt;https://communities.sas.com/t5/Statistical-Procedures/How-to-split-record-into-multiple-rows-one-row-per-month-year/td-p/249306&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the end, I did this, but your way seems much more efficient, I'll try that!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;data want;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;set have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;date=StartDate;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;if StartDate lt EndDate then do while (date lt EndDate);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;day=day(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;month=month(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;year=year(date);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;date=intnx('day',date,1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;drop date;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Behavior difference at beginning of the interval if the start = end. With the DO loop the it will execute once. The DO WHILE as shown would not execute.&lt;/P&gt;
&lt;P&gt;I would guess the above code was written by someone either less familiar with SAS DO loop construct using start and end variable&amp;nbsp;values or from a programming language/school that does everything with DO WHILE/UNTIL and not iterated loops for some other reason..&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Split-date-range-into-one-row-per-day/m-p/516394#M16029</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-27T16:36:46Z</dc:date>
    </item>
  </channel>
</rss>

