Output 2.19 Sorting by Column Position
Sorting by Columns That Are Not Selected
You can sort query results by columns that are not included in the query. For example,
the following query returns all the rows in the Sql.Countries table and sorts them by
population, even though the Population column is not included in the query:
libname sql 'SAS-library';
proc sql outobs=12;
title 'Countries, Sorted by Population';
select Name, Continent
from sql.countries
order by Population;
42 Chapter 2 Retrieving Data from a Single Table
Output 2.20 Sorting by Columns That Are Not Selected
Specifying a Different Sorting Sequence
SORTSEQ= is a PROC SQL statement option that specifies the sorting sequence for
PROC SQL to use when a query contains an ORDER BY clause. Use this option only if
you want to use a sorting sequence other than your operating environment's default
sorting sequence. Possible values include ASCII, EBCDIC, and some languages other
than English. For example, in an operating environment that supports the EBCDIC
sorting sequence, you could use the following option in the PROC SQL statement to set
the sorting sequence to EBCDIC:
proc sql sortseq=ebcdic;
In the third maintenance release for SAS 9.4, linguistic collation is supported with the
SORTSEQ statement option. For more information, see “SORTSEQ=sort-table |
LINGUISTIC” on page 229.
Note: SORTSEQ= affects only the ORDER BY clause. It does not override your
operating environment's default comparison operations for the WHERE clause.
Operating Environment Information
For more information about the default and other sorting sequences for your
operating environment, see the SAS documentation for your operating environment.
Sorting Columns That Contain Missing Values
PROC SQL sorts nulls, or missing values, before character or numeric data. Therefore,
when you specify ascending order, missing values appear first in the query results.
Sorting Data 43

Get SAS 9.4 SQL Procedure User's Guide, Fourth Edition, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.