1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
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.
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.
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/>.
17 AT_BANNER([SAVE TRANSLATE /TYPE=CSV])
19 m4_define([PREPARE_SAVE_TRANSLATE_CSV], [dnl
20 AT_KEYWORDS([SAVE TRANSLATE])
21 AT_DATA([data.txt], [dnl
22 0 '1 9:30:05' 1/2/2003 "25/8/1995 15:30:00" "'a,b,c'",0
23 , '-0 5:17' 10/31/2010 "9/4/2008 9:29:00" " xxx ",1
24 1.625,'0 12:00',,,xyzzy,1
26 AT_DATA([save-translate.pspp], [dnl
28 DATA LIST LIST NOTABLE FILE="data.txt"
29 /number(F8.3) time(DTIME10) date(ADATE10) datetime(DATETIME20) string(A8)
31 MISSING VALUES number(0) time('0 12:00') string('xyzzy').
33 SAVE TRANSLATE /OUTFILE="data.csv" /TYPE=m4_if([$2], [], [CSV], [$2])
36 AT_CHECK([pspp -O format=csv save-translate.pspp], [0])
39 AT_SETUP([CSV output -- defaults])
40 PREPARE_SAVE_TRANSLATE_CSV
41 AT_CHECK([cat data.csv], [0], [dnl
42 0,33:30:05,01/02/2003,08/25/1995 15:30:00,"'a,b,c'",0
43 ,-05:17:00,10/31/2010,04/09/2008 09:29:00, xxx,1
44 1.625,12:00:00, , ,xyzzy,1
48 AT_SETUP([CSV output -- recode missing, delete unselected])
49 PREPARE_SAVE_TRANSLATE_CSV([/MISSING=RECODE /UNSELECTED=DELETE])
50 AT_CHECK([cat data.csv], [0], [dnl
51 ,-05:17:00,10/31/2010,04/09/2008 09:29:00, xxx,1
56 AT_SETUP([CSV output -- var names, formats])
57 PREPARE_SAVE_TRANSLATE_CSV(
58 [/FIELDNAMES /TEXTOPTIONS FORMAT=VARIABLE /UNSELECTED=RETAIN])
59 AT_CHECK([cat data.csv], [0], [dnl
60 number,time,date,datetime,string,filter
61 .000,1 09:30:05,01/02/2003,25-AUG-1995 15:30:00,"'a,b,c'",0
62 ,-0 05:17,10/31/2010,09-APR-2008 09:29:00, xxx,1
63 1.625,0 12:00:00, , ,xyzzy,1
67 AT_SETUP([CSV output -- comma as decimal point])
68 PREPARE_SAVE_TRANSLATE_CSV([/FIELDNAMES /TEXTOPTIONS DECIMAL=COMMA])
69 AT_CHECK([cat data.csv], [0], [dnl
70 number;time;date;datetime;string;filter
71 0;33:30:05;01/02/2003;08/25/1995 15:30:00;'a,b,c';0
72 ;-05:17:00;10/31/2010;04/09/2008 09:29:00; xxx;1
73 1,625;12:00:00; ; ;xyzzy;1
77 AT_SETUP([CSV output -- custom delimiter, qualifier])
78 PREPARE_SAVE_TRANSLATE_CSV(
79 [/FIELDNAMES /TEXTOPTIONS DELIMITER=':' QUALIFIER="'"])
80 AT_CHECK([cat data.csv], [0], [dnl
81 number:time:date:datetime:string:filter
82 0:'33:30:05':01/02/2003:'08/25/1995 15:30:00':'''a,b,c''':0
83 :'-05:17:00':10/31/2010:'04/09/2008 09:29:00': xxx:1
84 1.625:'12:00:00': : :xyzzy:1
88 AT_SETUP([CSV output -- KEEP, RENAME quoted])
89 PREPARE_SAVE_TRANSLATE_CSV(
90 [/FIELDNAMES /KEEP=time string /RENAME string='long name with spaces' /UNSELECTED=DELETE])
91 AT_CHECK([cat data.csv], [0], [dnl
92 time,long name with spaces
99 AT_SETUP([CSV output -- KEEP, RENAME multi quoted])
100 PREPARE_SAVE_TRANSLATE_CSV(
106 datetime = "another variable replacement"
107 string="long name with spaces"
109 AT_CHECK([cat data.csv], [0], [dnl
110 this one,that one,which one?,another variable replacement,long name with spaces,filter
111 ,-05:17:00,10/31/2010,04/09/2008 09:29:00, xxx,1
112 1.625,12:00:00, , ,xyzzy,1
117 AT_SETUP([CSV output -- KEEP, RENAME bad name ])
119 data list notable list /Var1 Var2 Var3 Var4 Var5 *.
133 (Var1 Var2 = one Var3 )
134 (Var3 = "The second")
139 AT_CHECK([pspp -O format=csv bad.sps], [1], [dnl
140 "bad.sps:16: error: SAVE TRANSLATE: Cannot rename Var2 as Var3 because there already exists a variable named Var3. To rename variables with overlapping names, use a single RENAME subcommand such as `/RENAME (A=B)(B=C)(C=A)', or equivalently, `/RENAME (A B C=B C A)'."
148 AT_BANNER([SAVE TRANSLATE /TYPE=TAB])
150 AT_SETUP([TAB output])
151 PREPARE_SAVE_TRANSLATE_CSV([/FIELDNAMES], [TAB])
152 AT_CHECK([cat data.csv], [0], [dnl
153 number time date datetime string filter
154 0 33:30:05 01/02/2003 08/25/1995 15:30:00 'a,b,c' 0
155 -05:17:00 10/31/2010 04/09/2008 09:29:00 xxx 1
156 1.625 12:00:00 xyzzy 1