Chapter Contents

Previous

Next
SORT

SORT



Sorts observations in a SAS data set by one or more variables, storing the resulting sorted observations in a new SAS data set or replacing the original data set

Language element: procedure
OpenVMS specifics: available sort routines


Syntax
Details
NODUPKEY Option
SORTWKNO= Option
Customizing Collating Sequences
See Also

Syntax

PROC SORT <option(s)> <collating-sequence-option>;

Note:   This is a simplified version of the SORT procedure syntax. For the complete syntax and its explanation, see the SORT procedure in SAS Procedures Guide.  [cautionend]

option(s)

NODUPKEY
under OpenVMS, the observation that is returned is unpredictable; that is, the observation returned is not guaranteed to be the first observation that was encountered for that BY variable. For further explanation of the NODUPKEY option, see NODUPKEY Option.

SORTWKNO=n
specifies the number of sort work files to be used by the OpenVMS sort utility. The value for n can be 0 through 6. For further explanation of the SORTWKNO= option, see SORTWKNO= Option.


Details

By default under OpenVMS, the SORT procedure uses the ASCII collating sequence. Whenever the SORT procedure uses the HOST sort utility, it uses the OpenVMS sort utility. (For information about how the sort utility is chosen, see the discussion of the SORTPGM= system option in SORTPGM=.) The HOST sort utility accepts all options that are available to the SAS sort utility. For a complete list of options, see the SORT procedure in the SAS Procedures Guide.

NODUPKEY Option

The SAS sort utility and the OpenVMS sort utility differ slightly in their implementation of the NODUPKEY option. If you need to use both the NODUPKEY and EQUALS options (that is, if you need to guarantee that the first observation returned is the first observation that was input), then use the SAS sort utility.

When you use the SAS sort utility, the NODUPKEY option implies the EQUALS option by default. As a result, the observation that is returned for like BY values is the first observation that was encountered for the key BY variable. That is, the observations are returned in the order in which they were input.

By contrast, the OpenVMS sort utility does not support the EQUALS option in conjunction with the NODUPKEY option. When NODUPKEY is used with the OpenVMS sort utility, the EQUALS option is set to NOEQUALS unconditionally. As a result, when NODUPKEY is specified with the OpenVMS sort utility, the observation that is returned for observations with like BY values is not guaranteed to be the first observation that was encountered for that BY variable. The observation that the OpenVMS sort utility returns when NODUPKEY is in effect is unpredictable.

SORTWKNO= Option

The SORT procedure also supports the SORTWKNO= option in the PROC SORT statement. The SORTWKNO= option specifies the number of sort work files to be used by the OpenVMS sort utility.

The OpenVMS sort utility can support up to 10 work files. If you set SORTWKNO= to 0 and define the ten sort work files, the SAS System uses the ten files. To use the sort work files, you must define a SORTWORK# logical name for each sort work area. For example:

$DEFINE SORTWORK0  DISK1:[TEMP]
$DEFINE SORTWORK1  DISK2:[TEMP]
$DEFINE SORTWORK2  DISK3:[TEMP]

The following example uses the SORTWKNO= option to specify that four work files should be used:

libname mylib '[mydata]';

proc sort data=mylib.june sortwkno=4;
   by revenue;
run;

Customizing Collating Sequences

The options EBCDIC, ASCII, NATIONAL, DANISH, SWEDISH, and REVERSE specify collating sequences that are stored in the HOST catalog.

If you want to provide your own collating sequences or change a collating sequence provided for you, use the TRANTAB procedure to create or modify translation tables. For complete details on the TRANTAB procedure, see SAS Procedures Guide. When you create your own translation tables, they are stored in your PROFILE catalog, and they override any translation tables that have the same names in the HOST catalog.

Note:   System managers can modify the HOST catalog by copying newly created tables from the PROFILE catalog to the HOST catalog. Then all users can access the new or modified translation table.  [cautionend]

If you are using the SAS windowing environment and want to see the names of the collating sequences that are stored in the HOST catalog, issue the following command from any window:

CATALOG SASHELP.HOST

If you are not using the SAS windowing environment, then issue the following statements to generate a list of the contents of the HOST catalog:

proc catalog catalog=sashelp.host;
contents;
run;
Entries of type TRANTAB are the collating sequences.

To see the contents of a particular translate table, use the following statements:

proc trantab table=table-name;
list;
run;
The contents of collating sequences are displayed in the SAS log.

See Also


Chapter Contents

Previous

Next

Top of Page

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