<?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: Replace missing values with previous values in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407242#M26142</link>
    <description>&lt;PRE&gt;


data have;
infile cards truncover;
retain id 1;
input Date $   Var1 Var2 Var3  Var3000;
cards;
10/25   5        2       1             8
10/24
10/23
10/22
10/21   2       4        2             6
10/20
10/19
10/18
10/17   4       5        1             7
;
run;

data want;
 update have(obs=0) have;
 by id;
 output;
 drop id;
run;

&lt;/PRE&gt;</description>
    <pubDate>Wed, 25 Oct 2017 13:08:05 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-10-25T13:08:05Z</dc:date>
    <item>
      <title>Replace missing values with previous values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407151#M26137</link>
      <description>&lt;P&gt;I have a data set as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Date &amp;nbsp; &amp;nbsp;Var1 Var2 Var3 .... Var3000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/25 &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/24&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/23&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/22&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/21 &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/20&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/19&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/18&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10/17 &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to replace the missing values with the previous values across all 3000 variables. I have successfully done it for one variable with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
 retain temp;
 if not missing(Var1) then temp = Var1;
 else Var1 = temp;
 drop temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can one maybe do this in an array?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 07:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407151#M26137</guid>
      <dc:creator>StephanDup</dc:creator>
      <dc:date>2017-10-25T07:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values with previous values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407156#M26138</link>
      <description>&lt;P&gt;You're thinking along the right lines.&amp;nbsp; It's easier if you define a temporary array.&amp;nbsp; Then the elements are automatically retained, and never become part of the output.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array real {3000} var1-var3000;&lt;/P&gt;
&lt;P&gt;array latest {3000} _temporary_;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 3000;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if real{_n_} &amp;gt; . then latest{_n_} = real{_n_};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else real{_n_} = latest{_n_};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 08:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407156#M26138</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-25T08:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values with previous values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407167#M26139</link>
      <description>&lt;P&gt;Thank you so much. It worked!! I can't tell you how long I struggled with that.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 08:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407167#M26139</guid>
      <dc:creator>StephanDup</dc:creator>
      <dc:date>2017-10-25T08:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing values with previous values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407242#M26142</link>
      <description>&lt;PRE&gt;


data have;
infile cards truncover;
retain id 1;
input Date $   Var1 Var2 Var3  Var3000;
cards;
10/25   5        2       1             8
10/24
10/23
10/22
10/21   2       4        2             6
10/20
10/19
10/18
10/17   4       5        1             7
;
run;

data want;
 update have(obs=0) have;
 by id;
 output;
 drop id;
run;

&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 13:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Replace-missing-values-with-previous-values/m-p/407242#M26142</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-25T13:08:05Z</dc:date>
    </item>
  </channel>
</rss>

