SORT Clause in a View Descriptor

Using the SORT Clause in a View Descriptor

When you define a view descriptor, you can also include a SORT clause to specify data order. You can reference only the data fields selected for the view descriptor, and the data fields must be descriptors. That is, they must have indexes. Without a SORT clause or a SAS BY statement, the data order is determined by ADABAS.
A SAS BY statement automatically issues a SORT clause to ADABAS. If a view descriptor already contains a SORT clause, the BY statement overrides the sort for that program. An exception is when the SAS procedure includes the NOTSORTED option. Then, the SAS BY statement is ignored, and the view descriptor SORT clause is used; a message is written to the log when NOTSORTED causes a SAS BY statement to be ignored.

View SORT Clause Syntax

The syntax for the SORT clause is
SUBSET SORT field-name <,field-name> <,field-name> <option>
The elements of the SORT clause are described below.
field-name
is the name of an ADABAS data field or its corresponding SAS variable name to sort by. The data field must be an ADABAS descriptor. That is, it must be a key data field. You can use the data field's ADABAS field name or its DDM name.
You can specify up to three data fields; you can separate them with commas. If you specify more than one field name, the values are ordered by the first named field, then the second, and so on.
option
is one of the following, which applies to all specified field names. That is, you cannot specify an option for one field name and a different option for another field name.
<ASCENDING|ASCENDISN|DESCENDING>
ASCENDING
indicates the sort is to be in ascending order (low-to-high). For example, A, B, C, D or 1, 2, 3 4. The default is ASCENDING.
ASCENDISN
indicates the sort is to be in ascending ISN (internal sequence number) order. Each logical record in an ADABAS file has an assigned ISN for identification. If you specify ASCENDISN, you cannot specify a data field name.
DESCENDING
indicates the sort is to be in descending order (high-to-low). For example, Z, Y, X, W or 9, 8, 7 6.

SORT Clause Examples

The following SORT clause causes the ADABAS values to be presented in ascending order. Based on the data fields included in the VLIB.USACUST view descriptor, the logical records are presented first by the values in the data field CUSTOMER, then by the values in data field ZIPCODE, and then by the values in the data field FIRSTORDERDATE.
subset sort customer, zipcode, firstorderdate
The following SORT clause causes logical records that are accessed by the VLIB.CUSPHON view descriptor to be presented in descending order based on the values in the NAME data field:
subset sort name descending