CHAR Function

Returns a single character from a specified position in a character string.

Category: Character

Syntax

Required Arguments

string

specifies a character constant, variable, or expression.

position

is an integer that specifies the position of the character to be returned.

Details

In a DATA step, the default length of the target variable for the CHAR function is 1.
If position has a missing value, then CHAR returns a string with a length of 0. Otherwise, CHAR returns a string with a length of 1.
If position is less than or equal to 0, or greater than the length of the string, then CHAR returns a blank. Otherwise, CHAR returns the character at the specified position in the string.

Comparisons

The CHAR function returns the same result as SUBPAD(string, position, 1). While the results are the same, the default length of the target variable is different.

Example

The following example shows the results of using the CHAR function.
data test;
   retain string "abc";
   do position = -1 to 4;
      result=char(string, position);
      output;
   end;
run;

proc print noobs data=test;
run;
Output from the CHAR Function
Output from the CHAR Function

See Also

Functions: