Examples of substringing


The following example selects the fourth character of a string and specifies a substring length of three characters.

The substring, FEB, is assigned to the M2 variable.

Example
SET Q1 = 'JANFEBMAR'
SET M2 = Q1(4:3)

The next example shows how substrings can be used to determine a value, in this case the name of the month:

Example
SET MONS = 'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'
SET MM   = ZDATE(1:2)
SET V1   = MM - 1
SET V2   = V1 * 3
SET V3   = V2 + 1
SET MNTH = MONS(&V3:3)

The substring expression ZDATE(1:2) specifies the first character, for a length of two characters, of the mm/dd/yyyy value passed to ZDATE (03 for example). The substring expression, MONS(&V3:3), selects the portion of the character string determined by the value of the V3 variable and limits the substring to 3 characters. If 03/15/2000 is passed to the ZDATE predefined variable, the variables are assigned the following values:


Variable

Assigned value

V1

2

V2

6

V3

7

MNTH

MAR

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*