<?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: Maximum Variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36587#M9225</link>
    <description>Very clean, Olivier.  The VNAME function had escaped me and so I used the macro variable (parsing) approach.  Thanks for the great tip!&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Thu, 07 Aug 2008 13:08:19 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2008-08-07T13:08:19Z</dc:date>
    <item>
      <title>Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36579#M9217</link>
      <description>Hi &lt;BR /&gt;
&lt;BR /&gt;
I have a list of 8 variables and want to find the largest variable for each record.&lt;BR /&gt;
For example if my data looked like this:&lt;BR /&gt;
Key  age1 age2 age3 age4&lt;BR /&gt;
001    0.5  0.6    0.7   0.3&lt;BR /&gt;
002   0.8  1.7    1.2   4.6&lt;BR /&gt;
I would like to create a variable that looks like this:&lt;BR /&gt;
Key  age1  age2  age3  age4            maxv&lt;BR /&gt;
001    0.5   0.6     0.7     0.3               age3&lt;BR /&gt;
002   0.8   1.7     1.2     4.6                age4&lt;BR /&gt;
&lt;BR /&gt;
Anyone know how I could do this, or something similar?</description>
      <pubDate>Wed, 06 Aug 2008 09:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36579#M9217</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-06T09:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36580#M9218</link>
      <description>Hi,&lt;BR /&gt;
try the MAX-function (in a data step):&lt;BR /&gt;
&lt;BR /&gt;
maxv = max(age1, age2, age3, age4); or in your specific case with a variable list:&lt;BR /&gt;
maxv = max(of age1-age4);&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Linus</description>
      <pubDate>Wed, 06 Aug 2008 11:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36580#M9218</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-08-06T11:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36581#M9219</link>
      <description>One technique is to use a SAS macro variable to identify/track the age values, presuming the data sample you provided. Here's some SAS code that works.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
%let ages = age1 age2 age3 age4;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
input Key $ &amp;amp;ages;&lt;BR /&gt;
* use array to interrogate age# var list for max. ;&lt;BR /&gt;
array _agevars (*) &amp;amp;ages ;&lt;BR /&gt;
do i=1 to dim(_agevars);&lt;BR /&gt;
  if _agevars(i) gt _maxval then do;&lt;BR /&gt;
    drop _maxval;&lt;BR /&gt;
    * keep track of the max var-value thus far. ;&lt;BR /&gt;
    _maxval = _agevars(i);&lt;BR /&gt;
	* keep track of the var-name having max value thus far. ;&lt;BR /&gt;
	maxv = upcase(scan("&amp;amp;ages",i,' '));&lt;BR /&gt;
  end;&lt;BR /&gt;
end;&lt;BR /&gt;
putlog _all_;&lt;BR /&gt;
datalines;&lt;BR /&gt;
001 0.5 0.6 0.7 0.3&lt;BR /&gt;
002 0.8 1.7 1.2 4.6&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 06 Aug 2008 12:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36581#M9219</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-08-06T12:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36582#M9220</link>
      <description>thanks Linus, this gave me the value of the maximum variable, whereas I was after the variable name, however I will definitely use this in the future!</description>
      <pubDate>Wed, 06 Aug 2008 13:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36582#M9220</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-06T13:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36583#M9221</link>
      <description>thank you Scott that worked perfectly</description>
      <pubDate>Wed, 06 Aug 2008 13:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36583#M9221</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-06T13:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36584#M9222</link>
      <description>you can use the function varname and varnum combine with macro to do that</description>
      <pubDate>Thu, 07 Aug 2008 03:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36584#M9222</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-07T03:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36585#M9223</link>
      <description>use these two function you do not need to know the variname, only do loop on the variable number, but be ware that you should use %sysfun in the macro enviroment</description>
      <pubDate>Thu, 07 Aug 2008 03:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36585#M9223</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-07T03:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36586#M9224</link>
      <description>Hi.&lt;BR /&gt;
What seems to me a simpler solution -- no macros needed, just use the VNAME function.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data out (drop = i max_age) ;&lt;BR /&gt;
	set in ;&lt;BR /&gt;
	array ages age: ;&lt;BR /&gt;
	max_age=MAX(OF age:) ;&lt;BR /&gt;
	do i=1 TO DIM(ages) ;&lt;BR /&gt;
		if ages(i) = max_age then maxv=VNAME(ages(i)) ;&lt;BR /&gt;
	end ;&lt;BR /&gt;
run ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards,&lt;BR /&gt;
Olivier</description>
      <pubDate>Thu, 07 Aug 2008 07:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36586#M9224</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2008-08-07T07:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36587#M9225</link>
      <description>Very clean, Olivier.  The VNAME function had escaped me and so I used the macro variable (parsing) approach.  Thanks for the great tip!&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 07 Aug 2008 13:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Maximum-Variable/m-p/36587#M9225</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-08-07T13:08:19Z</dc:date>
    </item>
  </channel>
</rss>

