<?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 issue with calculation between dates  using lag in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605593#M35126</link>
    <description>&lt;P&gt;Hi there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The numeric value for date '03SEP2019' should be 43711 but the data shows a value of 21837. Thus the calculation of Skipped_days is wrong.&amp;nbsp; Any one can help with the issue ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;dateFrom=Service_FromDate;&lt;/P&gt;
&lt;P&gt;Lag_Service_toDate=lag(Service_ToDate);&lt;/P&gt;
&lt;P&gt;Skipped_days=Service_FromDate-lag(Service_ToDate);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 486px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34101iAD7B5D50FAF398B0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Nov 2019 01:35:55 GMT</pubDate>
    <dc:creator>Suzy_Cat</dc:creator>
    <dc:date>2019-11-20T01:35:55Z</dc:date>
    <item>
      <title>issue with calculation between dates  using lag</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605593#M35126</link>
      <description>&lt;P&gt;Hi there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The numeric value for date '03SEP2019' should be 43711 but the data shows a value of 21837. Thus the calculation of Skipped_days is wrong.&amp;nbsp; Any one can help with the issue ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;dateFrom=Service_FromDate;&lt;/P&gt;
&lt;P&gt;Lag_Service_toDate=lag(Service_ToDate);&lt;/P&gt;
&lt;P&gt;Skipped_days=Service_FromDate-lag(Service_ToDate);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 486px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34101iAD7B5D50FAF398B0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 01:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605593#M35126</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-11-20T01:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: issue with calculation between dates  using lag</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605595#M35127</link>
      <description>&lt;P&gt;Add a format statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format myvar date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;replace myvar with your 2 variable names!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 02:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605595#M35127</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-20T02:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: issue with calculation between dates  using lag</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605598#M35128</link>
      <description>&lt;P&gt;Thank you unison!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thought of the format but did not think it matters. I will try&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 02:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605598#M35128</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-11-20T02:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: issue with calculation between dates  using lag</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605611#M35131</link>
      <description>&lt;P&gt;First, let's correct two of your assumptions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The internal SAS date value for September 3, 2019 is 21795 (not 43711).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS is not saying that the value of 21837 corresponds to September 3, 2019.&amp;nbsp; It actually comes from the line above, not shown in your display.&amp;nbsp; The LAG function is getting the value from the previous observation.&amp;nbsp; That's why Lag_Service_ToDate is 21795 on the second line of your display.&amp;nbsp; The LAG function retrieved that value from the first line of your display, corresponding to Service_ToDate of September 3, 2019.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 03:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605611#M35131</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-11-20T03:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: issue with calculation between dates  using lag</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605627#M35132</link>
      <description>&lt;P&gt;My bad. I got the value from Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand how lag works ... I just did not attach the correct part of the result to show the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the issue was if it was the second record for the group, the calculation was wrong but the following records in the same group would be correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will check further tomorrow as the system was down&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 07:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605627#M35132</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-11-20T07:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: issue with calculation between dates  using lag</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605644#M35133</link>
      <description>&lt;P&gt;You are talking about groups. Your problem might be the way you handle a group change with lag():&lt;/P&gt;
&lt;P&gt;Wrong method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by group;
if not first.group then lagdate = lag(date);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Correct method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by group;
lagdate = lag(date)
if first.group then lagdate =.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For proper function, you must make sure that lag() is called in every iteration of the data step.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 09:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605644#M35133</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-20T09:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: issue with calculation between dates  using lag</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605647#M35134</link>
      <description>&lt;P&gt;Hi &lt;A class="lia-link-navigation lia-page-link lia-user-name-link" id="link_8" style="color: rgb(0, 153, 153);" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;&lt;SPAN class="login-bold"&gt;KurtBremser,&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perfect!&amp;nbsp; you have directed me to the right direction!!&lt;/P&gt;
&lt;P&gt;Now I have got exactly what I wanted! Thank you very much for your great knowledge!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 09:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605647#M35134</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2019-11-20T09:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: issue with calculation between dates  using lag</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605871#M35141</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293494"&gt;@Suzy_Cat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My bad. I got the value from Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand how lag works ... I just did not attach the correct part of the result to show the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the issue was if it was the second record for the group, the calculation was wrong but the following records in the same group would be correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will check further tomorrow as the system was down&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I really don't trust Excel for date manipulation. I received an Excel file very recently that has "dates" of "1/0/1900". It doesn't matter which way you might read that but either the day of the month or the month of the year cannot be 0 in a valid date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 18:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/issue-with-calculation-between-dates-using-lag/m-p/605871#M35141</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-20T18:18:40Z</dc:date>
    </item>
  </channel>
</rss>

