Determining an expression's length in bytes - &LENGTH

Use the &LENGTH built-in function to determine the number of bytes in an expression or character string. &LENGTH performs symbolic substitution and arithmetic evaluations before determining the length. If a variable has a null value, &LENGTH returns a value of zero.

For example, after the following statement executes, &LENANSWR has the value 2 because there are two bytes in the result of the addition, 11.
SET LENANSWR = &LENGTH(1+1+9)
&LENGTH can also reference symbolic variables. Assume you want to save a value that is triple the length of the value of a variable called &CSTRING. To save the value in a variable called &NXTFIELD, code:
SET NXTFIELD = 3 * &LENGTH(&CSTRING)

If &CSTRING contains the value 100, &NXTFIELD contains the value 9.

If a string contains data of the double-byte character set (DBCS), &LENGTH counts each DBCS character as two bytes, and counts each DBCS delimiter as one byte. For example, using d1d2 to denote two DBCS characters and using < and > to represent the DBCS delimiters X'0E' and X'0F':
SET A = &LENGTH(<d1d2>)    /* result: &A = 6
The same is true when a string contains mixed EBCDIC and DBCS characters. For example:
SET A = &LENGTH(ABC<d1d2>)    /* result: &A = 9