<?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: how to find out the last non missing value in a list of variable in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540012#M148909</link>
    <description>&lt;P&gt;True (although whether actual numbers (rather than formatted) can contain commas is a different discussion&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; ) and hadn't though about that.&amp;nbsp; Just replace the comma usage:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  lastmissing=scan(catx('|',of a--d),-1,'|');
run;&lt;/PRE&gt;
&lt;P&gt;A bar (pipe) for instance.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Mar 2019 13:09:42 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2019-03-04T13:09:42Z</dc:date>
    <item>
      <title>how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/539992#M148896</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input a b c d;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 . 4&lt;BR /&gt;4 . 3 6&lt;BR /&gt;2 3 5 .&lt;BR /&gt;. 2 3 5&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to find out the &lt;STRONG&gt;last non-missing&lt;/STRONG&gt; value?&lt;/P&gt;&lt;P&gt;Generally if we use coalesce function we get &lt;STRONG&gt;first non-missing&lt;/STRONG&gt; value right.&lt;/P&gt;&lt;P&gt;I am looking for last non-missing value.... in the same sequencial order &lt;STRONG&gt;(a,b.c.d...) or (A--D);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 11:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/539992#M148896</guid>
      <dc:creator>vThanu</dc:creator>
      <dc:date>2019-03-04T11:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/539993#M148897</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a b c d;
cards;
1 2 . 4
4 . 3 6
2 3 5 .
. 2 3 5
;
run;

data want(drop = i);
set have;
array nums[*] A--D;
do i = dim(nums) to 1 by -1 until (i=1 or vvalue(nums[i]) ne . );
	LastNonMissing = nums[i];
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;LastNonMissing will be missing if the entire row is missing.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 11:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/539993#M148897</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2019-03-04T11:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/539997#M148900</link>
      <description>&lt;P&gt;As an alternative to the array method:&lt;/P&gt;
&lt;PRE&gt;data have;
input a b c d;
cards;
1 2 . 4
4 . 3 6
2 3 5 .
. 2 3 5
;
run;

data want;
  set have;
  lastmissing=scan(catx(',',of a--d),-1,',');
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2019 11:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/539997#M148900</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-04T11:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540005#M148904</link>
      <description>&lt;P&gt;Thanks for your support....&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 12:30:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540005#M148904</guid>
      <dc:creator>vThanu</dc:creator>
      <dc:date>2019-03-04T12:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540008#M148905</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
NM= coalesce(d,c,b,a);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2019 12:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540008#M148905</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2019-03-04T12:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540010#M148907</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; This is a really elegant solution however sometimes numbers contain commas which could throw your results off.&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 have;
format a b c d comma9.;
input a b c d;
cards;
1 2 . 4
4 . 3 6
2 3 5 .
. 2 3 5
4 . 3000 .
;
run;

data want(drop = i);
set have;
array nums[*] A--D;
do i = dim(nums) to 1 by -1 until (i=1 or nums[i] ne . ); *Modified to get rid of vvalue;
	LastNonMissing = nums[i];
end;
lastmissing=scan(catx(',',of a--d),-1,','); *from RW9;
NM= coalesce(d,c,b,a); * from mansour_ib_sas;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 13:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540010#M148907</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2019-03-04T13:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540011#M148908</link>
      <description>&lt;P&gt;Yes, the coalesce is a good idea, only problem is you can't do lists in reverse.&amp;nbsp; It would be great to do:&lt;/P&gt;
&lt;PRE&gt;  lastmissing=coalesce(of d--a);&lt;/PRE&gt;
&lt;P&gt;But we can't as that's not the order of the variables.&amp;nbsp; So needing to put a lot of variables in the line could get long winded.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 13:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540011#M148908</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-04T13:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540012#M148909</link>
      <description>&lt;P&gt;True (although whether actual numbers (rather than formatted) can contain commas is a different discussion&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; ) and hadn't though about that.&amp;nbsp; Just replace the comma usage:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  lastmissing=scan(catx('|',of a--d),-1,'|');
run;&lt;/PRE&gt;
&lt;P&gt;A bar (pipe) for instance.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 13:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540012#M148909</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-04T13:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540037#M148918</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/247664"&gt;@vThanu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the interesting question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solutions you received so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Loop aka linear search&lt;/P&gt;
&lt;P&gt;2. Colaesce ( problem: &lt;STRONG&gt;what if you have numerous variables to reverse the list&lt;/STRONG&gt;, this would involve loading the list in a macro var in a reverse order&lt;/P&gt;
&lt;P&gt;3. scan ( didn;t work as it didn;t produce 4 6 5 5 as the wanted result but I think this is a slick approach regardless)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One easy approach in my opinion is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a b c d;
cards;
1 2 . 4
4 . 3 6
2 3 5 .
. 2 3 5
;
run;

data want;
set have;
temp=compress(cats(of a--d),'.');
lastnonmissing=char(temp,length(temp));
drop temp;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This handles the variable list conveniently, stripping of '.' from the last and extracting the last one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;a b c d lastnonmissing 
1 2 . 4 4 
4 . 3 6 6 
2 3 5 . 5 
. 2 3 5 5 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 14:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540037#M148918</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-04T14:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out the last non missing value in a list of variable in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540433#M149090</link>
      <description>&lt;P&gt;Another solution is possible:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input a b c d;
cards;
1 2 . 4
4 . 3 6
2 3 5 .
. 2 . .
;
run;

proc contents noprint  data=test out=test1;run;

proc sql noprint ;
select name into : col separated by ' ' from test1 order by varnum desc;
quit;

 
data test1(drop=i);
set test;
array nums &amp;amp;col.;
do i=dim(nums) to 1 by -1;
if nums(i) ^= . then do;
 lnm=nums(i);
output;
leave;
end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Mar 2019 13:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-out-the-last-non-missing-value-in-a-list-of-variable/m-p/540433#M149090</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2019-03-05T13:34:10Z</dc:date>
    </item>
  </channel>
</rss>

