1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
*(Q) I have data file with a string variable containing patients first and last name.
How do I keep the first 3 letters of the last name only in a new variable?
Example:
Patients Name                   New Name
ANNIS, DAVID            DAV
ARMOUR, STEPHEN STE
JACKO, RICK             RIC

*(A) Posted by Ray to SPSSX-L list on 2002/01/24.
* Create dummy sample file.
DATA LIST FIXED /Patient 1-20 (A).
BEGIN DATA
ANNIS, DAVID           
ARMOUR, STEPHEN
JACKO, RICK            
John,    Smith
END DATA.

* Do it.
STRING newvar(A3).
COMPUTE newvar=LTRIM(SUBSTR(patient,INDEX(patient,',')+1)).
EXECUTE.