Sample 46471: Return the variable name that contains the max or min value across an observation
This macro gives you the variable name of the maximum or minimum value across an observation.
The macro contains 3 parameters:
1st parameter is the name of the SAS data set
2nd parameter is the list of the variables (separated by a space) that you want to check
(if all variables need to be checked just pass in the value of _numeric_)
3rd parameter is the function to use, either pass in max or min
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/** Sample data set **/
data one;
input a b c d e;
cards;
1 3 12 6 15
34 583 294 493 2
;
%macro test(dsn,vars,func);
data new;
set &dsn;
array list(*) &vars;
&func = vname(list[whichn(&func(of list[*]), of list[*])]);
run;
%mend test;
/** retrieve maximum value from a b and c **/
%test(one,a b c,max)
proc print;
run;
/** retrieve maximum value from all numeric variables **/
%test(one,_numeric_,max)
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/** First PROC PRINT **/
Obs a b c d e max
1 1 3 12 6 15 c
2 34 583 294 493 2 b
/** Second PROC PRINT **/
Obs a b c d e max
1 1 3 12 6 15 e
2 34 583 294 493 2 b
This macro gives you the variable name that contains the maximum value or the minimum value for each observation.
Date Modified: | 2012-10-01 10:25:02 |
Date Created: | 2012-05-02 10:16:47 |
Operating System and Release Information
SAS System | Base SAS | Aster Data nCluster on Linux x64 | | |
DB2 Universal Database on AIX | | |
DB2 Universal Database on Linux x64 | | |
Greenplum on Linux x64 | | |
Netezza TwinFin 32bit blade | | |
Netezza TwinFin 32-bit SMP Hosts | | |
Netezza TwinFin 64-bit S-Blades | | |
Netezza TwinFin 64-bit SMP Hosts | | |
Teradata on Linux | | |
z/OS | | |
Z64 | | |
OpenVMS VAX | | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
Microsoft Windows XP 64-bit Edition | | |
Microsoft® Windows® for x64 | | |
OS/2 | | |
Microsoft Windows 95/98 | | |
Microsoft Windows 2000 Advanced Server | | |
Microsoft Windows 2000 Datacenter Server | | |
Microsoft Windows 2000 Server | | |
Microsoft Windows 2000 Professional | | |
Microsoft Windows NT Workstation | | |
Microsoft Windows Server 2003 Datacenter Edition | | |
Microsoft Windows Server 2003 Enterprise Edition | | |
Microsoft Windows Server 2003 Standard Edition | | |
Microsoft Windows Server 2003 for x64 | | |
Microsoft Windows Server 2008 | | |
Microsoft Windows Server 2008 for x64 | | |
Microsoft Windows XP Professional | | |
Windows 7 Enterprise 32 bit | | |
Windows 7 Enterprise x64 | | |
Windows 7 Home Premium 32 bit | | |
Windows 7 Home Premium x64 | | |
Windows 7 Professional 32 bit | | |
Windows 7 Professional x64 | | |
Windows 7 Ultimate 32 bit | | |
Windows 7 Ultimate x64 | | |
Windows Millennium Edition (Me) | | |
Windows Vista | | |
Windows Vista for x64 | | |
64-bit Enabled AIX | | |
64-bit Enabled HP-UX | | |
64-bit Enabled Solaris | | |
ABI+ for Intel Architecture | | |
AIX | | |
HP-UX | | |
HP-UX IPF | | |
IRIX | | |
Linux | | |
Linux for x64 | | |
Linux on Itanium | | |
OpenVMS Alpha | | |
OpenVMS on HP Integrity | | |
Solaris | | |
Solaris for x64 | | |
Tru64 UNIX | | |