SAS Component Language Dictionary |
Category: | List |
Syntax | |
Details | |
Examples | |
See Also |
Syntax |
rc=SORTLIST(list-id<,options<,start-index<,n-items>>>); |
contains the identifier of the sorted list. The value passed as list-id is returned unless there is an error. The value 0 means out of memory.
is the identifier of the list to sort. An invalid list-id produces an error condition.
specify how the sort operation is performed. Multiple options can be specified, separated by blanks. Each option can be abbreviated to a unique substring. The substring can be as short as the first character for all options except 'NAME' and 'NODUP', which may be abbreviated to two characters, 'NA' or 'NO', respectively. Later keywords override previous keywords.
Ignore case when comparing string values. Case is always ignored when sorting by name, because names are always converted to uppercase.
Sort the list by item name. Unnamed items appear before named items in an ascending sort.
Delete duplicate items when sorting. All but the first item in the sort range that have the same value (or the same name, if sorting by name) are deleted. The default is not to delete duplicates.
Obey case when comparing string values. This is the default when sorting by value.
Sort the list by item value. In an ascending sort, character items precede list identifiers, which precede numeric missing values, followed by non-missing numeric values. (This is a default.)
specifies the starting position for sorting a range of items in the list. By default, start-index is 1 (the first item). If start-index is positive, then the range begins start-index items from the beginning of the list. If start-index is negative, then the range begins at the item specified by ABS(start-index) items from the end of the list. An error condition results if the absolute value of start-index is zero or if it is greater than the number of items in the list.
specifies the number of items in the list to sort. The default is all items between start-index and the opposite end of the list. To explicitly specify all items, specify -1.
Details |
SORTLIST does not make a copy of the list before it is sorted. The list is modified in place.
Sublists that are contained in the sorted list are not sorted recursively.
When you specify the 'NODUP' and 'IGNORECASE' options, the character list items or names that are spelled the same but differ only in case are considered duplicates, and all but the first occurrence are removed from the sorted list.
An error occurs if the list has the NOUPDATE attribute or if an item to be removed has the NODELETE attribute, if NODUP is specified. Use HASATTR to check the attributes of a list or item. To change attributes, use SETLATTR.
Examples |
Sort the first 10 items in a list in descending order:
list=sortlist(list,'D',1,10);
Sort the last 16 items in a list in ascending order:
list=sortlist(list,'',-1,16);
Sort the second ten items in a list in ascending name order, deleting items that have duplicate names:
list=sortlist(list,'NODUP ASCENDING NAME',11,10);
See Also |
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.