Respected users, I want to split one string variable into two variables. The string variable (master variable) contain 6 digits maximum. Now I want one variable of first 3 digits from master variable and another variable containing last 3 digits without effecting the other variables. Please suggest me any path.
Thanks and regards, Biswajit
Answer by David Dwyer (56) | Feb 26, 2016 at 10:58 AM
This is something that can be handled in the GUI under the "Transform -> Compute" menus. In the Compute dialog you will want to create two new variables of the appropriate type and then assign a portion of your original variable to each of these. Assuming you have a string field to start with, you might use the CHAR.SUBSTR(strvar,start,length) function to parse it. You could also do this in SPSS Statistics Command Syntax.
Assuming your original variable "master" is a 6 character string field, here is an example creating two 3 character string fields "left" and "right" with the leftmost and rightmost 3 characters from "master" respectively:
DATA LIST FREE /master (A6).
BEGIN DATA
abcdef ghijkl mnopqr stuvwx
END DATA.
LIST.
STRING left right (A3).
COMPUTE left = CHAR.SUBSTR(master,1,3).
COMPUTE right = CHAR.SUBSTR(master,4).
LIST.
Output Export Problem 3 Answers
How to use custom dialog variable list in CTABLES /TABLE subcommand 2 Answers
bugs in SPSS22? 9 Answers
How to send a email in spss? 9 Answers
Entering a date into a save file name 3 Answers