RANK Function

Returns the position of a character in the ASCII collating sequence.

Category:Character
Returned data type:DOUBLE

Syntax

Required Argument

expression

specifies any valid expression that evaluates or can be coerced to a character string.

Data type CHAR, NCHAR, NVARCHAR, VARCHAR
SeeDS2 Expressions in SAS DS2 Programmer’s Guide

Details

The RANK function returns a whole number that represents the position of the character in the ASCII collating sequence. When more than one character is specified, the RANK function returns the position in the ASCII collating sequence for the first character.

Note: Any program that uses the RANK function with characters above ASCII 127 is not portable. (The hexadecimal notation is '7F'x.) The program is not portable because these characters are national characters and they vary from country to country.

Example

The following program illustrates the RANK function:

Note: In this example, DS2 statements are sent to SAS using PROC DS2.
proc ds2;
data test(overwrite=yes);
   dcl varchar x;
   method run();
      x=rank('A');
	  put x;
   end;
enddata;
run;
quit;

SAS writes the following ASCII output to the log.

65

See Also

Last updated: September 2, 2026