<?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 Retain with Arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/285278#M58282</link>
    <description>&lt;P&gt;I have a scenario where I have missing data that I would like to fill in with the previous (non-missing) observation. &amp;nbsp;So, for example my data looks like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs &amp;nbsp;FFY2012&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.2&lt;/P&gt;&lt;P&gt;3&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;4&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;6&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And I want to fill in Obs #3 with 0.2 (i.e., the value from Obs #2). &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So I wrote up this code and it works well...&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;if ffy2012 = . and open_cit_lag_c = 0 then ffyear2012 = 0;
	if ffy2012 ne . then ffyear2012 = ffy2012;
	retain ffyear2012;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;(Open_cit_lag_c = 0 is the first observation, and sometimes this value is missing as well. &amp;nbsp;Just FYI...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I have 5 such variables that need to be fixed, so I tried to write this up as an array, like so:&lt;/P&gt;&lt;PRE&gt;array FFY{5} FFY2011 FFY2012 FFY2013 FFY2014 FFY2015;
array FFYEAR{5} FFYEAR2011 FFYEAR2012 FFYEAR2013 FFYEAR2014 FFYEAR2015;
do i = 1 to 5;
	if ffy{i} = . and open_cit_lag_c = 0 then ffyear{i} = 0;
	if ffy{i} ne . then ffyear{i} = ffy{i};
	retain ffyear{i};
	end;&lt;/PRE&gt;&lt;P&gt;And it errored out at the retain statement. &amp;nbsp;It's early in the morning, so it's possible that I'm missing something small. &amp;nbsp;But I'm wondering if my use of a retain statement within the array do loop is causing some sort of crossing of streams? &amp;nbsp;Anywho, any thoughts would help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jul 2016 16:16:17 GMT</pubDate>
    <dc:creator>TashaChapman14</dc:creator>
    <dc:date>2016-07-18T16:16:17Z</dc:date>
    <item>
      <title>Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/285278#M58282</link>
      <description>&lt;P&gt;I have a scenario where I have missing data that I would like to fill in with the previous (non-missing) observation. &amp;nbsp;So, for example my data looks like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs &amp;nbsp;FFY2012&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.2&lt;/P&gt;&lt;P&gt;3&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;4&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;6&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And I want to fill in Obs #3 with 0.2 (i.e., the value from Obs #2). &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So I wrote up this code and it works well...&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;if ffy2012 = . and open_cit_lag_c = 0 then ffyear2012 = 0;
	if ffy2012 ne . then ffyear2012 = ffy2012;
	retain ffyear2012;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;(Open_cit_lag_c = 0 is the first observation, and sometimes this value is missing as well. &amp;nbsp;Just FYI...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I have 5 such variables that need to be fixed, so I tried to write this up as an array, like so:&lt;/P&gt;&lt;PRE&gt;array FFY{5} FFY2011 FFY2012 FFY2013 FFY2014 FFY2015;
array FFYEAR{5} FFYEAR2011 FFYEAR2012 FFYEAR2013 FFYEAR2014 FFYEAR2015;
do i = 1 to 5;
	if ffy{i} = . and open_cit_lag_c = 0 then ffyear{i} = 0;
	if ffy{i} ne . then ffyear{i} = ffy{i};
	retain ffyear{i};
	end;&lt;/PRE&gt;&lt;P&gt;And it errored out at the retain statement. &amp;nbsp;It's early in the morning, so it's possible that I'm missing something small. &amp;nbsp;But I'm wondering if my use of a retain statement within the array do loop is causing some sort of crossing of streams? &amp;nbsp;Anywho, any thoughts would help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2016 16:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/285278#M58282</guid>
      <dc:creator>TashaChapman14</dc:creator>
      <dc:date>2016-07-18T16:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/285281#M58283</link>
      <description>&lt;P&gt;Don't put the RETAIN in the loop, It is not an executable statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array FFY FFY2011 FFY2012 FFY2013 FFY2014 FFY2015;
array FFYEAR FFYEAR2011 FFYEAR2012 FFYEAR2013 FFYEAR2014 FFYEAR2015;
retain FFYEAR2011 FFYEAR2012 FFYEAR2013 FFYEAR2014 FFYEAR2015;
do i = 1 to dim(FFY);
  if ffy{i} = . and open_cit_lag_c = 0 then ffyear{i} = 0;
  if ffy{i} ne . then ffyear{i} = ffy{i};
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Note that if you assign initial values in the ARRAY statement then SAS will automatically retain the values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array FFYEAR FFYEAR2011 FFYEAR2012 FFYEAR2013 FFYEAR2014 FFYEAR2015 (5*.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Jul 2016 16:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/285281#M58283</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-18T16:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/285282#M58284</link>
      <description>&lt;P&gt;Slick! &amp;nbsp;That fixed it. &amp;nbsp;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2016 16:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/285282#M58284</guid>
      <dc:creator>TashaChapman14</dc:creator>
      <dc:date>2016-07-18T16:25:28Z</dc:date>
    </item>
  </channel>
</rss>

