SPSS RTRIM Function

Summary By default, SPSS right pads string values with spaces up to the length of their containing string variables. You don’t usually see this but it may complicate concatenating strings. Such complications are avoided by trimming off trailing spaces using RTRIM (right trim). In Unicode mode, RTRIM is applied automatically but it’s fine to use it anyway. Results of steps 6 and 7 of the […]

SPSS LTRIM Function

Summary SPSS LTRIM (left trim) removes leading spaces from string values. These occur especially when converting numbers to strings by using the string function.* For removing trailing rather than leading spaces, see RTRIM. Results of CONCAT with and without LTRIM SPSS Ltrim Example The syntax below demonstrates a situation where you’ll like to use LTRIM. Running step 1 simply creates a mini dataset. Step 3 uses CONCAT without LTRIM and […]

SPSS REPLACE Function

Definition SPSS REPLACE replaces a substring in a string by a different (possibly empty) substring. SPSS Replace – Removing Spaces URLs are created from “title” by using REPLACE. The syntax below demonstrates how to do this. We have a dataset holding the titles of web pages and we’d like to convert these to URLs. For one thing, we don’t like spaces in […]

SPSS INDEX Function

Summary The SPSS INDEX function returns the position of the first occurrence of a given expression within a string. If the expression does not occur in the string, it returns a zero. As a rule of thumb, always use it as CHAR.INDEX. The reason for this is explained SPSS Unicode Mode. Note that string values are case sensitive. SPSS Index […]

SPSS String Variables Basics

For working proficiently with SPSS string variables , it greatly helps to understand some string basics. This tutorial explains what SPSS string variables are and demonstrates their main properties. We encourage you along by downloading and opening string_basics.sav. The syntax we use can be copy-pasted or downloaded here. SPSS String Variables – What Are They? String variables are one […]

SPSS String Variables Tutorial

Working with string variables in SPSS is pretty straightforward if one masters some basic string functions. This tutorial will quickly walk you through the important ones. SPSS Main String Functions CHAR.SUBSTR (substring) – Extract character(s) from string CONCAT (concatenate) – Combine strings CHAR.INDEX – Find first occurrence of character(s) in string CHAR.RINDEX (right index) – Find last occurrence of character(s) in […]