COLLATE Function

Returns a character string in ASCII or EBCDIC collating sequence.

Category: Character
Restriction: I18N Level 0 functions are designed for use with Single Byte Character Sets (SBCS) only.
See: COLLATE Function: Windows in SAS Companion for Windows
COLLATE Function: UNIX in SAS Companion for UNIX Environments

Syntax

Required Argument

start-position

specifies the numeric position in the collating sequence of the first character to be returned.

Interaction If you specify only start-position, COLLATE returns consecutive characters from that position to the end of the collating sequence or up to 255 characters, whichever comes first.

Optional Arguments

end-position

specifies the numeric position in the collating sequence of the last character to be returned.

The maximum end-position for the EBCDIC collating sequence is 255. For ASCII collating sequences, the characters that correspond to end-position values between 0 and 127 represent the standard character set. Other ASCII characters that correspond to end-position values between 128 and 255 are available on certain ASCII operating environments, but the information that those characters represent varies with the operating environment.
Tips end-position must be larger than start-position
If you specify end-position, COLLATE returns all character values in the collating sequence between start-position and end-position, inclusive.
If you omit end-position and use length, mark the end-position place with a comma.

length

specifies the number of characters in the collating sequence.

Default 200
Tip If you omit end-position, use length to specify the length of the result explicitly.

Details

Length of Returned Variable

In a DATA step, if the COLLATE function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes.

The Basics

If you specify both end-position and length, COLLATE ignores length. If you request a string longer than the remainder of the sequence, COLLATE returns a string through the end of the sequence.

Example

The following SAS statements produce these results.
SAS Statement
Result
ASCII
----+----1----+-—-2--
x=collate(48,,10);
y=collate(48,57);
put @1 x @14 y;
 
0123456789   0123456789
EBCDIC
x=collate(240,,10);
y=collate(240,249);
put @1 x @14 y;
 
0123456789   0123456789

See Also