SAS Component Language Dictionary |
Sorts an array
rc=ASORT(array<,order><,elements>);
|
-
rc
-
contains the return code for the operation:
0 |
successful |
0 |
not successful |
Type:
Numeric
-
array
-
is an SCL array that was declared in an
ARRAY statement.
Type: Character
-
order
-
specifies the order for the sort:
'A' |
ascending order (the default) |
'D' |
descending order |
Type:
Character
-
elements
-
is the number of elements to sort.
Type: Numeric
By default, the
array is sorted in ascending order. You can use the optional order argument to specify either ascending or descending order.
By default, the
entire array is sorted. You can use
the optional elements argument to restrict sorting
to the specified number of elements (starting from the beginning of the array).
If the value of the elements
argument is greater than the total number of array elements, the program halts
execution and sends an error message to the log.
Sort the first five items of array VALUES in ascending
order:
array values[8] val1-val8 (3,5,2,1,6,8,7,4);
if (asort(values,'d',5)) then _msg_=sysmsg();
else do;
_msg_='Sort was successful';
do i=1 to dim(values);
put values{i}=;
end;
end;
This produces the following output:
values[ 1 ]=6
values[ 2 ]=5
values[ 3 ]=3
values[ 4 ]=2
values[ 5 ]=1
values[ 6 ]=8
values[ 7 ]=7
values[ 8 ]=4
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.