<?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 get the Value from the Previous Year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-Value-from-the-Previous-Year/m-p/396279#M95655</link>
    <description>&lt;P&gt;There are hundreds of examples on here of the use of lag() function and retained variables. &amp;nbsp;I personally prefer retained variables:&lt;/P&gt;
&lt;PRE&gt;data want (drop=lstvalue);
  set have;
  retain lstval;
  lstval=ifn(value ne 0,value,lstval);
  if value=0 then value=lstvalue;
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 15 Sep 2017 11:34:04 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-09-15T11:34:04Z</dc:date>
    <item>
      <title>How to get the Value from the Previous Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-Value-from-the-Previous-Year/m-p/396273#M95651</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need help in creating the dataset, which gets the previous year value, or the base value when null.&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input product $ scenario year value;&lt;BR /&gt;cards;&lt;BR /&gt;MOR 0 2016 800&lt;BR /&gt;MOR 0 2017 100&lt;BR /&gt;MOR 0 2018 0&lt;BR /&gt;MOR 0 2019 0&lt;BR /&gt;MOR 1 2017 0&lt;BR /&gt;MOR 1 2018 700&lt;BR /&gt;MOR 1 2019 600&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/*If it's Scenario 1, year 2017, and Value = 0, I should get the 2016 value of 800, functioning something like a base value*/&lt;BR /&gt;/*Else, I just get the value of the previous year*/&lt;/P&gt;
&lt;P&gt;data want; &lt;BR /&gt;input product $ scenario year value;&lt;BR /&gt;cards;&lt;BR /&gt;MOR 0 2016 800&lt;BR /&gt;MOR 0 2017 100&lt;BR /&gt;MOR 0 2018 100&lt;BR /&gt;MOR 0 2019 100&lt;BR /&gt;MOR 1 2017 800&lt;BR /&gt;MOR 1 2018 700&lt;BR /&gt;MOR 1 2019 600&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 11:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-Value-from-the-Previous-Year/m-p/396273#M95651</guid>
      <dc:creator>angeliquec</dc:creator>
      <dc:date>2017-09-15T11:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the Value from the Previous Year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-Value-from-the-Previous-Year/m-p/396279#M95655</link>
      <description>&lt;P&gt;There are hundreds of examples on here of the use of lag() function and retained variables. &amp;nbsp;I personally prefer retained variables:&lt;/P&gt;
&lt;PRE&gt;data want (drop=lstvalue);
  set have;
  retain lstval;
  lstval=ifn(value ne 0,value,lstval);
  if value=0 then value=lstvalue;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Sep 2017 11:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-Value-from-the-Previous-Year/m-p/396279#M95655</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-15T11:34:04Z</dc:date>
    </item>
  </channel>
</rss>

