Previous Page | Next Page

SAS Component Language Dictionary

SORT



Sorts a SAS table by one or more columns
Category: SAS Table

Syntax
Details
Example

Syntax

sysrc=SORT(table-id,col-list-1<. . .col-list-4>);

sysrc

contains the return code for the operation:

0

successful

[ne]0

not successful

Type: Numeric

table-id

contains the identifier that was assigned when the table was opened. The table must be open in UPDATE mode. If table-id is invalid, the program halts.

Type: Numeric

col-list

is one to four quoted strings of columns or options, separated by blanks. For a list of options, the first character in the list must be a forward slash (/). Columns and options cannot be mixed in the same list.

Type: Character


Details

SORT uses the sorting program that SAS supports on your operating system. If a column list contains more than one column, the table is sorted by those columns in the order in which they are specified.

You can use the following options for col-list, depending on your operating system:

DATECOPY
DIAG
EQUALS
FORCE
LEAVE
LIST
MESSAGE
NODUPKEY
NODUPLICATES
NOEQUALS
OUT
REVERSE
SORTSEQ=ASCII|EBCDIC|DANISH|FINNISH
   |NATIONAL|NORWEGIAN|SWEDISH
SORTSIZE
SORTWKNO
TAGSORT
TRANTAB

SAS views cannot be sorted in place. To sort views, you must specify an output SAS table.

If a SAS table is already in sorted order, then you must use the FORCE option.

Note:   Unless you specify the FORCE option, the SORT function and PROC SORT do not sort and replace an indexed SAS table, because sorting destroys indexes for the table.  [cautionend]


Example

Use the SORT function with the options NODUPKEY, NODUPLICATES, and TAGSORT to sort the SAS table MYDATA by column A in ascending order and by column B in descending order:

rc=sort(mydataid,'a descending b',
'/ nodupkey noduplicates tagsort');

Previous Page | Next Page | Top of Page