<?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 Idenfitying variable with the lowest/highest values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155975#M40933</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have this sample dataset and want to identify the variable with either the highest or lowest value. So in this case not to report the value but report the variable. Does anyone have any suggestions on how to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Var2&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Var3&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;WANT_Lowest&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;WANT_Highest&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;20&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;50&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;30&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Var1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Var2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;0.90&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;0.25&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;0.10&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Var3&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Var1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I want these two variables. As we can see with ID=1, the highest value is Var2 so the WANT_highest is coded Var2.&amp;nbsp; Similaringly with the lowest for Var1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the easiest way to do this? I know the max/min function will return the values. But in this case I want it to return the variable name.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Dec 2014 14:26:17 GMT</pubDate>
    <dc:creator>Tpham</dc:creator>
    <dc:date>2014-12-18T14:26:17Z</dc:date>
    <item>
      <title>Idenfitying variable with the lowest/highest values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155975#M40933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have this sample dataset and want to identify the variable with either the highest or lowest value. So in this case not to report the value but report the variable. Does anyone have any suggestions on how to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid #000000; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Var2&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Var3&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;WANT_Lowest&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;WANT_Highest&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;20&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;50&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;30&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Var1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Var2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;0.90&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;0.25&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;0.10&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Var3&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;Var1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I want these two variables. As we can see with ID=1, the highest value is Var2 so the WANT_highest is coded Var2.&amp;nbsp; Similaringly with the lowest for Var1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the easiest way to do this? I know the max/min function will return the values. But in this case I want it to return the variable name.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Dec 2014 14:26:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155975#M40933</guid>
      <dc:creator>Tpham</dc:creator>
      <dc:date>2014-12-18T14:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Idenfitying variable with the lowest/highest values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155976#M40934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, let me re-do that, I see you don't want the value.&amp;nbsp; I would transpose, then you can do normal min/max:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id=1; var1=20; var2=50; var3=30; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var var1-var3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Arrays are probably the easiest:&lt;BR /&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array var{3};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; want_lowest=min(of var{*});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; want_highest=max(of var{*});&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Dec 2014 14:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155976#M40934</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-12-18T14:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Idenfitying variable with the lowest/highest values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155977#M40935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array arr&lt;LI&gt; Var1--Var3;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length WANT_Lowest WANT_Highest $32;&lt;/P&gt;&lt;P&gt;&amp;nbsp; WANT_Lowest = vname(arr[whichn(min(of arr&lt;LI&gt;), of arr&lt;/LI&gt;&lt;LI&gt;)]);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; WANT_Highest = vname(arr[whichn(max(of arr&lt;LI&gt;), of arr&lt;/LI&gt;&lt;LI&gt;)]);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Dec 2014 14:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155977#M40935</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-12-18T14:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Idenfitying variable with the lowest/highest values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155978#M40936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input ID Var1 Var2 Var3&amp;nbsp; ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 20 50 30 &lt;BR /&gt;2 0.90 0.25 0.10 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array vars{*} var1-var3;&lt;BR /&gt;max_val=max(var1, var2,var3);&lt;BR /&gt;min_val=min(var1, var2,var3);&lt;/P&gt;&lt;P&gt;do i=1 to dim(vars) until(vars{i}=max_val);&lt;BR /&gt; WANT_Highest=vname(vars{i});&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;do i=1 to dim(vars) until(vars{i}=min_val);&lt;BR /&gt; WANT_Lowest=vname(vars{i});&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;drop max_val min_val i;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Dec 2014 15:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Idenfitying-variable-with-the-lowest-highest-values/m-p/155978#M40936</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-12-18T15:08:32Z</dc:date>
    </item>
  </channel>
</rss>

