<?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: Determining which variable produced the maximum value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473367#M121468</link>
    <description>&lt;P&gt;Here is another way. I learned about VNAME from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/28/jedi-sas-tricks-variable-names-to-values-with-vname/" target="_self"&gt;Jedi SAS Tricks&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input value1-value10;
datalines ;
1 2 3 4 20 6 7 8 9 10
;
run;

data want;
set test;
array values (10)value1-value10;
max_value=max(of value1-value10);
do i=1 to dim(values);
if values(i)=max_value then var=vname(values(i));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Jun 2018 13:05:35 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-06-26T13:05:35Z</dc:date>
    <item>
      <title>Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473348#M121456</link>
      <description>&lt;P&gt;I have 30 numeric variables (named VALUE1, VALUE2, VALUE3, …) and have already written to code to find which has the&amp;nbsp;Maximum value, however, I also need to know which of the 30 numeric variables produced that maximum value. Please see the example code below (this is what I have so far, but I don't know what else I need to get my desired output).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example1;&lt;BR /&gt;set example;&lt;/P&gt;&lt;P&gt;MAX_Value= max(&amp;nbsp;&lt;SPAN&gt;VALUE1, VALUE2, VALUE3, …&lt;/SPAN&gt;, VALUE29, VALUE30);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I just need to know for a given observation if the maximum value is 1000 which of the 30 values did that come from.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 12:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473348#M121456</guid>
      <dc:creator>mdz</dc:creator>
      <dc:date>2018-06-26T12:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473351#M121459</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
    var value1-value30;
    output out=max max=max1-max30;
run;
data want;
    set max;
    array m max1-max30;
    maxvaluevar = whichn(max(of max1-max30),of m[*]);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jun 2018 12:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473351#M121459</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-26T12:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473360#M121466</link>
      <description>&lt;P&gt;After running this code, I realized I may need to add clarity to my goal. It appears this would work to determine across all the observations of Value1 what is the maximum, but that is not my goal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not looking for the maximum for each Value, but instead for a given observation I am trying to find the maximum across the 30 values. For example, for observation 1 I need to know which of the 30 values is the highest (I have already figured out how to code that) and which of the 30 values that maximum came from. Ideally each observation would have a variable named "Max_value" and "Max_variable". &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 12:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473360#M121466</guid>
      <dc:creator>mdz</dc:creator>
      <dc:date>2018-06-26T12:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473367#M121468</link>
      <description>&lt;P&gt;Here is another way. I learned about VNAME from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/28/jedi-sas-tricks-variable-names-to-values-with-vname/" target="_self"&gt;Jedi SAS Tricks&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input value1-value10;
datalines ;
1 2 3 4 20 6 7 8 9 10
;
run;

data want;
set test;
array values (10)value1-value10;
max_value=max(of value1-value10);
do i=1 to dim(values);
if values(i)=max_value then var=vname(values(i));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jun 2018 13:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473367#M121468</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-06-26T13:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473386#M121469</link>
      <description>&lt;P&gt;An alternative works by transposing the dataset and determining the row with the highest value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id $ value1-value10;
datalines ;
A 1 2 3 4 20 6 7 8 9 10
;
run;

proc transpose data=test out=int;
by id;
var value:;
run;

proc sql;
select id, _name_, col1
from int
group by id
having col1 = max(col1);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jun 2018 13:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473386#M121469</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-26T13:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473391#M121470</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/197611"&gt;@mdz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;After running this code, I realized I may need to add clarity to my goal. It appears this would work to determine across all the observations of Value1 what is the maximum, but that is not my goal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not looking for the maximum for each Value, but instead for a given observation I am trying to find the maximum across the 30 values. For example, for observation 1 I need to know which of the 30 values is the highest (I have already figured out how to code that) and which of the 30 values that maximum came from. Ideally each observation would have a variable named "Max_value" and "Max_variable". &amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So run the WHICHN function on each row of your original data.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 13:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473391#M121470</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-26T13:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473394#M121473</link>
      <description>&lt;P&gt;It should be noted that in the case of a tied maximum (i.e. more than one variable having the maximum value) the suggested solutions return different results:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;WHICHN returns (the array index of) the &lt;EM&gt;first&lt;/EM&gt; variable&lt;/LI&gt;
&lt;LI&gt;SuryaKiran's solution returns the name of the &lt;EM&gt;last&lt;/EM&gt; variable&lt;/LI&gt;
&lt;LI&gt;KurtBremser's&lt;SPAN&gt;&amp;nbsp;solution returns the names of&amp;nbsp;&lt;EM&gt;all&lt;/EM&gt; variables&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;of the group of variables sharing the same (maximum) value.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 14:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473394#M121473</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-06-26T14:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473399#M121477</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;Absolutely sir, whichn is the way to go.&amp;nbsp; Loop is not ideal and too costly for this exercise in my opinion&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input value1-value10;
datalines ;
1 2 3 4 20 6 7 8 9 10
;
run;

data want;
set test;
array values (10)value1-value10;
max_value=max(of value1-value10);
var=vname(values(whichn(max_value,of values(*))));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jun 2018 14:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473399#M121477</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-26T14:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473402#M121479</link>
      <description>&lt;P&gt;Agree, In case if multiple values with maximum values then this would list all of the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
Format Var $50.;
set test;
array values (10)value1-value10;
max_value=max(of value1-value10);
do i=1 to dim(values);
if values(i)=max_value then var=CATX('|',strip(var),vname(values(i)));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jun 2018 14:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473402#M121479</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-06-26T14:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473403#M121480</link>
      <description>&lt;P&gt;Wouldn't it depend on the purpose of the result (hopefully documented in specifications), which of the three solutions (i.e. ways of handling ties) is "the way to go"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[But thanks for calling me "sir" -- I &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/INPUT-Function-unexpectedly-producing-missing-values/m-p/472601#M121194" target="_blank"&gt;know&lt;/A&gt;&amp;nbsp;that you mean it as a honorary title. :-)]&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 14:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473403#M121480</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-06-26T14:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Determining which variable produced the maximum value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473405#M121482</link>
      <description>&lt;P&gt;Hmm interesting as you bring in a new dynamic with "ties". Well well, I guess will have to wait and see how OP would want to deal with that and which variable he/she wants to pick.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 14:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-which-variable-produced-the-maximum-value/m-p/473405#M121482</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-26T14:36:42Z</dc:date>
    </item>
  </channel>
</rss>

