<?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 Lag Statement in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/297445#M8401</link>
    <description>&lt;P&gt;I have a large data set that I am trying to use a lag statement that is nested within an if statement. I have attached a file that has the code and also an example of what the output looks like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The lag statment is returning the previous weight and then using this weight to calculate a difference. The lag statment is nested within an if statement based on animal ID. If the previous ID doesn't match, a "." is returned. It is working with the exception of the 2nd observation. I know the first observation for each animal will be a ".". But the first two are ".". Any help is appreacited.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Sep 2016 16:25:24 GMT</pubDate>
    <dc:creator>llt34c</dc:creator>
    <dc:date>2016-09-09T16:25:24Z</dc:date>
    <item>
      <title>Lag Statement</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/297445#M8401</link>
      <description>&lt;P&gt;I have a large data set that I am trying to use a lag statement that is nested within an if statement. I have attached a file that has the code and also an example of what the output looks like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The lag statment is returning the previous weight and then using this weight to calculate a difference. The lag statment is nested within an if statement based on animal ID. If the previous ID doesn't match, a "." is returned. It is working with the exception of the 2nd observation. I know the first observation for each animal will be a ".". But the first two are ".". Any help is appreacited.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 16:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/297445#M8401</guid>
      <dc:creator>llt34c</dc:creator>
      <dc:date>2016-09-09T16:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Statement</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/297451#M8402</link>
      <description>&lt;P&gt;LAG does not retrieve the value from the previous observation. &amp;nbsp;That's a common mistake. &amp;nbsp;LAG retrieves the value from the last time that LAG executed. &amp;nbsp;So it becomes important (in most applications) to make sure that LAG executes on every observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The usual fix is to execute LAG on every observation by taking it out of any IF THEN statements. &amp;nbsp;Then on the first observation for each animal ID, reset your new variable (the one that holds the results of the LAG function) to a missing value.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 16:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/297451#M8402</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-09T16:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Statement</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/298370#M8437</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggeling on how to reset a variable to a missing value? I have never done this without using some type of if statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your time.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 16:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/298370#M8437</guid>
      <dc:creator>llt34c</dc:creator>
      <dc:date>2016-09-14T16:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Statement</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/298379#M8438</link>
      <description>&lt;P&gt;Yes, that's the right tool.&amp;nbsp; Use an IF/THEN statement.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 17:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/298379#M8438</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-14T17:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Statement</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/298386#M8439</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 17:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Lag-Statement/m-p/298386#M8439</guid>
      <dc:creator>llt34c</dc:creator>
      <dc:date>2016-09-14T17:22:20Z</dc:date>
    </item>
  </channel>
</rss>

