Chapter Contents

Previous

Next
The SORT Procedure

Concepts


Sorting Orders for Numeric Variables
For numeric variables, the smallest-to-largest comparison sequence is

  1. SAS System missing values (shown as a period or special missing value)

  2. negative numeric values

  3. zero

  4. positive numeric values.


Sorting Orders for Character Variables
PROC SORT uses either the EBCDIC or the ASCII collating sequence when it compares character values, depending on the environment under which the procedure is running.

EBCDIC Order

The operating environments that use the EBCDIC collating sequence include CMS and OS/390.

The sorting order of the English-language EBCDIC sequence is

blank . < ( + | & ! $ * ) ; ¬ - / , % _ > ?: # @ ' = "
a b c d e f g h i j k l m n o p q r ~ s t u v w x y z
{ A B C D E F G H I } J K L M N O P Q R \S T
U V W X Y Z
0 1 2 3 4 5 6 7 8 9

The main features of the EBCDIC sequence are that lowercase letters are sorted before uppercase letters, and uppercase letters are sorted before digits. Note also that some special characters interrupt the alphabetic sequences. The blank is the smallest displayable character.

ASCII Order

The operating environments that use the ASCII collating sequence include

Macintosh PC DOS
MS-DOS UNIX and its derivatives
OpenVMS Windows
OS/2

From the smallest to largest displayable character, the English-language ASCII sequence is

blank ! " # $ % & ' ( ) * + , - . /0 1 2 3 4 5 6 7 8 9 : ; < = > ? @
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z[ \] ˆ_
a b c d e f g h i j k l m n o p q r s t u v w x y z { } ~

The main features of the ASCII sequence are that digits are sorted before uppercase letters, and uppercase letters are sorted before lowercase letters. The blank is the smallest displayable character.


Stored Sort Information
PROC SORT records the BY variables, collating sequence, and character set that it uses to sort the data set. This information is stored with the data set to help avoid unnecessary sorts.

Before PROC SORT sorts a data set, it checks the stored sort information. If you try to sort a data set the way that it is currently sorted, PROC SORT does not perform the sort and writes a message to the log to that effect. To override this behavior, use the FORCE option. If you try to sort a data set the way that it is currently sorted and you specify an OUT= data set, PROC SORT simply makes a copy of the DATA= data set.

To override the sort information that PROC SORT stores, use the _NULL_ value with the SORTEDBY= data set option. For information about SORTEDBY=, see the section on data set options in SAS Language Reference: Dictionary.

If you want to change the sort information for an existing data set, use the SORTEDBY= data set option in the MODIFY statement in the DATASETS procedure. To access the sort information that is stored with a data set, use the CONTENTS statement in PROC DATASETS. For details, see The DATASETS Procedure .


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.