SUBSTR: Extracting a Substring (Maintain)

How to:

The SUBSTR function extracts a substring based on where it begins and its length in the parent string. SUBSTR can vary the position of the substring depending on the values of other fields.

There is also a SUBSTR function available for the reporting language. For information on this function, see SUBSTR: Extracting a Substring.

Syntax: How to Extract a Substring

SUBSTR(string, start, length)

where:

string

Alphanumeric

Is the parent string enclosed in single quotation marks, or a field or variable containing the character string.

start

Integer

Is the starting position of the substring in the parent string.

length

Integer

Is the length, in characters, of the substring.

Example: Extracting the First Character of a String in Maintain

SUBSTR extracts the first letter of FIRST_NAME, combines it with LAST_NAME, and stores the result in UID:

MAINTAIN FILE EMPLOYEE
CASE TOP
INFER EMP_ID FIRST_NAME LAST_NAME INTO ADDSTACK
COMPUTE UID/A9 = SUBSTR(ADDSTACK().FIRST_NAME,1,1) ||
                 ADDSTACK().LAST_NAME;
ENDCASE
END

The following table shows sample values for FIRST_NAME and LAST_NAME, and the corresponding values for UID:

FIRST_NAME    LAST_NAME     UID
JOE           SMITH         JSMITH
SAM           JONES         SJONES
TERRI         WHITE         TWHITE