String variables (COMPUTE command)
- String variables can be modified but not created
on
COMPUTE
. However, a new string variable can be created and assigned a width with theSTRING
command and then assigned new values withCOMPUTE
. - Existing string variables transformed with
COMPUTE
retain their original dictionary formats. String variables declared onSTRING
and transformed withCOMPUTE
retain the formats assigned to them onSTRING
. - The format of string variables cannot be changed
with
FORMATS
. Instead, useSTRING
to create a new variable with the desired width and then useCOMPUTE
to set the values of the new string equal to the values of the original. - The string returned by a string expression does not have to be the same width as the target variable. If the target variable is shorter, the result is right-trimmed. If the target variable is longer, the result is right-padded. The program displays no warning messages when trimming or padding.
- To control the width of strings, use the functions
that are available for padding (
LPAD
,RPAD
), trimming (LTRIM
,RTRIM
), and selecting a portion of strings (SUBSTR
). - To determine whether a character in a string is single-byte
or double-byte, use the
MBLEN.BYTE
function. Specify the string and, optionally, its beginning byte position. If the position is not specified, it defaults to 1.
See the topic String functions for more information.