Previous Page | Next Page

Functions and CALL Routines

CHAR Function



Returns a single character from a specified position in a character string.
Category: Character

Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

CHAR(string, position)


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.


Examples

The following example shows the results of using the CHAR function.

options pageno=1 ps=64 ls=80 nodate;

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

                                 The SAS System                                1

                          string    position    result

                           abc         -1             
                           abc          0             
                           abc          1         a   
                           abc          2         b   
                           abc          3         c   
                           abc          4             

See Also

Functions:

FIRST Function

Previous Page | Next Page | Top of Page