AUTORECODE: Fix treatment of missing values.
[pspp] / tests / language / stats / autorecode.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl 
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl 
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl 
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([AUTORECODE procedure])
18
19 AT_SETUP([AUTORECODE multiple missing values])
20 AT_DATA([autorecode.sps],
21   [DATA LIST LIST NOTABLE /u v w x y z (F2.0).
22 BEGIN DATA.
23 11 11 11 11 11 11
24 12 12 12 12 12 12
25 13 13 13 13 13 13
26 14 14 14 14 14 14
27 15 15 15 15 15 15
28 16 16 16 16 16 16
29 END DATA.
30
31 MISSING VALUES u (11)
32                v (11, 12)
33                w (11, 12, 13)
34                x (11 THRU 14)
35                y (11 THRU 15)
36                z (11 THRU 16).
37
38 AUTORECODE u v w x y z INTO a b c d e f.
39 LIST.
40 DISPLAY VARIABLES/VARIABLES=a TO f.
41 ])
42 AT_CHECK([pspp -O format=csv autorecode.sps], [0], [dnl
43 Table: Data List
44 u,v,w,x,y,z,a,b,c,d,e,f
45 11,11,11,11,11,11,6.00,5.00,4.00,3.00,2.00,1.00
46 12,12,12,12,12,12,1.00,6.00,5.00,4.00,3.00,2.00
47 13,13,13,13,13,13,2.00,1.00,6.00,5.00,4.00,3.00
48 14,14,14,14,14,14,3.00,2.00,1.00,6.00,5.00,4.00
49 15,15,15,15,15,15,4.00,3.00,2.00,1.00,6.00,5.00
50 16,16,16,16,16,16,5.00,4.00,3.00,2.00,1.00,6.00
51
52 Table: Variables
53 Name,Position,Print Format,Write Format,Missing Values
54 a,7,F8.2,F8.2,6
55 b,8,F8.2,F8.2,5; 6
56 c,9,F8.2,F8.2,4; 5; 6
57 d,10,F8.2,F8.2,3 THRU 6
58 e,11,F8.2,F8.2,2 THRU 6
59 f,12,F8.2,F8.2,1 THRU 6
60 ])
61 AT_CLEANUP
62
63 AT_SETUP([AUTORECODE numbers and short strings])
64 AT_DATA([autorecode.sps],
65   [data list /X 1-5(a) Y 7.
66 begin data.
67 lasdj 1
68 asdfk 0
69 asdfj 2
70 asdfj 1
71 asdfk 2
72 asdfj 9
73 lajks 9
74 asdfk 0
75 asdfk 1
76 end data.
77
78 missing values x('asdfk') y(9).
79
80 autorecode x y into A B/descend.
81
82 list.
83 compute Z=trunc(y/2).
84 autorecode z into W.
85 list.
86 ])
87 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
88   [Table: Reading 1 record from INLINE.
89 Variable,Record,Columns,Format
90 X,1,1-  5,A5
91 Y,1,7-  7,F1.0
92
93 Table: Data List
94 X,Y,A,B
95 lasdj,1,1.00,2.00
96 asdfk,0,4.00,3.00
97 asdfj,2,3.00,1.00
98 asdfj,1,3.00,2.00
99 asdfk,2,4.00,1.00
100 asdfj,9,3.00,4.00
101 lajks,9,2.00,4.00
102 asdfk,0,4.00,3.00
103 asdfk,1,4.00,2.00
104
105 Table: Data List
106 X,Y,A,B,Z,W
107 lasdj,1,1.00,2.00,.00,1.00
108 asdfk,0,4.00,3.00,.00,1.00
109 asdfj,2,3.00,1.00,1.00,2.00
110 asdfj,1,3.00,2.00,.00,1.00
111 asdfk,2,4.00,1.00,1.00,2.00
112 asdfj,9,3.00,4.00,.  ,.  @&t@
113 lajks,9,2.00,4.00,.  ,.  @&t@
114 asdfk,0,4.00,3.00,.00,1.00
115 asdfk,1,4.00,2.00,.00,1.00
116 ])
117 AT_CLEANUP
118
119
120
121 AT_SETUP([AUTORECODE long strings and check the value labels])
122 AT_DATA([ar.sps],
123   [data list notable list /s (a16) x *.
124 begin data.
125 widgets      1
126 thingummies  2
127 oojars       3
128 widgets      4
129 oojars       5
130 thingummies  6
131 oojimiflips  7
132 end data.
133
134 autorecode s into new.
135
136 list.
137
138 display dictionary.
139 ])
140
141 AT_CHECK([pspp -O format=csv ar.sps], [0],
142   [Table: Data List
143 s,x,new
144 widgets,1.00,4.00
145 thingummies,2.00,3.00
146 oojars,3.00,1.00
147 widgets,4.00,4.00
148 oojars,5.00,1.00
149 thingummies,6.00,3.00
150 oojimiflips,7.00,2.00
151
152 Table: Variables
153 Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
154 s,1,,Nominal,Input,16,Left,A16,A16,
155 x,2,,Scale,Input,8,Right,F8.2,F8.2,
156 new,3,,Scale,Input,8,Right,F8.2,F8.2,
157
158 Table: Value Labels
159 Variable Value,,Label
160 new,1.00,oojars
161 ,2.00,oojimiflips
162 ,3.00,thingummies
163 ,4.00,widgets
164 ])
165
166 AT_CLEANUP
167
168
169 AT_SETUP([AUTORECODE group subcommand])
170 AT_DATA([ar-group.sps],
171 [data list notable list /x * y *.
172 begin data.
173 11 10
174 12 12 
175 13 15
176 14 11
177 15 12
178 16 18
179 end data.
180
181 missing values y (12).
182
183 autorecode 
184         x y into a b
185         /group.
186
187 list.
188 display variables /variables=a b.
189 ])
190
191 AT_CHECK([pspp -O format=csv ar-group.sps], [0],
192 [Table: Data List
193 x,y,a,b
194 11.00,10.00,2.00,1.00
195 12.00,12.00,8.00,8.00
196 13.00,15.00,3.00,5.00
197 14.00,11.00,4.00,2.00
198 15.00,12.00,5.00,8.00
199 16.00,18.00,6.00,7.00
200
201 Table: Variables
202 Name,Position,Print Format,Write Format,Missing Values
203 a,3,F8.2,F8.2,8
204 b,4,F8.2,F8.2,8
205 ])
206
207 AT_CLEANUP
208
209
210
211 AT_SETUP([AUTORECODE group - string variables])
212 AT_DATA([strings.sps],
213 [data list notable list /x (a8) y (a16).
214 begin data.
215 fred bert
216 charlie "         "
217 delta echo
218 "      " windows
219 " "  nothing
220 end data.
221
222
223 autorecode x y into a b
224         /group.
225
226 delete variables x y.
227
228 list.
229
230 ])
231
232 AT_CHECK([pspp -O format=csv strings.sps], [0],
233 [Table: Data List
234 a,b
235 6.00,2.00
236 3.00,1.00
237 4.00,5.00
238 1.00,8.00
239 1.00,7.00
240 ])
241
242 AT_CLEANUP
243
244
245 dnl Tests for a crash which happened when the /GROUP subcommand
246 dnl appeared with string variables of different widths.
247 AT_SETUP([AUTORECODE group vs. strings])
248 AT_DATA([ar-strings.sps],
249   [data list notable list /a (a12) b (a6).
250 begin data.
251 one    nine
252 two    ten
253 three  eleven 
254 four   nought
255 end data.
256
257 autorecode a b into x y 
258         /group.
259
260 list.
261 ])
262
263 AT_CHECK([pspp -O format=csv ar-strings.sps], [0],
264 [dnl
265 Table: Data List
266 a,b,x,y
267 one,nine,5.00,3.00
268 two,ten,8.00,6.00
269 three,eleven,7.00,1.00
270 four,nought,2.00,4.00
271 ])
272
273 AT_CLEANUP
274
275
276
277 AT_SETUP([AUTORECODE /blank])
278
279 AT_DATA([auto-blank.sps],  [dnl
280 data list notable list /x (a8) y * z (a16).
281 begin data.
282 one   2  fred
283 two   4  ""
284 ""    4  fred
285 ""    2  charliebrown
286 three 2  charliebrown
287 end data.
288
289 autorecode variables x y z into a b c  /blank=missing.
290
291 list a b c y.
292 ])
293
294 AT_CHECK([pspp -O format=csv auto-blank.sps], [0], [dnl
295 Table: Data List
296 a,b,c,y
297 1.00,1.00,2.00,2.00
298 3.00,2.00,.  ,4.00
299 .  ,2.00,2.00,4.00
300 .  ,1.00,1.00,2.00
301 2.00,1.00,1.00,2.00
302 ])
303
304 AT_CLEANUP
305
306 dnl AUTORECODE had a use-after-free error when TEMPORARY was in use.
307 dnl Bug #32757.
308 AT_SETUP([AUTORECODE with TEMPORARY])
309 AT_DATA([autorecode.sps],
310   [data list /X 1-5(a) Y 7.
311 begin data.
312 lasdj 1
313 asdfk 0
314 asdfj 2
315 asdfj 1
316 asdfk 2
317 asdfj 9
318 lajks 9
319 asdfk 0
320 asdfk 1
321 end data.
322
323 temporary.
324 select if y > 1.
325 autorecode x y into A B/descend.
326 list.
327 ])
328 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
329   [Table: Reading 1 record from INLINE.
330 Variable,Record,Columns,Format
331 X,1,1-  5,A5
332 Y,1,7-  7,F1.0
333
334 Table: Data List
335 X,Y,A,B
336 lasdj,1,.  ,.  @&t@
337 asdfk,0,2.00,.  @&t@
338 asdfj,2,3.00,2.00
339 asdfj,1,3.00,.  @&t@
340 asdfk,2,2.00,2.00
341 asdfj,9,3.00,1.00
342 lajks,9,1.00,1.00
343 asdfk,0,2.00,.  @&t@
344 asdfk,1,2.00,.  @&t@
345 ])
346 AT_CLEANUP
347
348
349 dnl For compatibility, make sure that /INTO (with leading slash) is accepted
350 dnl (bug #48762)
351 AT_SETUP([AUTORECODE with /INTO])
352 AT_DATA([autorecode.sps],
353   [data list list notable /x .
354 begin data.
355 1
356 8
357 -901
358 4
359 1
360 99
361 8
362 end data.
363
364 autorecode x  /into y.
365
366 list.
367 ])
368 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
369 [Table: Data List
370 x,y
371 1.00,2.00
372 8.00,4.00
373 -901.00,1.00
374 4.00,3.00
375 1.00,2.00
376 99.00,5.00
377 8.00,4.00
378 ])
379 AT_CLEANUP