LEFT: Returning Characters From the Left 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, LEFT returns that number of characters from the left end of the string.

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

LEFT(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 Left of a Character String

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

TABLE FILE WF_RETAIL_EMPLOYEE
PRINT FULLNAME AND
COMPUTE LEN/I5 = ARGLEN(54, GET_TOKEN(FULLNAME, ' ', 1), LEN); NOPRINT
COMPUTE FIRST/A20 = LEFT(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.