<?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 Replace missing value with latest instance of an observation in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807895#M20296</link>
    <description>&lt;P&gt;I need to replace all the missing values (in previous instances) with the latest instance values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;Start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;3/4/2022&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;3/5/2022&amp;nbsp; &amp;nbsp;3/6/2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;needs to looks like -&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;Start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;3/4/2022&amp;nbsp;&amp;nbsp;3/6/2022&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;3/5/2022&amp;nbsp; &amp;nbsp;3/6/2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Apr 2022 18:42:28 GMT</pubDate>
    <dc:creator>SidB</dc:creator>
    <dc:date>2022-04-14T18:42:28Z</dc:date>
    <item>
      <title>Replace missing value with latest instance of an observation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807895#M20296</link>
      <description>&lt;P&gt;I need to replace all the missing values (in previous instances) with the latest instance values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;Start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;3/4/2022&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;3/5/2022&amp;nbsp; &amp;nbsp;3/6/2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;needs to looks like -&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;Start&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;3/4/2022&amp;nbsp;&amp;nbsp;3/6/2022&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;3/5/2022&amp;nbsp; &amp;nbsp;3/6/2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 18:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807895#M20296</guid>
      <dc:creator>SidB</dc:creator>
      <dc:date>2022-04-14T18:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing value with latest instance of an observation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807900#M20297</link>
      <description>&lt;P&gt;The double DOW technique is well suited for this kind of operation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (Start End) (:mmddyy.);
format start end yymmdd10.;
datalines;
1   3/4/2022  .
1   3/5/2022   3/6/2022
;

data want;
do until (last.id);
    set have; by id;
    if not missing(end) then latest = max(latest, end);
    end;
do until (last.id);
    set have; by id;
    end = coalesce(end, latest);
    output;
    end;
drop latest;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2022 18:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807900#M20297</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-04-14T18:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing value with latest instance of an observation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807944#M20298</link>
      <description>&lt;P&gt;The double DOW, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;suggests is well suited to your task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The core logic of the double DOW is to read all obs for each ID twice, the first time to establish the latest END value, and the second time to assign that value when necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below also reads each ID twice, but uses the "IN=" dataset name parameters (in the SET statement) to identify the equivalent of each DO loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (Start End) (:mmddyy.);
format start end yymmdd10.;
datalines;
1   3/4/2022  .
1   3/5/2022   3/6/2022
run;

data want (drop=_:);
  set have (in=firstpass)  have (in=secondpass);
  by id;
  retain _last_end;
  if first.id then call missing(_last_end);
  if firstpass then _last_end=coalesce(end,_last_end);
  if secondpass;
  end=coalesce(end,_last_end);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2022 23:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807944#M20298</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-14T23:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Replace missing value with latest instance of an observation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807946#M20299</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;Thank you so much! this worked&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2022 00:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-missing-value-with-latest-instance-of-an-observation/m-p/807946#M20299</guid>
      <dc:creator>SidB</dc:creator>
      <dc:date>2022-04-15T00:33:13Z</dc:date>
    </item>
  </channel>
</rss>

