RIGHT: Returning Characters From the Right of a Character String

How to:

Given a source character string, or an expression that can be converted to varchar (variable-length alphanumeric), and an integer number, RIGHT returns that number of characters from the right end of the string.

Syntax: How to Return Characters From the Right of a Character String

RIGHT(chr_exp, int_exp) 

where:

chr_exp

Alphanumeric or an expression that can be converted to variable-length alphanumeric.

Is the source character string.

int_exp

Integer

Is the number of characters to be returned.

Example: Returning Characters From the Right of a Character String

The following request computes the length of the last name in the FULLNAME field and returns that number of characters to LAST.

TABLE FILE WF_RETAIL_EMPLOYEE
PRINT FULLNAME AND
COMPUTE LEN/I5 = ARGLEN(54, GET_TOKEN(FULLNAME, ' ', 2), LEN); NOPRINT
COMPUTE LAST/A20 = RIGHT(FULLNAME, LEN);
WHERE RECORDLIMIT EQ 20
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END

The output is shown in the following image.