<?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: Pick The Last Non Missing Value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292508#M60729</link>
    <description>&lt;P&gt;This is a good place to apply the UPDATE trick it handles BY group automatically.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data XY;
   input X Y @@;
   cards;
1 70 1 . 1 . 1 .
1 80 1 . 1 . 
2 60 2 . 3 .
;;;;
   run;
proc print;
   run;
data LOCF;
   update XY(obs=0) XY;
   by X;
   output;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Aug 2016 18:01:25 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-08-18T18:01:25Z</dc:date>
    <item>
      <title>Pick The Last Non Missing Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292490#M60718</link>
      <description>I have the following dataset:&lt;BR /&gt;X Y&lt;BR /&gt;1 70&lt;BR /&gt;1 .&lt;BR /&gt;1 .&lt;BR /&gt;1 .&lt;BR /&gt;1 80&lt;BR /&gt;1 .&lt;BR /&gt;1 .&lt;BR /&gt;&lt;BR /&gt;I want to assign the last non missing value to the missing observations. Expected output as follows&lt;BR /&gt;X Y&lt;BR /&gt;1 70&lt;BR /&gt;1 70&lt;BR /&gt;1 70&lt;BR /&gt;1 70&lt;BR /&gt;1 80&lt;BR /&gt;1 80&lt;BR /&gt;1 80&lt;BR /&gt;&lt;BR /&gt;Please help. I tried do end loop but to no use.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 18 Aug 2016 16:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292490#M60718</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2016-08-18T16:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Pick The Last Non Missing Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292493#M60720</link>
      <description>Adding to the above requirment, I may also need to pick last non missing in a BY group. That is, I don't need to assign 80 if X=2.</description>
      <pubDate>Thu, 18 Aug 2016 16:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292493#M60720</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2016-08-18T16:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Pick The Last Non Missing Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292494#M60721</link>
      <description>&lt;P&gt;Remove the rename and drop statements if you want the new variable to be in its own column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
   input X Y;
   datalines;
1 70
1 .
1 .
1 .
1 80
1 .
1 .
;

data temp2;
    set temp;
    retain last_non_missing;
    
    if (not missing(Y)) then
        last_non_missing = Y;

    rename last_non_missing=Y;
    drop Y;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 16:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292494#M60721</guid>
      <dc:creator>paulkaefer</dc:creator>
      <dc:date>2016-08-18T16:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Pick The Last Non Missing Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292496#M60723</link>
      <description>&lt;P&gt;with your updated requirement, is this what you want? note that the Y value when X is 3 will be .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
   input X Y;
   datalines;
1 70
1 .
1 .
1 .
1 80
1 .
1 .
2 60
2 .
3 .
;

data temp2;
    set temp;
    retain last_non_missing;
    
    if (first.x) then
        last_non_missing = .;

    if (not missing(Y)) then
        last_non_missing = Y;

    by x;
    rename last_non_missing=Y;
    drop Y;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 16:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292496#M60723</guid>
      <dc:creator>paulkaefer</dc:creator>
      <dc:date>2016-08-18T16:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Pick The Last Non Missing Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292508#M60729</link>
      <description>&lt;P&gt;This is a good place to apply the UPDATE trick it handles BY group automatically.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data XY;
   input X Y @@;
   cards;
1 70 1 . 1 . 1 .
1 80 1 . 1 . 
2 60 2 . 3 .
;;;;
   run;
proc print;
   run;
data LOCF;
   update XY(obs=0) XY;
   by X;
   output;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 18:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-The-Last-Non-Missing-Value/m-p/292508#M60729</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-08-18T18:01:25Z</dc:date>
    </item>
  </channel>
</rss>

