<?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 Need help with date comparison with previous date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785494#M32157</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="H1M_0-1639187051484.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66637i23471FC1F10F3591/image-size/medium?v=v2&amp;amp;px=400" role="button" title="H1M_0-1639187051484.png" alt="H1M_0-1639187051484.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data with above columns where per reference I have multiple extension start dates and extension end dates&amp;nbsp;&lt;/P&gt;&lt;P&gt;in most case new extension start date doesn't start before pervious extension end date but in some instance new extension start date start before the previous extension end date&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find total numbers of days per extension but I need to ensure if new extension starts before previous extension end date , then it should take difference of last extension end date and new extension end date&lt;BR /&gt;&lt;BR /&gt;I am not sure how to do this in SAS ,is any one able to help ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 11 Dec 2021 03:35:38 GMT</pubDate>
    <dc:creator>H1M</dc:creator>
    <dc:date>2021-12-11T03:35:38Z</dc:date>
    <item>
      <title>Need help with date comparison with previous date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785494#M32157</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="H1M_0-1639187051484.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66637i23471FC1F10F3591/image-size/medium?v=v2&amp;amp;px=400" role="button" title="H1M_0-1639187051484.png" alt="H1M_0-1639187051484.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data with above columns where per reference I have multiple extension start dates and extension end dates&amp;nbsp;&lt;/P&gt;&lt;P&gt;in most case new extension start date doesn't start before pervious extension end date but in some instance new extension start date start before the previous extension end date&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find total numbers of days per extension but I need to ensure if new extension starts before previous extension end date , then it should take difference of last extension end date and new extension end date&lt;BR /&gt;&lt;BR /&gt;I am not sure how to do this in SAS ,is any one able to help ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 03:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785494#M32157</guid>
      <dc:creator>H1M</dc:creator>
      <dc:date>2021-12-11T03:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with date comparison with previous date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785499#M32158</link>
      <description>&lt;P&gt;Sure! And this is also a common asked question so if you search for "overlapping dates" you'll find some examples. &lt;BR /&gt;&lt;BR /&gt;To be able to help you it would be best if you could provide data as text as minimum, definitely not an image. We'd have to type your data out to work with it and it's much easier and faster if you post it as text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409572"&gt;@H1M&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="H1M_0-1639187051484.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66637i23471FC1F10F3591/image-size/medium?v=v2&amp;amp;px=400" role="button" title="H1M_0-1639187051484.png" alt="H1M_0-1639187051484.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have data with above columns where per reference I have multiple extension start dates and extension end dates&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in most case new extension start date doesn't start before pervious extension end date but in some instance new extension start date start before the previous extension end date&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to find total numbers of days per extension but I need to ensure if new extension starts before previous extension end date , then it should take difference of last extension end date and new extension end date&lt;BR /&gt;&lt;BR /&gt;I am not sure how to do this in SAS ,is any one able to help ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 03:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785499#M32158</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-11T03:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with date comparison with previous date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785502#M32159</link>
      <description>Thanks Reeza i have save sample data in txt. format&lt;BR /&gt;&lt;BR /&gt;Apricate your help</description>
      <pubDate>Sat, 11 Dec 2021 03:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785502#M32159</guid>
      <dc:creator>H1M</dc:creator>
      <dc:date>2021-12-11T03:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with date comparison with previous date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785503#M32160</link>
      <description>&lt;P&gt;Please paste it as text directly into the forums, not as an attachment.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 03:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785503#M32160</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-11T03:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with date comparison with previous date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785506#M32161</link>
      <description>Reference Extetion_start_Date Extention_end_date Total_Extension_days Should_be_ext_days&lt;BR /&gt;123456789 7-Aug-12 20-Sep-12 44 44&lt;BR /&gt;123456789 5-Mar-13 6-Jun-13 93 93&lt;BR /&gt;123456789 10-May-13 20-Jun-13 41 14&lt;BR /&gt;123456789 25-Jul-14 30-Sep-14 67 67&lt;BR /&gt;123456789 12-Sep-14 30-Oct-14 48 30&lt;BR /&gt;123456789 14-Dec-15 20-Jan-16 37 37&lt;BR /&gt;123456789 1-Apr-16 30-Jun-16 90 90&lt;BR /&gt;123456789 2-Feb-17 30-May-17 117 117&lt;BR /&gt;234567891 7-Aug-13 20-Sep-13 44 44&lt;BR /&gt;234567891 5-Mar-14 6-Jun-14 93 93&lt;BR /&gt;234567891 10-May-14 20-Jun-14 41 14&lt;BR /&gt;234567891 29-Jul-15 30-Sep-15 63 63&lt;BR /&gt;234567891 1-Sep-15 30-Oct-15 59 30&lt;BR /&gt;234567891 14-Dec-16 20-Jan-17 37 37&lt;BR /&gt;234567891 1-Apr-17 30-Jun-17 90 90&lt;BR /&gt;234567891 2-Feb-18 30-May-18 117 90&lt;BR /&gt;</description>
      <pubDate>Sat, 11 Dec 2021 03:43:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785506#M32161</guid>
      <dc:creator>H1M</dc:creator>
      <dc:date>2021-12-11T03:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with date comparison with previous date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785507#M32162</link>
      <description>&lt;P&gt;I don't think your last line is correct? The dates do not overlap?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;234567891 1-Apr-17 30-Jun-17 90 90&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;234567891 2-Feb-18 30-May-18 117 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;90&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Assuming I'm correct, this works for me:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat ID 8. date_start date_end date11.;
