<?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 splie records based on start and end dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503000#M134342</link>
    <description>&lt;P&gt;Ah, it's the durations only that matter. See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd truncover;
input id num (start end) (:date9.);
format start end date9.;
datalines4;
101,2,12MAR2018,14MAR2018
101,3,15MAR2018,19MAR2018
101,4,20MAR2018,29MAR2018
102,2,12JAN2018,19JAN2018
102,3,20JAN2018,28JAN2018
102,4,29JAN2018,12FEB2018
102,5,13FEB2018,18FEB2018
102,6,19FEB2018,28FEB2018
;;;;
run;

data want;
set have (rename=(start=_start end=_end));
format start end date9.;
if _end - _start le 2
then do;
  start = _start;
  end = _end;
  output;
end;
else do;
  start = _start;
  end = start + 1;
  do while (end le _end);
    output;
    start + 2;
    end = start + 1;
  end;
  if end = _end + 1
  then do;
    start = _end;
    end = _end;
    output;
  end;
end;
drop _start _end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 10 Oct 2018 08:31:19 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-10T08:31:19Z</dc:date>
    <item>
      <title>how splie records based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/502997#M134339</link>
      <description>&lt;P&gt;I have id's along with num- i need to spliet the same id and num basis on start and end&amp;nbsp; by 2. and if the duration is 5 days than 3 records with start and end in which 2 will have start and end seperate dates and one record with same date as they are odd.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data WORK.TEST;
  infile datalines dsd truncover;
  input id:32. num:32. start:DATE9. end:DATE9.;
datalines4;
101,2,12MAR2018,14MAR2018
101,3,15MAR2018,19MAR2018
101,4,20MAR2018,29MAR2018
102,2,12JAN2018,19JAN2018
102,3,20JAN2018,28JAN2018
102,4,29JAN2018,12FEB2018
102,5,13FEB2018,18FEB2018
102,6,19FEB2018,28FEB2018
;;;;
&lt;/PRE&gt;
&lt;P&gt;Need something like this&lt;/P&gt;
&lt;PRE&gt;data WORK.want;
  infile datalines dsd truncover;
  input id:32. num:32. start:DATE9. end:DATE9.;
datalines4;
101,2,12MAR2018,14MAR2018
101,3,15MAR2018,16MAR2018
101,3,17MAR2018,18MAR2018
101,3,19MAR2018,19MAR2018
101,4,20MAR2018,21MAR2018
101,4,20MAR2018,21MAR2018
101,4,22MAR2018,23MAR2018
101,4,24MAR2018,25MAR2018
101,4,26MAR2018,27MAR2018
101,4,28MAR2018,29MAR2018
;;;;
&lt;/PRE&gt;
&lt;P&gt;any help please&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 07:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/502997#M134339</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-10T07:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: how splie records based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/502998#M134340</link>
      <description>&lt;P&gt;Re-think your issue with regards to what constitutes an "odd" or "even" date, and how you want to handle month boundaries, as months can have odd (29,31) and even (28,30) numbers of days.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 08:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/502998#M134340</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-10T08:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: how splie records based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/502999#M134341</link>
      <description>&lt;P&gt;odd means if duration of start and end is 5 days and i want to split on 2 days each than 2 rows with 2 days duration and one row with 1 day. I am looking only for days and it will be continous start and end for one id&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 08:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/502999#M134341</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-10T08:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: how splie records based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503000#M134342</link>
      <description>&lt;P&gt;Ah, it's the durations only that matter. See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd truncover;
input id num (start end) (:date9.);
format start end date9.;
datalines4;
101,2,12MAR2018,14MAR2018
101,3,15MAR2018,19MAR2018
101,4,20MAR2018,29MAR2018
102,2,12JAN2018,19JAN2018
102,3,20JAN2018,28JAN2018
102,4,29JAN2018,12FEB2018
102,5,13FEB2018,18FEB2018
102,6,19FEB2018,28FEB2018
;;;;
run;

data want;
set have (rename=(start=_start end=_end));
format start end date9.;
if _end - _start le 2
then do;
  start = _start;
  end = _end;
  output;
end;
else do;
  start = _start;
  end = start + 1;
  do while (end le _end);
    output;
    start + 2;
    end = start + 1;
  end;
  if end = _end + 1
  then do;
    start = _end;
    end = _end;
    output;
  end;
end;
drop _start _end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Oct 2018 08:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503000#M134342</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-10T08:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: how splie records based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503019#M134348</link>
      <description>&lt;P&gt;Sorry kurt i just realised that. it should only split 2 days for first 2 times and the rest should be as it is. I am very sorry for confusion.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if first.id then it should split num 2 times and the rest of dates should be as it is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines dsd truncover;
input id num (start end) (:date9.);
format start end date9.;
datalines4;
101,2,12MAR2018,18MAR2018
101,3,15MAR2018,19MAR2018
101,4,20MAR2018,29MAR2018
102,2,12JAN2018,19JAN2018
102,3,20JAN2018,28JAN2018
102,4,29JAN2018,12FEB2018
102,5,13FEB2018,18FEB2018
102,6,19FEB2018,28FEB2018
;;;;
run;

data want;
infile datalines dsd truncover;
input id num (start end) (:date9.);
format start end date9.;
datalines4;
101,2,12MAR2018,13MAR2018
101,2,14MAR2018,15MAR2018
101,2,16MAR2018,18MAR2018
101,3,15MAR2018,19MAR2018
101,4,20MAR2018,29MAR2018
102,2,12JAN2018,19JAN2018
102,3,20JAN2018,28JAN2018
102,4,29JAN2018,12FEB2018
102,5,13FEB2018,18FEB2018
102,6,19FEB2018,28FEB2018
;;;;
run;
&lt;/PRE&gt;
&lt;P&gt;very sorry for the confusion&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 10:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503019#M134348</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-10T10:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: how splie records based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503021#M134350</link>
      <description>&lt;P&gt;In your example, only the first observation is split, so you can use by-group processing and apply the whole algorithm only at first.id.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 10:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503021#M134350</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-10T10:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: how splie records based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503024#M134353</link>
      <description>&lt;PRE&gt;data have;
infile datalines dsd truncover;
input id num (start end) (:date9.);
format start end date9.;
datalines4;
101,2,12MAR2018,18MAR2018
101,3,15MAR2018,19MAR2018
101,4,20MAR2018,29MAR2018
102,2,12JAN2018,19JAN2018
102,3,20JAN2018,28JAN2018
102,4,29JAN2018,12FEB2018
102,5,13FEB2018,18FEB2018
102,6,19FEB2018,28FEB2018
;;;;
run;


proc sort data=have; by id num; run;

data want;
set have (rename=(start=_start end=_end));
by id;
format start end date9.;
if first.id then do;
if _end - _start le 2
then do;
  start = _start;
  end = _end;
  output;
end;
else do;
  start = _start;
  end = start + 1;
  do while (end le _end);
    output;
    start + 2;
    end = start + 1;
  end;
  if end = _end + 1
  then do;
    start = _end;
    end = _end;
    output;
  end;
end;
end;
drop _start _end;
run;&lt;/PRE&gt;
&lt;P&gt;I tried this way but it gave me same result&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 10:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-splie-records-based-on-start-and-end-dates/m-p/503024#M134353</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-10T10:30:02Z</dc:date>
    </item>
  </channel>
</rss>

