<?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 pick multiple column names for a max value using vname function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560175#M156567</link>
    <description>&lt;P&gt;So where is the value "highest_variance" supposed to come from?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please describe exactly how you will use that variable with all the comma separated values. Many times when we see this sort of request we get another one a week or two later about pulling that combined value apart for actual use.&lt;/P&gt;</description>
    <pubDate>Mon, 20 May 2019 15:12:35 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-05-20T15:12:35Z</dc:date>
    <item>
      <title>How to pick multiple column names for a max value using vname function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560171#M156564</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do i fetch multiple column name for a value using Vname function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Input*/
Vid	sep_2017	Oct_2017	Nov_2017	Dec_2017	jan_2018	max
aa	3	0	5	1	0	5
bb	4	4	4	4	2	4
cc	8	3	8	1	2	8
dd	0	0	0	5	1	5
ee	9	2	5	6	9	9

/*expected output**/

Vid	sep_2017	Oct_2017	Nov_2017	Dec_2017	jan_2018	max	Period
aa	3	0	5	1	0	5	Nov_2017
bb	4	4	4	4	2	4	sep_2017,Oct_2017,Nov_2017,Dec_2017
cc	8	3	8	1	2	8	sep_2017,Nov_2017
dd	0	0	0	5	1	5	Dec_2017
ee	9	2	5	6	9	9	sep_2017,Dec_2017

/**Code**/


Data want;
Length period $200.;
Set need;
Array V (*) sep_2017 -- jan_2018 ;
do i = 1 to dim(v)until (i = DIM(V));
if v{i}=Highest_variance then do;
name=vname(v[whichn(Highest_variance, of v{i} )]);
period=CATX(',',period,name);
end;
end;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 15:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560171#M156564</guid>
      <dc:creator>SAS_prep</dc:creator>
      <dc:date>2019-05-20T15:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick multiple column names for a max value using vname function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560175#M156567</link>
      <description>&lt;P&gt;So where is the value "highest_variance" supposed to come from?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please describe exactly how you will use that variable with all the comma separated values. Many times when we see this sort of request we get another one a week or two later about pulling that combined value apart for actual use.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 15:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560175#M156567</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-20T15:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick multiple column names for a max value using vname function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560180#M156572</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;apologies for the incorrect code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Input*/
Vid	sep_2017	Oct_2017	Nov_2017	Dec_2017	jan_2018	max
aa	3	0	5	1	0	5
bb	4	4	4	4	2	4
cc	8	3	8	1	2	8
dd	0	0	0	5	1	5
ee	9	2	5	6	9	9

/*expected output**/

Vid	sep_2017	Oct_2017	Nov_2017	Dec_2017	jan_2018	max	Period
aa	3	0	5	1	0	5	Nov_2017
bb	4	4	4	4	2	4	sep_2017,Oct_2017,Nov_2017,Dec_2017
cc	8	3	8	1	2	8	sep_2017,Nov_2017
dd	0	0	0	5	1	5	Dec_2017
ee	9	2	5	6	9	9	sep_2017,Dec_2017

/**Code**/


Data want;
Length period $200.;
Set need;
Array V (*) sep_2017 -- jan_2018 ;
do i = 1 to dim(v)until (i = DIM(V));
if v{i}=max then do;
name=vname(v[whichn(max, of v{i} )]);
period=CATX(',',period,name);
end;
end;
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, 20 May 2019 15:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560180#M156572</guid>
      <dc:creator>SAS_prep</dc:creator>
      <dc:date>2019-05-20T15:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick multiple column names for a max value using vname function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560182#M156573</link>
      <description>&lt;P&gt;You can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Vid $	sep_2017	Oct_2017	Nov_2017	Dec_2017	jan_2018 max;
datalines;
aa	3	0	5	1	0	5
bb	4	4	4	4	2	4
cc	8	3	8	1	2	8
dd	0	0	0	5	1	5
ee	9	2	5	6	9	9
;

data temp;
   set have;
   array v{*} sep_2017 -- jan_2018;
   do i=1 to dim(v);
      varname=vname(v[i]);
      value=v[i];
      output;
   end;
run;

proc sql;
   create table temp2 as
      select * from temp
      group by Vid
      having value=max(value);
quit;

data want; 
   do until (last.Vid);
      set temp2;
      Length period $200.;
      by Vid;
      Period=catx(', ', Period, varname);
   end;
   drop i varname value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 15:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560182#M156573</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-20T15:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick multiple column names for a max value using vname function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560240#M156612</link>
      <description>&lt;P&gt;Your loop is a little convoluted. Why are your using the UNTIL() clause?&lt;/P&gt;
&lt;P&gt;Calculate the max value before the loop.&lt;/P&gt;
&lt;P&gt;Then you just need to loop over the array and call the VNAME() function when you have hit a copy of the max value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set need;
  length period $200.;
  array V sep_2017 -- jan_2018 ;
  max = max(of v[*]);
  do i = 1 to dim(v);
    if v[i]=max then period=catx(',',period,vname(v[i]));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 18:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-multiple-column-names-for-a-max-value-using-vname/m-p/560240#M156612</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-20T18:00:14Z</dc:date>
    </item>
  </channel>
</rss>

