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
* Ages are coded as 
	nnH for nn Hours
	nnD for nn Days
	nnM for nn months
	nnA for nn years
* How can I convert ages in years.
* Posted to SPSSX-L list on 2003/09/16.

DATA LIST FREE /age (A3).
BEGIN DATA
'00H'  '01H' '74H' '01D' '99D' '01M' '74M' '01A' '02A' '06A' '99A'.
END DATA.

COMPUTE num1=NUMBER(SUBSTR(age,1,2),F2).

STRING type(A1).
COMPUTE type=SUBSTR(age,3).

DO IF type="H".
- COMPUTE ageyrs=num1/(24*365.25).
ELSE IF type="D".
- COMPUTE ageyrs=num1/365.25.
ELSE IF type="M".
- COMPUTE ageyrs=num1/12.
ELSE.
- COMPUTE ageyrs=num1.
END IF.

RECODE ageyrs (11 THRU HI=4)(5 THRU 10=3)(1 THRU 5=2)(0 THRU 1=1) INTO agecode.
VALUE LABELS agecode 1 "<1 yr" 2 "1-4 yrs" 3 "5-9 yrs" 4 "10 yrs +".