O'Reilly logo

SAS 9.4 SQL Procedure User's Guide, Fourth Edition, 4th Edition by SAS Institute

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required