1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
* How to reverse the digits of an integer.

* (A) Posted to SPSSX-L list by Raynald Levesque on 2003/09/16.

NEW FILE.
DATA LIST FREE /test.
BEGIN DATA.
12345678
12345
21
END DATA.

* Assume a maximum of 12 digits.
NUMERIC result (F12).
STRING #nb1 #nb2(A12).
COMPUTE #nb1=STRING(test,F12).
COMPUTE #nb2="".
LOOP #I = 1 TO LENGTH(RTRIM(#nb1)).
- COMPUTE #nb2 = CONCAT(RTRIM(#nb2), SUBSTR(#nb1,LENGTH(RTRIM(#nb1)) - #i + 1,1)).
END LOOP.
COMPUTE result=NUMBER(#nb2,F12).
EXECUTE.