1 AT_BANNER([RECODE transformation])
3 m4_define([RECODE_SAMPLE_DATA],
4 [DATA LIST LIST NOTABLE/x (f1) s (a4) t (a10).
5 MISSING VALUES x(9)/s('xxx').
21 AT_SETUP([RECODE numeric to numeric, without INTO])
24 NUMERIC x0 TO x8 (F3).
25 MISSING VALUES x0 to x8 (9).
29 RECODE x1 (1=9)(3=8)(5=7).
31 RECODE x2 (1=8)(2,3,4,5,6,8=9)(9=1).
33 RECODE x3 (1 THRU 9=10)(MISSING=11).
35 RECODE x4 (MISSING=11)(1 THRU 9=10).
37 RECODE x5 (LOWEST THRU 5=1).
39 RECODE x6 (4 THRU HIGHEST=2).
41 RECODE x7 (LO THRU HI=3).
46 AT_CHECK([pspp -O format=csv recode.sps], [0],
48 x,x0,x1,x2,x3,x4,x5,x6,x7,x8
63 AT_SETUP([RECODE numeric to numeric, with INTO, without COPY])
66 NUMERIC ix0 TO ix8 (F3).
67 RECODE x (1=9) INTO ix0.
68 RECODE x (1=9)(3=8)(5=7) INTO ix1.
69 RECODE x (1=8)(2,3,4,5,6,8=9)(9=1) INTO ix2.
70 RECODE x (1 THRU 9=10)(MISSING=11) INTO ix3.
71 RECODE x (MISSING=11)(1 THRU 9=10) INTO ix4.
72 RECODE x (LOWEST THRU 5=1) INTO ix5.
73 RECODE x (4 THRU HIGHEST=2) INTO ix6.
74 RECODE x (LO THRU HI=3) INTO ix7.
75 RECODE x (SYSMIS=4) INTO ix8.
78 AT_CHECK([pspp -O format=csv recode.sps], [0],
80 x,ix0,ix1,ix2,ix3,ix4,ix5,ix6,ix7,ix8
95 AT_SETUP([RECODE numeric to numeric, with INTO, with COPY])
98 NUMERIC cx0 TO cx8 (F3).
99 RECODE x (1=9)(ELSE=COPY) INTO cx0.
100 RECODE x (1=9)(3=8)(5=7)(ELSE=COPY) INTO cx1.
101 RECODE x (1=8)(2,3,4,5,6,8=9)(9=1)(ELSE=COPY) INTO cx2.
102 RECODE x (1 THRU 9=10)(MISSING=11)(ELSE=COPY) INTO cx3.
103 RECODE x (MISSING=11)(1 THRU 9=10)(ELSE=COPY) INTO cx4.
104 RECODE x (LOWEST THRU 5=1)(ELSE=COPY) INTO cx5.
105 RECODE x (4 THRU HIGHEST=2)(ELSE=COPY) INTO cx6.
106 RECODE x (LO THRU HI=3)(ELSE=COPY) INTO cx7.
107 RECODE x (SYSMIS=4)(ELSE=COPY) INTO cx8.
108 RECODE x (5=COPY)(ELSE=22) INTO cx9.
111 AT_CHECK([pspp -O format=csv recode.sps], [0],
113 x,cx0,cx1,cx2,cx3,cx4,cx5,cx6,cx7,cx8,cx9
114 0,0,0,0,0,0,1,0,3,0,22.00
115 1,9,9,8,10,10,1,1,3,1,22.00
116 2,2,2,9,10,10,1,2,3,2,22.00
117 3,3,8,9,10,10,1,3,3,3,22.00
118 4,4,4,9,10,10,1,2,3,4,22.00
119 5,5,7,9,10,10,1,2,3,5,5.00
120 6,6,6,9,10,10,6,2,3,6,22.00
121 7,7,7,7,10,10,7,2,3,7,22.00
122 8,8,8,9,10,10,8,2,3,8,22.00
123 9,9,9,1,10,11,9,2,3,9,22.00
124 .,.,.,.,11,11,.,.,.,4,22.00
128 AT_SETUP([RECODE string to string, with INTO, without COPY])
129 AT_DATA([recode.sps],
131 STRING s0 TO s3 (A4)/t0 TO t3 (A10).
132 RECODE s t ('a'='b')('ab'='bc') INTO s0 t0.
133 RECODE s t ('abcd'='xyzw') INTO s1 t1.
134 RECODE s t ('abc'='def')(ELSE='xyz') INTO s2 t2.
135 RECODE t ('a'='b')('abcdefghi'='xyz')('abcdefghij'='jklmnopqr') INTO t3.
136 RECODE s (MISSING='gone') INTO s3.
137 LIST s t s0 TO s3 t0 TO t3.
139 AT_CHECK([pspp -O format=csv recode.sps], [0],
141 s,t,s0,s1,s2,s3,t0,t1,t2,t3
143 a ,a ,b ,,xyz ,,b ,,xyz ,b @&t@
144 ab ,ab ,bc ,,xyz ,,bc ,,xyz ,
145 abc ,abc ,,,def ,,,,def ,
146 abcd,abcd ,,xyzw,xyz ,,,xyzw ,xyz ,
147 123 ,123 ,,,xyz ,,,,xyz ,
148 123,123 ,,,xyz ,,,,xyz ,
149 +1 ,+1 ,,,xyz ,,,,xyz ,
150 1x ,1x ,,,xyz ,,,,xyz ,
151 abcd,abcdefghi ,,xyzw,xyz ,,,,xyz ,xyz @&t@
152 xxx ,abcdefghij,,,xyz ,gone,,,xyz ,jklmnopqr @&t@
156 AT_SETUP(RECODE string to string, with INTO, with COPY])
157 AT_DATA([recode.sps],
159 STRING cs0 TO cs2 (A4)/ct0 TO ct3 (A10).
160 RECODE s t ('a'='b')('ab'='bc')(ELSE=COPY) INTO cs0 ct0.
161 RECODE s t ('abcd'='xyzw')(ELSE=COPY) INTO cs1 ct1.
162 RECODE s t ('abc'='def')(ELSE='xyz')(ELSE=COPY) INTO cs2 ct2.
163 RECODE t ('a'='b')('abcdefghi'='xyz')('abcdefghij'='jklmnopqr')(ELSE=COPY)
165 LIST s t cs0 TO cs2 ct0 TO ct3.
167 AT_CHECK([pspp -O format=csv recode.sps], [0],
169 s,t,cs0,cs1,cs2,ct0,ct1,ct2,ct3
171 a ,a ,b ,a ,xyz ,b ,a ,xyz ,b @&t@
172 ab ,ab ,bc ,ab ,xyz ,bc ,ab ,xyz ,ab @&t@
173 abc ,abc ,abc ,abc ,def ,abc ,abc ,def ,abc @&t@
174 abcd,abcd ,abcd,xyzw,xyz ,abcd ,xyzw ,xyz ,abcd @&t@
175 123 ,123 ,123 ,123 ,xyz ,123 ,123 ,xyz ,123 @&t@
176 123,123 ,123,123,xyz ,123 ,123 ,xyz ,123 @&t@
177 +1 ,+1 ,+1 ,+1 ,xyz ,+1 ,+1 ,xyz ,+1 @&t@
178 1x ,1x ,1x ,1x ,xyz ,1x ,1x ,xyz ,1x @&t@
179 abcd,abcdefghi ,abcd,xyzw,xyz ,abcdefghi ,abcdefghi ,xyz ,xyz @&t@
180 xxx ,abcdefghij,xxx ,xxx ,xyz ,abcdefghij,abcdefghij,xyz ,jklmnopqr @&t@
184 AT_SETUP([RECODE string to numeric])
185 AT_DATA([recode.sps],
187 NUMERIC ns0 TO ns2 (F3)/nt0 TO nt2 (F3).
188 RECODE s t (CONVERT)(' '=0)('abcd'=1) INTO ns0 nt0.
189 RECODE s t (' '=0)(CONVERT)('abcd'=1) INTO ns1 nt1.
190 RECODE s t ('1x'=1)('abcd'=2)(ELSE=3) INTO ns2 nt2.
191 LIST s t ns0 TO ns2 nt0 TO nt2.
193 AT_CHECK([pspp -O format=csv recode.sps], [0],
195 s,t,ns0,ns1,ns2,nt0,nt1,nt2
199 abc ,abc ,.,.,3,.,.,3
200 abcd,abcd ,1,1,2,1,1,2
201 123 ,123 ,123,123,3,123,123,3
202 123,123 ,123,123,3,123,123,3
205 abcd,abcdefghi ,1,1,2,.,.,3
206 xxx ,abcdefghij,.,.,3,.,.,3
210 AT_SETUP([RECODE numeric to string])
211 AT_DATA([recode.sps],
213 STRING sx0 TO sx2 (a10).
214 RECODE x (1 THRU 9='abcdefghij') INTO sx0.
215 RECODE x (0,1,3,5,7,MISSING='xxx') INTO sx1.
216 RECODE x (2 THRU 6,SYSMIS='xyz')(ELSE='foobar') INTO sx2.
219 AT_CHECK([pspp -O format=csv recode.sps], [0],
223 1,abcdefghij,xxx ,foobar @&t@
224 2,abcdefghij,,xyz @&t@
225 3,abcdefghij,xxx ,xyz @&t@
226 4,abcdefghij,,xyz @&t@
227 5,abcdefghij,xxx ,xyz @&t@
228 6,abcdefghij,,xyz @&t@
229 7,abcdefghij,xxx ,foobar @&t@
230 8,abcdefghij,,foobar @&t@
231 9,abcdefghij,xxx ,foobar @&t@
236 AT_SETUP([RECODE bug in COPY])
237 AT_DATA([recode.sps],
248 ** Clearly, the else=copy is superfluous here
249 RECODE A ("1"="3") ("3"="1") (ELSE=COPY).
253 AT_CHECK([pspp -O format=csv recode.sps], [0],
254 [Table: Reading free-form data from INLINE.
267 AT_SETUP([RECODE bug in COPY with INTO])
268 AT_DATA([recode.sps],
280 RECODE A ("1"="3") ("3"="1") (ELSE=COPY) INTO a1.
284 AT_CHECK([pspp -O format=csv recode.sps], [0],
285 [Table: Reading free-form data from INLINE.