SPSS Tips & Tricks #5 – Substring

 In Tips & Tricks

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. 

  1. Choose the command : Transform – Compute
  2. And then click “Continue
  3. “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.
  4. Click OK and here is the new string variable “VAR2”:

Thanks for the visit!


error: Content is protected !!