<?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: How to retain values created using Lag function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516632#M139554</link>
    <description>Thanks KurtBremser. This is working</description>
    <pubDate>Wed, 28 Nov 2018 12:12:25 GMT</pubDate>
    <dc:creator>BalajiBollu</dc:creator>
    <dc:date>2018-11-28T12:12:25Z</dc:date>
    <item>
      <title>How to retain values created using Lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516615#M139549</link>
      <description>&lt;P&gt;Hi I have created a dataset with some sample values like below;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input x @@;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 &lt;STRONG&gt;0 0&lt;/STRONG&gt; 3 4 5 &lt;STRONG&gt;0 0 0&lt;/STRONG&gt; 6&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Now i need to create another variable x1 where&amp;nbsp;the non zero value of x should retain instead of&amp;nbsp;0's. The output i am looking for is&lt;/P&gt;&lt;P&gt;1 2 &lt;STRONG&gt;2 2&lt;/STRONG&gt; 3 4 5 &lt;STRONG&gt;5 5 5&lt;/STRONG&gt; 6.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using lag function but i am not able to retain it if it has more than one 0 successively. Any help?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 10:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516615#M139549</guid>
      <dc:creator>BalajiBollu</dc:creator>
      <dc:date>2018-11-28T10:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values created using Lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516622#M139552</link>
      <description>&lt;P&gt;You've already found the right word: &lt;EM&gt;retain&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;The code should look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain _x 0;
if x ne 0
then _x = x; * this will always keep the last non-zero value;
else x = _x; * and this overrides the zeroes;
drop _x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to do it for groups, the init of _x to 0 has to be done at first.group instead of in the retain statement.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 11:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516622#M139552</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-28T11:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values created using Lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516632#M139554</link>
      <description>Thanks KurtBremser. This is working</description>
      <pubDate>Wed, 28 Nov 2018 12:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516632#M139554</guid>
      <dc:creator>BalajiBollu</dc:creator>
      <dc:date>2018-11-28T12:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values created using Lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516691#M139585</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input x @@;
datalines;
1 2 0 0 3 4 5 0 0 0 6
;

data want;
set a;
_iorc_=ifn( x=0 and lag(x) ne 0 ,lag(x),_iorc_);
if x=0 then x=_iorc_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 14:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-created-using-Lag-function/m-p/516691#M139585</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-28T14:41:58Z</dc:date>
    </item>
  </channel>
</rss>

