Previous Page | Next Page

SAS Component Language Dictionary

SORTLIST



Sorts the items in an SCL list by value or by name
Category: List

Syntax
Details
Examples
See Also

Syntax

rc=SORTLIST(list-id<,options<,start-index<,n-items>>>);

rc

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.

Type: Numeric

list-id

is the identifier of the list to sort. An invalid list-id produces an error condition.

Type: Numeric or List

options

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.

'ASCENDING'

Sort the list in ascending order. (This is a default.)

'DESCENDING'

Sort the list in descending order.

'IGNORECASE'

Ignore case when comparing string values. Case is always ignored when sorting by name, because names are always converted to uppercase.

'NAME'

Sort the list by item name. Unnamed items appear before named items in an ascending sort.

'NODUP'

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.

'OBEYCASE'

Obey case when comparing string values. This is the default when sorting by value.

'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.)

Type: Character

start-index

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.

Type: Numeric

n-items

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.

Type: Numeric


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


See Also

HASATTR

REVLIST

ROTLIST

SETLATTR

Previous Page | Next Page | Top of Page