<?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: Filling up missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853427#M337316</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Group$ Value;
datalines;
A .
A . 
A .
A 1
A .
B . 
B . 
B 1
B .
B .
;
run;

data want;
merge have
      have(keep=Group Value rename=(Group=Group1 Value=Value1 ) firstobs=2)
   have(keep=Group Value rename=(Group=Group2 Value=Value2 ) firstobs=3);
Value=coalesce( Value, ifn(Group=Group1,Value1,.),ifn(Group=Group2,Value2,.) );
drop Group1 Value1 Group2 Value2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Jan 2023 11:36:33 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-01-12T11:36:33Z</dc:date>
    <item>
      <title>Filling up missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853288#M337251</link>
      <description>&lt;P&gt;I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Group&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Value&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each group, I want to fill the missing values of the previous two rows with the non-missing values. Specifically, I want to get the following data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Group&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Value&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I could explain myself &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Khaladdin&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 16:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853288#M337251</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2023-01-11T16:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853296#M337255</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122878"&gt;@Khaladdin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wonder what yout purpose is, but the following code will solve this particular case, which looks like a test vase to me..&lt;/P&gt;
&lt;P&gt;It demonstrates hoiw to perform look-ahead with extra set statements, and I think it could easily be modified, so it could be used in a real-life situation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Group$ Value;
datalines;
A .
A . 
A .
A 1
A .
B . 
B . 
B 1
B .
B .
;
run;

data want (drop=group2 value2 group3 value3); 
  set have nobs=n;
  if _N_ &amp;lt; n-1 then set have (firstobs=2 rename=(group=group2 value=value2));
  if _N_ &amp;lt; n-2 then set have (firstobs=3 rename=(group=group3 value=value3));
  if (group2 = group and value2 ne .) or (group3 = group and value3 ne .) and value = . then value = max(value2,value3);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 16:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853296#M337255</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-01-11T16:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853304#M337257</link>
      <description>&lt;P&gt;Something like this, I think:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by group;
  if first.group then
    _firstobs=_N_;
  if missing(value) then do _point=_N_-1 by -1 to max(_firstobs,_N_-2);
    set have(keep=value) point=_point;
    if not missing(value) then leave;
    end;
  retain _:;
  drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(not tested, as you did not supply test data in data step format)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 17:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853304#M337257</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-01-11T17:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853361#M337282</link>
      <description>Thank you very much! It works too. However, the next code works more efficiently in terms of timing.</description>
      <pubDate>Wed, 11 Jan 2023 21:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853361#M337282</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2023-01-11T21:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853362#M337283</link>
      <description>Thanks!</description>
      <pubDate>Wed, 11 Jan 2023 21:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853362#M337283</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2023-01-11T21:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Filling up missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853427#M337316</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Group$ Value;
datalines;
A .
A . 
A .
A 1
A .
B . 
B . 
B 1
B .
B .
;
run;

data want;
merge have
      have(keep=Group Value rename=(Group=Group1 Value=Value1 ) firstobs=2)
   have(keep=Group Value rename=(Group=Group2 Value=Value2 ) firstobs=3);
Value=coalesce( Value, ifn(Group=Group1,Value1,.),ifn(Group=Group2,Value2,.) );
drop Group1 Value1 Group2 Value2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jan 2023 11:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-up-missing-values/m-p/853427#M337316</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-12T11:36:33Z</dc:date>
    </item>
  </channel>
</rss>

