<?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 Comparing dates from different data points and merge based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932797#M366937</link>
    <description>&lt;P&gt;I have a ( kind of specific) problem, I would say.&lt;BR /&gt;Here is the dataset I have:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;data have;
    infile datalines delimiter='|' dsd truncover;
    input client $ account $ start :date9. end :date9.;
    format start end date9.;
datalines;
123 | 123ABC | 30JUN2019 | 30SEP2019
321 | 123ABC | 30JUN2020 | 31JUL2020
456 | 456ABC | 30JUN2021 | 30SEP2023
456 | 456ABC | 30JUN2018 | 30NOV2019
654 | 456ABC | 01DEC2019 | 05FEB2020
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this data I want to compare the end date from the current datapoint with the start date of the next datapoint and calculate the date difference between these two dates. If the difference is shorter than 4 days I want to merge the two data points. So in this case the output should be:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;data have;
    infile datalines delimiter='|' dsd truncover;
    input client $ account $ start :date9. end :date9.;
    format start end date9.;
datalines;
123 | 123ABC | 30JUN2019 | 30SEP2019
321 | 123ABC | 30JUN2020 | 31JUL2020
456 | 456ABC | 30JUN2021 | 30SEP2023
456 | 456ABC | 30JUN2018 | 05FEB2020
;
run;&lt;/PRE&gt;&lt;P&gt;ChatGPT did fail to produce the desired output.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jun 2024 13:48:38 GMT</pubDate>
    <dc:creator>nbora</dc:creator>
    <dc:date>2024-06-18T13:48:38Z</dc:date>
    <item>
      <title>Comparing dates from different data points and merge based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932797#M366937</link>
      <description>&lt;P&gt;I have a ( kind of specific) problem, I would say.&lt;BR /&gt;Here is the dataset I have:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;data have;
    infile datalines delimiter='|' dsd truncover;
    input client $ account $ start :date9. end :date9.;
    format start end date9.;
datalines;
123 | 123ABC | 30JUN2019 | 30SEP2019
321 | 123ABC | 30JUN2020 | 31JUL2020
456 | 456ABC | 30JUN2021 | 30SEP2023
456 | 456ABC | 30JUN2018 | 30NOV2019
654 | 456ABC | 01DEC2019 | 05FEB2020
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this data I want to compare the end date from the current datapoint with the start date of the next datapoint and calculate the date difference between these two dates. If the difference is shorter than 4 days I want to merge the two data points. So in this case the output should be:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;data have;
    infile datalines delimiter='|' dsd truncover;
    input client $ account $ start :date9. end :date9.;
    format start end date9.;
datalines;
123 | 123ABC | 30JUN2019 | 30SEP2019
321 | 123ABC | 30JUN2020 | 31JUL2020
456 | 456ABC | 30JUN2021 | 30SEP2023
456 | 456ABC | 30JUN2018 | 05FEB2020
;
run;&lt;/PRE&gt;&lt;P&gt;ChatGPT did fail to produce the desired output.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 13:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932797#M366937</guid>
      <dc:creator>nbora</dc:creator>
      <dc:date>2024-06-18T13:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing dates from different data points and merge based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932799#M366938</link>
      <description>&lt;P&gt;You &lt;STRONG&gt;really &lt;/STRONG&gt;want to combine dates across different clients????&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 14:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932799#M366938</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-18T14:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing dates from different data points and merge based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932861#M366940</link>
      <description>&lt;P&gt;Yes. Even if they different clients the "belong" to the same account.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 15:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932861#M366940</guid>
      <dc:creator>nbora</dc:creator>
      <dc:date>2024-06-18T15:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing dates from different data points and merge based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932899#M366955</link>
      <description>&lt;P&gt;The following code works based on the data provided. This assumes the data is sorted by client and uses by group processing and the lag function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have2;&lt;BR /&gt;set have;&lt;BR /&gt;by client;&lt;BR /&gt;p_end = lag(end);&lt;BR /&gt;p_start = lag(start);&lt;BR /&gt;p_client = lag(client);&lt;BR /&gt;p_account = lag(account);&lt;BR /&gt;diff = abs(p_end-start);&lt;BR /&gt;format p_start p_end date9.;&lt;/P&gt;
&lt;P&gt;if 0&amp;lt;= diff &amp;lt;=4 then&lt;BR /&gt;do;&lt;BR /&gt;client = p_client;&lt;BR /&gt;account = p_account;&lt;BR /&gt;start = p_start;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;if first.client =0 then delete;&lt;BR /&gt;keep client account start end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 19:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-dates-from-different-data-points-and-merge-based-on/m-p/932899#M366955</guid>
      <dc:creator>JOL</dc:creator>
      <dc:date>2024-06-18T19:46:03Z</dc:date>
    </item>
  </channel>
</rss>

