<?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: Replacing missing values with next and previous values in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Replacing-missing-values-with-next-and-previous-values/m-p/409010#M12497</link>
    <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
    <pubDate>Tue, 31 Oct 2017 08:58:47 GMT</pubDate>
    <dc:creator>StephanDup</dc:creator>
    <dc:date>2017-10-31T08:58:47Z</dc:date>
    <item>
      <title>Replacing missing values with next and previous values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replacing-missing-values-with-next-and-previous-values/m-p/408978#M12494</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 Var 4 Var 5 .... 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; &amp;nbsp; &amp;nbsp;8 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&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; &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&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; 5 &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. But I would like to replace then with the next value if there is no previous value (such as Var4 and Var3000). I have successfully replaced the missing values with the previous values 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 class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token keyword"&gt;array vars{*} _numeric_;&lt;BR /&gt;&lt;/SPAN&gt; array latest{3000} _temporary_;&lt;BR /&gt; do i = 1 to dim(vars);&lt;BR /&gt;   if vars{i} &amp;gt; . then latest{i} = vars{i};&lt;BR /&gt;   else vars{i} = latest{i};&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I also replace missing values with the following values that is not missing? Should I introduce another temporary array?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 04:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replacing-missing-values-with-next-and-previous-values/m-p/408978#M12494</guid>
      <dc:creator>StephanDup</dc:creator>
      <dc:date>2017-10-31T04:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing missing values with next and previous values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replacing-missing-values-with-next-and-previous-values/m-p/408986#M12496</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input Date $   Var1-Var5;
  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       5         7

data want;
  set have;
  length obs $4;
  obs=put(_n_,z4.);
  array vars{*} _numeric_;
  array latest{5} _temporary_;
  do _n_ = 1 to dim(vars);
    if vars{_n_} &amp;gt; . then latest{_n_} = vars{_n_};
    else vars{_n_} = latest{_n_};
  end;
run;

proc sort data=want;
  by descending obs;
run;

data want;
  set want;
  array vars{*} _numeric_;
  array latest{5} _temporary_;
  do _n_ = 1 to dim(vars);
    if vars{_n_} &amp;gt; . then latest{_n_} = vars{_n_};
    else vars{_n_} = latest{_n_};
  end;
  obs=put(_n_,z4.);
run;

proc sort data=want;
  by obs;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 05:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replacing-missing-values-with-next-and-previous-values/m-p/408986#M12496</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-10-31T05:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing missing values with next and previous values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replacing-missing-values-with-next-and-previous-values/m-p/409010#M12497</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 08:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replacing-missing-values-with-next-and-previous-values/m-p/409010#M12497</guid>
      <dc:creator>StephanDup</dc:creator>
      <dc:date>2017-10-31T08:58:47Z</dc:date>
    </item>
  </channel>
</rss>

