1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
*(Q) Now I need to find the name part of a string consisting of name and
	address. eg 
	"Bloggs J 10 Smith St" needs to be two variables, 
	"Bloggs J" and "10 Smith St".

*(A) Posted to SPSSX-L by Raynald Levesque on 2002/07/25.

******************.
* This is one way.
******************.
DATA LIST FIXED /str1 1-25 (A).
BEGIN DATA
Bloggs J 10 Smith St
Bloggs John 12 Smith St
END DATA.
LIST.

VECTOR nb(25F1).
LOOP cnt=1 TO 25.
COMPUTE nb(cnt)=cnt*(1-NMISS(NUMBER(SUBSTR(str1,cnt,cnt),F1))).
END LOOP.
LOOP cnt=1 TO 25.
IF nb(cnt)=0 nb(cnt)=$SYSMIS.
END LOOP.
COMPUTE pos=MIN(nb1 TO nb25).

STRING addr(A25).
COMPUTE addr=SUBSTR(str1,pos).

*Clean up.
ADD FILES FILE=* /DROP=pos nb1 TO nb25 cnt.


**************.
*This is a more efficient method.
**************.
DATA LIST FIXED /str1 1-25 (A).
BEGIN DATA
Bloggs J 10 Smith St
Bloggs John 12 Smith St
END DATA.
LIST.

VECTOR #nb(25F1).
LOOP #cnt=1 TO 25.
END LOOP IF #cnt*(1-NMISS(NUMBER(SUBSTR(str1,#cnt),F1)))>0.

STRING addr(A25).
COMPUTE addr=SUBSTR(str1,#cnt).
EXECUTE.