TRANTAB Procedure
Example 6: Using Different Translation Tables for Sorting
Features: |
PROC SORT statement option: SORTSEQ=
PRINT procedure
|
This example shows how
to specify a different translation table to sort data in an order
that is different from the default sort order. Characters that are
written in a language other than U.S. English might require a sort
order that is different from the default order.
You can use the TRABASE
program in the SAS Sample Library to create translation tables for
several languages. All examples were produced in the UNIX environment.
Set the SAS system options.
options nodate pageno=1 linesize=80 pagesize=60;
Create the TESTSORT data set. The DATA step creates a SAS data set with four pairs of words, each
pair different only in the case of the first letter.
data testsort;
input Values $10.;
datalines;
Always
always
Forever
forever
Later
later
Yesterday
yesterday
;
Sort the data in an order that is different from the default
sort order. PROC SORT sorts the data
by using the default translation table, which sorts all lowercase
words first, then all uppercase words.
proc sort;
by values;
run;
Print the data set. PROC
PRINT prints the sorted data set.
proc print noobs;
title 'Default Sort Sequence';
run;
SAS Output
The following output
is the output from sorting values with default translation table.
The default sort sequence sorts all the capitalized words in alphabetical
order before it sorts any lowercase words.
Default Sort Sequence
1
Values
Always
Forever
Later
Yesterday
always
forever
later
yesterday
Sort the data according to the translation table UPPER
and print the new data set. The SORTSEQ= option specifies that PROC
SORT sort the data according to the customized translation table UPPER,
which treats lowercase and uppercase letters alike. This method is
useful for sorting without regard for case. PROC PRINT prints the
sorted data set.
proc sort sortseq=upper;
by values;
run;
proc print noobs;
title 'Customized Sort Sequence';
run;
SAS Output
The following output
is the result from sorting values with a customized translation table.
The customized sort sequence sorts all the words in alphabetical order,
without regard for the case of the first letters.
Customized Sort Sequence 2
Values
Always
always
Forever
forever
Later
later
Yesterday
yesterday
Copyright © SAS Institute Inc. All rights reserved.