Next: , Previous: Statistical Functions, Up: Functions


7.7.7 String Functions

String functions take various arguments and return various results.

— Function: CONCAT (string, string[, ...])

Returns a string consisting of each string in sequence. CONCAT("abc", "def", "ghi") has a value of "abcdefghi". The resultant string is truncated to a maximum of 255 characters.

— Function: INDEX (haystack, needle)

Returns a positive integer indicating the position of the first occurrence of needle in haystack. Returns 0 if haystack does not contain needle. Returns system-missing if needle is an empty string.

— Function: INDEX (haystack, needles, needle_len)

Divides needles into one or more needles, each with length needle_len. Searches haystack for the first occurrence of each needle, and returns the smallest value. Returns 0 if haystack does not contain any part in needle. It is an error if needle_len does not evenly divide the length of needles. Returns system-missing if needles is an empty string.

— Function: LENGTH (string)

Returns the number of characters in string.

— Function: LOWER (string)

Returns a string identical to string except that all uppercase letters are changed to lowercase letters. The definitions of “uppercase” and “lowercase” are system-dependent.

— Function: LPAD (string, length)

If string is at least length characters in length, returns string unchanged. Otherwise, returns string padded with spaces on the left side to length length. Returns an empty string if length is system-missing, negative, or greater than 255.

— Function: LPAD (string, length, padding)

If string is at least length characters in length, returns string unchanged. Otherwise, returns string padded with padding on the left side to length length. Returns an empty string if length is system-missing, negative, or greater than 255, or if padding does not contain exactly one character.

— Function: LTRIM (string)

Returns string, after removing leading spaces. Other white space, such as tabs, carriage returns, line feeds, and vertical tabs, is not removed.

— Function: LTRIM (string, padding)

Returns string, after removing leading padding characters. If padding does not contain exactly one character, returns an empty string.

— Function: NUMBER (string, format)

Returns the number produced when string is interpreted according to format specifier format. If the format width w is less than the length of string, then only the first w characters in string are used, e.g. NUMBER("123", F3.0) and NUMBER("1234", F3.0) both have value 123. If w is greater than string's length, then it is treated as if it were right-padded with spaces. If string is not in the correct format for format, system-missing is returned.

— Function: RINDEX (string, format)

Returns a positive integer indicating the position of the last occurrence of needle in haystack. Returns 0 if haystack does not contain needle. Returns system-missing if needle is an empty string.

— Function: RINDEX (haystack, needle, needle_len)

Divides needle into parts, each with length needle_len. Searches haystack for the last occurrence of each part, and returns the largest value. Returns 0 if haystack does not contain any part in needle. It is an error if needle_len does not evenly divide the length of needle. Returns system-missing if needle is an empty string.

— Function: RPAD (string, length)

If string is at least length characters in length, returns string unchanged. Otherwise, returns string padded with spaces on the right to length length. Returns an empty string if length is system-missing, negative, or greater than 255.

— Function: RPAD (string, length, padding)

If string is at least length characters in length, returns string unchanged. Otherwise, returns string padded with padding on the right to length length. Returns an empty string if length is system-missing, negative, or greater than 255, or if padding does not contain exactly one character.

— Function: RTRIM (string)

Returns string, after removing trailing spaces. Other types of white space are not removed.

— Function: RTRIM (string, padding)

Returns string, after removing trailing padding characters. If padding does not contain exactly one character, returns an empty string.

— Function: STRING (number, format)

Returns a string corresponding to number in the format given by format specifier format. For example, STRING(123.56, F5.1) has the value "123.6".

— Function: SUBSTR (string, start)

Returns a string consisting of the value of string from position start onward. Returns an empty string if start is system-missing, less than 1, or greater than the length of string.

— Function: SUBSTR (string, start, count)

Returns a string consisting of the first count characters from string beginning at position start. Returns an empty string if start or count is system-missing, if start is less than 1 or greater than the number of characters in string, or if count is less than 1. Returns a string shorter than count characters if start + count - 1 is greater than the number of characters in string. Examples: SUBSTR("abcdefg", 3, 2) has value "cd"; SUBSTR("nonsense", 4, 10) has the value "sense".

— Function: UPCASE (string)

Returns string, changing lowercase letters to uppercase letters.