COLLATE Function: Windows

Returns an ASCII collating sequence character string.

Category: Character
Windows specifics: Uses the ASCII code sequence
See: COLLATE Function in SAS Functions and CALL Routines: Reference

Syntax

Required Argument

start-position

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

Optional Arguments

end-position

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

length

specifies the number of characters in the returned collating sequence.

Details

The COLLATE function returns a string of ASCII characters that range in value from 0 to 255. The string that is returned by the COLLATE function begins with the ASCII character that is specified by the start-position argument. If the end-position argument is specified, the string returned by the COLLATE function contains all the ASCII characters between the start-position and end-position arguments. If the length argument is specified instead of the end-position argument, then the COLLATE function returns a string that contains a value for length. The returned string ends, or truncates, and the character has the value 255 if you request a string length that contains characters exceeding this value.
The default length of the return string value is 200 characters. To return a length of 201 to 256 ASCII characters, use a format such as $256 for the return string variable or explicitly define the variable's length, such as length y $260.
Any programs using the COLLATE function with characters above ASCII 127 (the hexadecimal notation is '7F'x) can return a different value when used on a PC from another country. Characters above ASCII 127 are national characters and they vary from country to country.

Examples

Example 1: Returning an ASCII String Using the Return Variable Default String Length

In this example, the return code variable y uses the default return string length of 200. Therefore, the COLLATE function returns 200 characters of the collating sequence.
data _null_;
   y = collate(1,256);
   put y;
run;

Example 2: Returning an ASCII String Larger Than the Default Return Variable String Length

By formatting the return code variable to a length greater than 256, the COLLATE function returns 256 characters of the collating sequence.
data _null_;
   format y $260.;
   y = collate(1,256);
   put y;
run;

Example 3: Returning an ASCII String of a Specific Length

In this example, the return code variable y uses a return string length of 56, and the COLLATE function returns the first 56 characters of the collating sequence.
data _null_;
   y = collate(,,56);
   put y;
run;