<?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: Overlapping Periods - Select last row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Periods-Select-last-row/m-p/768405#M243731</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TABLE1 TABLE2;
  set TEST1;
  if FROM_DT&amp;lt;lag(TO_DT) then output TABLE2;
  else TABLE1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Sep 2021 02:23:03 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-09-18T02:23:03Z</dc:date>
    <item>
      <title>Overlapping Periods - Select last row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Periods-Select-last-row/m-p/768138#M243610</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.testl;&lt;BR /&gt;infile datalines ;&lt;BR /&gt;input Policy_number:$8. Test_Rk:8. Version:8. Amt:8. from_dt:date. to_dt:date.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 10 1 300 '01Jan2006'd&amp;nbsp; '01Jan2034'd&lt;BR /&gt;1 10 1 700 '01Jan2007’d&amp;nbsp; '01Jan2034'd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the above example. row 1 and row 2 are overlapping i.e. from_dt of the second row (01Jan2007) is less than to_dt of the first row(01Jan2034) of the same key policy_number,test_rk, and version. In that case, I want to select the second row in one dataset and write the first row in another table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset 1 :&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 10 1 700 '01Jan2007’d&amp;nbsp; '01Jan2034'd&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset 2:&lt;/P&gt;&lt;P&gt;1 10 1 300 '01Jan2006'd&amp;nbsp; '01Jan2034'd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jayaditya&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 13:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Periods-Select-last-row/m-p/768138#M243610</guid>
      <dc:creator>Jayaditya</dc:creator>
      <dc:date>2021-09-16T13:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping Periods - Select last row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Periods-Select-last-row/m-p/768405#M243731</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TABLE1 TABLE2;
  set TEST1;
  if FROM_DT&amp;lt;lag(TO_DT) then output TABLE2;
  else TABLE1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Sep 2021 02:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Periods-Select-last-row/m-p/768405#M243731</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-09-18T02:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping Periods - Select last row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Periods-Select-last-row/m-p/768529#M243772</link>
      <description>&lt;P&gt;Sorry, my explanation was not clear. I created a new dataline .&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input IDl ID2 ID3 ID4 ID5 FROM_DT: date9. TO_DT:date9. Amount;&lt;BR /&gt;datalines;&lt;BR /&gt;10 12 100 1 4 31DEC2019 31DEC2021 100.00&lt;BR /&gt;10 12 100 1 4 31DEC2012 31DEC2019 100.00&lt;BR /&gt;10 12 101 4 4 31DEC2019 31DEC2021 200.00&lt;BR /&gt;10 12 101 4 4 31DEC2012 31DEC2019 200.00&lt;BR /&gt;10 12 103 6 4 31DEC2012 31DEC2019 300.00&lt;BR /&gt;10 12 103 6 4 31DEC2019 31DEC2021 300.00&lt;BR /&gt;10 12 104 7 4 31DEC2012 31DEC2019 400.00&lt;BR /&gt;10 12 104 7 4 31DEC2019 31DEC2021 400.00&lt;BR /&gt;11 13 105 3 6 01JUL2019 31DEC4747 500.00&lt;BR /&gt;11 13 105 3 6 01OCT2019 31DEC4747 500.00&lt;BR /&gt;11 14 106 4 4 010CT2019 31DEC4747 600.00&lt;BR /&gt;11 14 106 4 4 01JUL2019 31DEC4747 700.00&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Here Key fields are ID1, ID2, ID3,Id4,ID5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for this combination:&lt;/P&gt;&lt;P&gt;1. if Amt were the same&amp;nbsp;and no overlapping dates i.e. if I take the first two rows then take min(to_date) and max(from_date)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;10 12 100 1 4 31DEC2019 31DEC2021 100.00&lt;BR /&gt;10 12 100 1 4 31DEC2012 31DEC2019 100.00&lt;/P&gt;&lt;P&gt;should become&amp;nbsp;&lt;/P&gt;&lt;P&gt;10 12 100 1 4 31DEC2012 31DEC2021 100.00&lt;/P&gt;&lt;P&gt;2. if amt are same or different and if the dates are overlapping for ex: below rows&lt;/P&gt;&lt;P&gt;11 14 106 4 4 010CT2019 31DEC4747 600.00&lt;BR /&gt;11 14 106 4 4 01JUL2019 31DEC4747 700.00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to flag row&amp;nbsp;11 14 106 4 4 010CT2019 31DEC4747 600.00 as 1 and&amp;nbsp;11 14 106 4 4 01JUL2019 31DEC4747 700.00 as 0 as&lt;/P&gt;&lt;P&gt;they are overlapping dates so I have to flag the row with latest to_date to 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jay&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 11:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Periods-Select-last-row/m-p/768529#M243772</guid>
      <dc:creator>Jayaditya</dc:creator>
      <dc:date>2021-09-20T11:25:04Z</dc:date>
    </item>
  </channel>
</rss>

