Usage Note 35865: How to determine the kth largest or smallest non-missing value
New functions LARGEST and SMALLEST are available in SAS 9.0 and above.
They return the kth value for non-missing values.
Sample code is located in the Full Code tab.
Additional information is available by clicking the links below.
Functions and CALL Routines by Category for SAS 9.1.3
Functions and CALL Routines for SAS 9.2
Operating System and Release Information
| SAS System | Base SAS | z/OS | 9 TS M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9 TS M0 | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9 TS M0 | |
| Microsoft Windows 2000 Advanced Server | 9 TS M0 | |
| Microsoft Windows 2000 Datacenter Server | 9 TS M0 | |
| Microsoft Windows 2000 Server | 9 TS M0 | |
| Microsoft Windows 2000 Professional | 9 TS M0 | |
| Microsoft Windows NT Workstation | 9 TS M0 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9 TS M0 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9 TS M0 | |
| Microsoft Windows Server 2003 Standard Edition | 9 TS M0 | |
| Microsoft Windows XP Professional | 9 TS M0 | |
| 64-bit Enabled AIX | 9 TS M0 | |
| 64-bit Enabled HP-UX | 9 TS M0 | |
| 64-bit Enabled Solaris | 9 TS M0 | |
| HP-UX IPF | 9 TS M0 | |
| Linux | 9 TS M0 | |
| OpenVMS Alpha | 9 TS M0 | |
| Tru64 UNIX | 9 TS M0 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
To see the results of the code below, go to the Results/Output tab
data largest;
input a b c d;
firstl=largest(1,a,b,c,d);
secondl=largest(2,a,b,c,d);
thirdl=largest(3,a,b,c,d);
fourthl=largest(4,a,b,c,d);
datalines;
2 4 6 8
;
run;
proc print;
title 'LARGEST';
run;
data smallest;
input a b c d;
firsts=smallest(1,a,b,c,d);
seconds=smallest(2,a,b,c,d);
thirds=smallest(3,a,b,c,d);
fourths=smallest(4,a,b,c,d);
datalines;
2 4 6 8
;
run;
proc print;
title 'SMALLEST';
run;
LARGEST
Obs a b c d firstl secondl thirdl fourthl
1 2 4 6 8 8 6 4 2
SMALLEST
Obs a b c d firsts seconds thirds fourths
1 2 4 6 8 2 4 6 8
This can find the first, second, third, or whatever level of the value you need across multiple values.
| Type: | Usage Note |
| Priority: | |
| Topic: | SAS Reference ==> Functions ==> Descriptive Statistics ==> LARGEST SAS Reference ==> Functions ==> Descriptive Statistics ==> SMALLEST
|
| Date Modified: | 2009-12-04 10:34:20 |
| Date Created: | 2009-05-08 15:04:41 |