SPSS Tips & Tricks #5 – Substring
Hi, last week I got the question how do you take the 3 first characters from a variable and put them into a new one?
Here is my example data file:
Note that the variable must be a string variable.
Tips: Sometimes you have to trim the variable first, left trim or right trim via compute command. You use left trim when you have to get rid of empty spaces in the beginning of the string.
- Choose the command : Transform – Compute
- And then click “Continue
- “Then you need to fill in the box at “Numeric Expression” with the substring command (CHAR.SUBSTR):As you see we use the “VAR1”-variable, start from position 1, and read 3 characters from the beginning.
- Click OK and here is the new string variable “VAR2”:
Thanks for the visit!