SAS Component Language Dictionary |
Category: | Array |
Syntax | |
Details | |
Example |
Syntax |
rc=ASORT(array<,order><,elements>); |
contains the return code for the operation:
0 | |
0 |
specifies the order for the sort:
'A' | |
'D' |
Details |
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.
Example |
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.