Merging two or more string variables into a single variable can be useful. Learn how to merge variables such as FirstName & LastName; or Address1 & Address2 & Address3; by using SPSS's Concatenation function.
2. What is Concatenating?
Merging two or more sting variables into a single variable is
called concatenating variables
This function can be very useful if you are working with string
data in SPSS
One common use of this function is to bring first name and
last name from two variables into one single full name
variable
2
3. How to Concatenate?
String Variables can be concatenated in IBM SPSS Statistics
using the CONCAT function
The following syntax demonstrates using a compute
command to bring three single name variables together into
a single variable, which combines the three into a full name
variable
3
4. The first piece of syntax simply creates a datafile in SPSS to
be worked with -
• DATA LIST
/First_Name 1-4(A) Initial 5-6(A) Last_Name 6-20(A).
BEGIN DATA
Rob E Barry
Ian L O'Connell
Ted W Payne
Rod G Early
Con T Not
Cat P Murphy
Pat C Clifford
Bob A O'Sullivan
END DATA.
CONCAT Function in Syntax
4
5. The STRING function below creates a string variable with 64
characters allocated to it-
• STRING Full_Name(A64)
The CONCAT Function is then used to combine the three
variables ‘First_Name’, ‘Initial’ and ‘Last_Name’
Notice how CONCAT needs to use the functions ‘rtrim’ and
‘trim’, which remove any blank spaces on the left side (ltrim)
and the right side (rtrim)
• COMPUTE Full_Name =CONCAT(rtrim(ltrim(First_Name)),"
",rtrim(ltrim(Initial))," ",rtrim(ltrim(Last_Name))).
EXEUTE.
CONCAT Function in Syntax
5
6. www.presidion.com
Talk to us
info@presidion.com +44 (0)208 757 8820 (UK) +353 (0)1 415 0234 (IRL)
www.presidion.com/ibm-spss-technical-tips
For more Tech Tips
visit