= SPSS Macro String Functions = SPSS macros offer the following library of '''string functions'''. <> ---- == Quoting == Quoting is technically optional within a macro, as all values within a macro are technically strings. Nonetheless, it is best practice to quote strings properly. Consider the following: ||'''Expression''' ||'''Result''' || ||`!UPCASE(abc)` ||`ABC` || ||`!UPCASE('abc')` ||`ABC` || ||`!UPCASE(a b c)` ||error || ||`!UPCASE('a b c')` ||`A B C` || ||`!UPCASE(a/b/c)` ||error || ||`!UPCASE('a/b/c')` ||`A/B/C` || ||`!UPCASE(!CONCAT(a,b,c))` ||`ABC` || ||`!UPCASE(!CONCAT('a','b','c'))` ||`ABC` || ||`!UPCASE(!CONCAT(a, b, c))` ||`ABC` || ||`!UPCASE(!CONCAT('a ','b ','c '))` ||`A B C` || ||`!UPCASE(!CONCAT('a,b,c'))` ||`A,B,C` || ||`!QUOTE(abc)` ||`'ABC'` || ||`!QUOTE('abc')` ||`abc` || ||`!QUOTE('Bill"s')` ||`'Bill"s'` || ||`!QUOTE("Bill's")` ||`"Bill's"` || ||`!QUOTE(Bill's)` ||error || ||`!QUOTE(!UNQUOTE('Bill"s'))` ||`'Bill"s'` || ---- == Functions == '''`!blanks(N)`''' returns a string composed of N blank spaces. '''`!concat(value...)`''' concatenates all values. '''`!eval(value)`''' scans a value for macros and evaluates. This is necessary for evaluating an externally defined macro within a macro definition. '''`!head(value...)`''' copies the first token from the values. '''`!index(value, pattern)`''' returns the integer position of a `pattern` inside a `value`. If the `value` does not contain the `pattern`, this function returns 0. '''`!length(value)`''' returns the integer length of a value. '''`!null`''' returns an empty string. This is mostly useful for checking if a macro parameter was specified (i.e. `!IF (!1 !NE !NULL)`). '''`!quote(value)`''' returns the value quoted, with internal quotes escaped. '''`!substr(value, index [, length])`''' copies a substring from a value. The substring starts at position `index` and continues for `length` characters. If `length` is not specified, the substring copies until the end of the original value. '''`!tail(value...)`''' copies the second through last tokens from the values. The complement to `!head()`. '''`!unquote(value)`''' returns the value un-quoted, with internal escaped quotes un-escaped. '''`!upcase(value)`''' translates lowercase characters into uppercase. ---- CategoryRicottone