format date_: date9.;
input ID date_start date_end days right_days;
cards;
123456789 7-Aug-12 20-Sep-12 44 44
123456789 5-Mar-13 6-Jun-13 93 93
123456789 10-May-13 20-Jun-13 41 14
123456789 25-Jul-14 30-Sep-14 67 67
123456789 12-Sep-14 30-Oct-14 48 30
123456789 14-Dec-15 20-Jan-16 37 37
123456789 1-Apr-16 30-Jun-16 90 90
123456789 2-Feb-17 30-May-17 117 117
234567891 7-Aug-13 20-Sep-13 44 44
234567891 5-Mar-14 6-Jun-14 93 93
234567891 10-May-14 20-Jun-14 41 14
234567891 29-Jul-15 30-Sep-15 63 63
234567891 1-Sep-15 30-Oct-15 59 30
234567891 14-Dec-16 20-Jan-17 37 37
234567891 1-Apr-17 30-Jun-17 90 90
234567891 2-Feb-18 30-May-18 117 90
;;;;
run;

proc sort data=have;
by id date_start;
run;

data want;
set have;
by id;

prev_date = lag(date_end);
if first.id then prev_date = .;

if prev_date&amp;gt;date_start then date_calc = date_end - prev_date;
else date_calc = date_end - date_start;

check = right_days - date_calc;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409572"&gt;@H1M&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Reference Extetion_start_Date Extention_end_date Total_Extension_days Should_be_ext_days&lt;BR /&gt;123456789 7-Aug-12 20-Sep-12 44 44&lt;BR /&gt;123456789 5-Mar-13 6-Jun-13 93 93&lt;BR /&gt;123456789 10-May-13 20-Jun-13 41 14&lt;BR /&gt;123456789 25-Jul-14 30-Sep-14 67 67&lt;BR /&gt;123456789 12-Sep-14 30-Oct-14 48 30&lt;BR /&gt;123456789 14-Dec-15 20-Jan-16 37 37&lt;BR /&gt;123456789 1-Apr-16 30-Jun-16 90 90&lt;BR /&gt;123456789 2-Feb-17 30-May-17 117 117&lt;BR /&gt;234567891 7-Aug-13 20-Sep-13 44 44&lt;BR /&gt;234567891 5-Mar-14 6-Jun-14 93 93&lt;BR /&gt;234567891 10-May-14 20-Jun-14 41 14&lt;BR /&gt;234567891 29-Jul-15 30-Sep-15 63 63&lt;BR /&gt;234567891 1-Sep-15 30-Oct-15 59 30&lt;BR /&gt;234567891 14-Dec-16 20-Jan-17 37 37&lt;BR /&gt;234567891 1-Apr-17 30-Jun-17 90 90&lt;BR /&gt;234567891 2-Feb-18 30-May-18 117 90&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 03:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785507#M32162</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-11T03:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with date comparison with previous date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785509#M32163</link>
      <description>&lt;P&gt;Thanks Reeza yes not all dates are overlapping only some where i need to ensure its not double counting No. of days&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for the quick response and it is working fine&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 04:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-date-comparison-with-previous-date/m-p/785509#M32163</guid>
      <dc:creator>H1M</dc:creator>
      <dc:date>2021-12-11T04:21:16Z</dc:date>
    </item>
  </channel>
</rss>

