<?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: Finding Last Column with Value and Save Column Name or Number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-Last-Column-with-Value-and-Save-Column-Name-or-Number/m-p/596649#M171821</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data input;
 input id1 supply1 supply2 supply3 supply4;
 datalines;
1 20 28 .  .
1 30 30 30 30
1 20 28 28 .
2 20 28 .  .
2 30 30 28 28
3 30 .  .  .
4 30 28 30 30
5 20 30 .  .
6 10 28 28 28
6 10 28 30 .
 ;

data want1;
set input;
array s(*)  supply4- supply1;
max=dim(s)-whichn(coalesce(of s(*)),of s(*))+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*OR*/&lt;/P&gt;
&lt;P&gt;Better to have both name and position in one solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
set input;
array s(*)  supply4- supply1;
array t(*)  supply1- supply4;
max=dim(s)-whichn(coalesce(of s(*)),of s(*))+1;
var_name=vname(t(max));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Oct 2019 20:05:14 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-15T20:05:14Z</dc:date>
    <item>
      <title>Finding Last Column with Value and Save Column Name or Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Last-Column-with-Value-and-Save-Column-Name-or-Number/m-p/596646#M171820</link>
      <description>&lt;P&gt;I am trying to loop across the columns of my data set and find the last column of a set of sequentially named columns has data in it and store off some indicator of which column that is. My input data looks as follows&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;
 input id1 supply1 supply2 supply3 supply4;
 datalines;
1 20 28 .  .
1 30 30 30 30
1 20 28 28 .
2 20 28 .  .
2 30 30 28 28
3 30 .  .  .
4 30 28 30 30
5 20 30 .  .
6 10 28 28 28
6 10 28 30 .
 ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I am trying to achieve something along the lines of the following two outputs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output;
 input id1 max;
 datalines;
1 2
1 4
1 3
2 2
2 4
3 1
4 4
5 2
6 4
6 3
 ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output2;
 input id1 max $10.;
 datalines;
1 supply2
1 supply4
1 supply3
2 supply2
2 supply4
3 supply1
4 supply4
5 supply2
6 supply4
6 supply3
 ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am really at a loss as to what is the best way to accomplish something like this. Either of the outputs can be attached as a new column to the original input as well, as that is the end goal is to have a column on each line indicating what the last sequential column with data is for each row. Thanks for any help you can give me&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 19:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Last-Column-with-Value-and-Save-Column-Name-or-Number/m-p/596646#M171820</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2019-10-15T19:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Last Column with Value and Save Column Name or Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Last-Column-with-Value-and-Save-Column-Name-or-Number/m-p/596649#M171821</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data input;
 input id1 supply1 supply2 supply3 supply4;
 datalines;
1 20 28 .  .
1 30 30 30 30
1 20 28 28 .
2 20 28 .  .
2 30 30 28 28
3 30 .  .  .
4 30 28 30 30
5 20 30 .  .
6 10 28 28 28
6 10 28 30 .
 ;

data want1;
set input;
array s(*)  supply4- supply1;
max=dim(s)-whichn(coalesce(of s(*)),of s(*))+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*OR*/&lt;/P&gt;
&lt;P&gt;Better to have both name and position in one solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
set input;
array s(*)  supply4- supply1;
array t(*)  supply1- supply4;
max=dim(s)-whichn(coalesce(of s(*)),of s(*))+1;
var_name=vname(t(max));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 20:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Last-Column-with-Value-and-Save-Column-Name-or-Number/m-p/596649#M171821</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-15T20:05:14Z</dc:date>
    </item>
  </channel>
</rss>

