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
*Convert 1st letter of each Word to Upper Case

DATA LIST  FIXED /Address 1-25 (a).
BEGIN DATA.
248 n. delphia ave.
9273 Fairvew dr. apt 410
6324 Meadowview
corner of south & maine
END DATA.

* Define 5 new string variables to hold the "pieces" of the
* address. You may need to define more if you know there are
* more separate words in the address.

STRING a1 to a5 (a25).

* Use the DO REPEAT command to repeat the process for each
* "piece" of the address (each separate word, number, etc.).
* First find the location of the first space in the address.
* Then compute a substring which is the address variable up
* until the first space. This is stand-in variable a, which
* represents a "piece" of the address.
* Then shorten the address variable by making it a substring 
* of itself from the first space until the end. In other words,
* the address variable has the new "piece" trimmed from the
* front of it.
* Use the CONCAT and UPCASE functions to convert the first 
* character of the new "piece" you've created to upper case & 
* concatenate it back together with the remainder of the new 
* piece (the stand-in variable a).
* This sequence loops through 5 times. If you know you'll have
* more than 5 "pieces" in the address, define more than 5 
* variables, i.e., define strings a1 to a8, instead.

DO REPEAT a=a1 to a5.
COMPUTE space=index(address," ").
COMPUTE a=substr(address,1,space-1).
COMPUTE address=substr(address,space+1).
COMPUTE a=concat(upcase(substr(a,1,1)),substr(a,2)).
END REPEAT PRINT.

* Now concatenate the pieces together into the new address 
* variable.  Use the RTRIM function to trim trailing blanks, and 
* insert single blanks where appropriate.

COMPUTE address=concat(rtrim(a1)," ", rtrim(a2)," ",rtrim(a3)," ", rtrim(a4)," ",rtrim(a5)).
LIST variables=address.