<?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: Lag function Basics in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900145#M40102</link>
    <description>&lt;P&gt;LAG, and its companion function DIF, are queued functions. That means that when you use Lag inside of an IF, or related conditional code structure, that the "previous value" returned by the function is that the previous time that the IF was true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So generally the preferred usage is to execute the Lag before any IF so you have the value as needed conditionally and typically drop the lagged variable unless needed later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2023 14:29:00 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-10-26T14:29:00Z</dc:date>
    <item>
      <title>Lag function Basics</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900141#M40100</link>
      <description>&lt;P&gt;I came across this MCQ.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correct ans is B and even I read the logic behind this. But can anyone plz explain the same in more simple words. I didn't understand the logic explained in the image below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="POOJA_J_0-1698329778196.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89109iD90EA4F9347ABEF3/image-size/large?v=v2&amp;amp;px=999" role="button" title="POOJA_J_0-1698329778196.png" alt="POOJA_J_0-1698329778196.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="POOJA_J_1-1698329796670.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89110i02AB6B348D9B2249/image-size/large?v=v2&amp;amp;px=999" role="button" title="POOJA_J_1-1698329796670.png" alt="POOJA_J_1-1698329796670.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 14:41:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900141#M40100</guid>
      <dc:creator>POOJA_J</dc:creator>
      <dc:date>2023-10-26T14:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Lag function Basics</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900143#M40101</link>
      <description>&lt;P&gt;From now on, please post text and code as text and not as screen captures. From now on, please provide data as working SAS data step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps these words work better for you:&amp;nbsp;&lt;U&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Unexpected-results-with-lag-function/m-p/820751#M324005" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Unexpected-results-with-lag-function/m-p/820751#M324005&lt;/A&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, if you call LAG in an IF statement, and that branch of the IF statement doesn't execute, then the lagged value doesn't get created and thus the lagged value can't be used by the next observation.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 14:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900143#M40101</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-26T14:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Lag function Basics</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900145#M40102</link>
      <description>&lt;P&gt;LAG, and its companion function DIF, are queued functions. That means that when you use Lag inside of an IF, or related conditional code structure, that the "previous value" returned by the function is that the previous time that the IF was true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So generally the preferred usage is to execute the Lag before any IF so you have the value as needed conditionally and typically drop the lagged variable unless needed later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 14:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900145#M40102</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-26T14:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Lag function Basics</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900152#M40104</link>
      <description>Thanks for explaining. &lt;BR /&gt;I will take care not to post screen shots next time. &lt;BR /&gt;</description>
      <pubDate>Thu, 26 Oct 2023 14:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900152#M40104</guid>
      <dc:creator>POOJA_J</dc:creator>
      <dc:date>2023-10-26T14:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Lag function Basics</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900156#M40105</link>
      <description>&lt;P&gt;The real answer is (C) use the DIF() function instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;tempdiff=dif(temp);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 15:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-function-Basics/m-p/900156#M40105</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-26T15:12:39Z</dc:date>
    </item>
  </channel>
</rss>

