5f0c527c4738c90ffaeab349c357dba46c73e4ca
[pspp-builds.git] / doc / files.texi
1 @node System and Portable File IO
2 @chapter System and Portable File I/O
3
4 The commands in this chapter read, write, and examine system files and
5 portable files.
6
7 @menu
8 * APPLY DICTIONARY::            Apply system file dictionary to active file.
9 * EXPORT::                      Write to a portable file.
10 * GET::                         Read from a system file.
11 * GET DATA::                    Read from foreign files.
12 * IMPORT::                      Read from a portable file.
13 * SAVE::                        Write to a system file.
14 * SAVE TRANSLATE::              Write data in foreign file formats.
15 * SYSFILE INFO::                Display system file dictionary.
16 * XEXPORT::                     Write to a portable file, as a transformation.
17 * XSAVE::                       Write to a system file, as a transformation.
18 @end menu
19
20 @node APPLY DICTIONARY
21 @section APPLY DICTIONARY
22 @vindex APPLY DICTIONARY
23
24 @display
25 APPLY DICTIONARY FROM=@{'file-name',file_handle@}.
26 @end display
27
28 @cmd{APPLY DICTIONARY} applies the variable labels, value labels,
29 and missing values taken from a file to corresponding
30 variables in the active file.  In some cases it also updates the
31 weighting variable.
32
33 Specify a system file, portable file, or scratch file with a file name
34 string or as a file handle (@pxref{File Handles}).  The dictionary in the
35 file will be read, but it will not replace the active file dictionary.
36 The file's data will not be read.
37
38 Only variables with names that exist in both the active file and the
39 system file are considered.  Variables with the same name but different
40 types (numeric, string) will cause an error message.  Otherwise, the
41 system file variables' attributes will replace those in their matching
42 active file variables:
43
44 @itemize @bullet
45 @item
46 If a system file variable has a variable label, then it will replace the
47 active file variable's variable label.  If the system file variable does
48 not have a variable label, then the active file variable's variable
49 label, if any, will be retained.  
50
51 @item
52 If the system file variable has custom attributes (@pxref{VARIABLE
53 ATTRIBUTE}), then those attributes replace the active file variable's
54 custom attributes.  If the system file variable does not have custom
55 attributes, then the active file variable's custom attributes, if any,
56 will be retained.
57
58 @item
59 If the active file variable is numeric or short string, then value
60 labels and missing values, if any, will be copied to the active file
61 variable.  If the system file variable does not have value labels or
62 missing values, then those in the active file variable, if any, will not
63 be disturbed.
64 @end itemize
65
66 In addition to properties of variables, some properties of the active
67 file dictionary as a whole are updated:
68
69 @itemize @bullet
70 @item
71 If the system file has custom attributes (@pxref{DATAFILE ATTRIBUTE}),
72 then those attributes replace the active file variable's custom
73 attributes.
74
75 @item
76 If the active file has a weighting variable (@pxref{WEIGHT}), and the
77 system file does not, or if the weighting variable in the system file
78 does not exist in the active file, then the active file weighting
79 variable, if any, is retained.  Otherwise, the weighting variable in
80 the system file becomes the active file weighting variable.
81 @end itemize
82
83 @cmd{APPLY DICTIONARY} takes effect immediately.  It does not read the
84 active
85 file.  The system file is not modified.
86
87 @node EXPORT
88 @section EXPORT
89 @vindex EXPORT
90
91 @display
92 EXPORT
93         /OUTFILE='file-name'
94         /UNSELECTED=@{RETAIN,DELETE@}
95         /DIGITS=n
96         /DROP=var_list
97         /KEEP=var_list
98         /RENAME=(src_names=target_names)@dots{}
99         /TYPE=@{COMM,TAPE@}
100         /MAP
101 @end display
102
103 The @cmd{EXPORT} procedure writes the active file dictionary and data to a
104 specified portable file or scratch file.
105
106 By default, cases excluded with FILTER are written to the
107 file.  These can be excluded by specifying DELETE on the UNSELECTED
108 subcommand.  Specifying RETAIN makes the default explicit.
109
110 Portable files express real numbers in base 30.  Integers are always
111 expressed to the maximum precision needed to make them exact.
112 Non-integers are, by default, expressed to the machine's maximum
113 natural precision (approximately 15 decimal digits on many machines).
114 If many numbers require this many digits, the portable file may
115 significantly increase in size.  As an alternative, the DIGITS
116 subcommand may be used to specify the number of decimal digits of
117 precision to write.  DIGITS applies only to non-integers.
118
119 The OUTFILE subcommand, which is the only required subcommand, specifies
120 the portable file or scratch file to be written as a file name string or
121 a file handle (@pxref{File Handles}).
122
123 DROP, KEEP, and RENAME follow the same format as the SAVE procedure
124 (@pxref{SAVE}).
125
126 The TYPE subcommand specifies the character set for use in the
127 portable file.  Its value is currently not used.
128
129 The MAP subcommand is currently ignored.
130
131 @cmd{EXPORT} is a procedure.  It causes the active file to be read.
132
133 @node GET
134 @section GET
135 @vindex GET
136
137 @display
138 GET
139         /FILE=@{'file-name',file_handle@}
140         /DROP=var_list
141         /KEEP=var_list
142         /RENAME=(src_names=target_names)@dots{}
143 @end display
144
145 @cmd{GET} clears the current dictionary and active file and
146 replaces them with the dictionary and data from a specified file.
147
148 The FILE subcommand is the only required subcommand.  Specify the system
149 file, portable file, or scratch file to be read as a string file name or
150 a file handle (@pxref{File Handles}).
151
152 By default, all the variables in a file are read.  The DROP
153 subcommand can be used to specify a list of variables that are not to be
154 read.  By contrast, the KEEP subcommand can be used to specify variable
155 that are to be read, with all other variables not read.
156
157 Normally variables in a file retain the names that they were
158 saved under.  Use the RENAME subcommand to change these names.  Specify,
159 within parentheses, a list of variable names followed by an equals sign
160 (@samp{=}) and the names that they should be renamed to.  Multiple
161 parenthesized groups of variable names can be included on a single
162 RENAME subcommand.  Variables' names may be swapped using a RENAME
163 subcommand of the form @samp{/RENAME=(A B=B A)}.
164
165 Alternate syntax for the RENAME subcommand allows the parentheses to be
166 eliminated.  When this is done, only a single variable may be renamed at
167 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
168 deprecated.
169
170 DROP, KEEP, and RENAME are executed in left-to-right order.  
171 Each may be present any number of times.  @cmd{GET} never modifies a
172 file on disk.  Only the active file read from the file
173 is affected by these subcommands.
174
175 @cmd{GET} does not cause the data to be read, only the dictionary.  The data
176 is read later, when a procedure is executed.
177
178 Use of @cmd{GET} to read a portable file or scratch file is a PSPP
179 extension.
180
181 @node GET DATA
182 @section GET DATA
183 @vindex GET DATA
184
185 @display
186 GET DATA
187         /TYPE=@{GNM,PSQL,TXT@}
188         @dots{}additional subcommands depending on TYPE@dots{}
189 @end display
190
191 The @cmd{GET DATA} command is used to read files and other data sources 
192 created by other applications. 
193 When this command is executed, the current dictionary and active file are
194 replaced  with variables and data read from the specified source.
195
196 The TYPE subcommand is mandatory and must be the first subcommand
197 specified.  It determines the type of the file or source to read.
198 PSPP currently supports the following file types:
199
200 @table @asis
201 @item GNM
202 Spreadsheet files created by Gnumeric (@url{http://gnumeric.org}).
203
204 @item PSQL
205 Relations from PostgreSQL databases (@url{http://postgresql.org}).
206
207 @item TXT
208 Textual data files in columnar and delimited formats.
209 @end table
210
211 Each supported file type has additional subcommands, explained in
212 separate sections below.
213
214 @menu
215 * GET DATA /TYPE=GNM::
216 * GET DATA /TYPE=PSQL::
217 * GET DATA /TYPE=TXT::
218 @end menu
219
220 @node GET DATA /TYPE=GNM
221 @subsection Gnumeric Spreadsheet Files
222
223 @display
224 GET DATA /TYPE=GNM
225         /FILE=@{'file-name'@}
226         /SHEET=@{NAME 'sheet-name', INDEX n@}
227         /CELLRANGE=@{RANGE 'range', FULL@}
228         /READNAMES=@{ON, OFF@}
229         /ASSUMEDVARWIDTH=n.
230 @end display
231
232 @cindex Gnumeric
233 @cindex spreadsheet files
234 To use GET DATA to read a spreadsheet file created by Gnumeric
235 (@url{http://gnumeric.org}), specify TYPE=GNM to indicate the file's
236 format and use FILE to indicate the Gnumeric file to be read.  All
237 other subcommands are optional.
238
239 The format of each variable is determined by the format of the spreadsheet 
240 cell containing the first datum for the variable.
241 If this cell is of string (text) format, then the width of the variable is
242 determined from the length of the string it contains, unless the 
243 ASSUMEDVARWIDTH subcommand is given.
244
245
246 The FILE subcommand is mandatory. Specify the name of the file
247 to be read.
248
249 The SHEET subcommand specifies the sheet within the spreadsheet file to read.
250 There are two forms of the SHEET subcommand.
251 In the first form,
252 @samp{/SHEET=name @var{sheet-name}}, the string @var{sheet-name} is the
253 name of the sheet to read.
254 In the second form, @samp{/SHEET=index @var{idx}}, @var{idx} is a
255 integer which is the index of the sheet to read.
256 The first sheet has the index 1.
257 If the SHEET subcommand is omitted, then the command will read the
258 first sheet in the file.
259
260 The CELLRANGE subcommand specifies the range of cells within the sheet to read.
261 If the subcommand is given as @samp{/CELLRANGE=FULL}, then the entire
262 sheet  is read.
263 To read only part of a sheet, use the form 
264 @samp{/CELLRANGE=range '@var{top-left-cell}:@var{bottom-right-cell}'}.
265 For example, the subcommand @samp{/CELLRANGE=range 'C3:P19'} reads 
266 columns C--P, and rows 3--19 inclusive.
267 If no CELLRANGE subcommand is given, then the entire sheet is read.
268
269 If @samp{/READNAMES=ON} is specified, then the contents of cells of
270 the first row are used as the names of the variables in which to store
271 the data from subsequent rows. 
272 If the READNAMES command is omitted, or if @samp{/READNAMES=OFF} is
273 used, then the variables  receive automatically assigned names.
274
275 The ASSUMEDVARWIDTH subcommand specifies the maximum width of string
276 variables read  from the file.
277 If omitted, the default value is determined from the length of the 
278 string in the first spreadsheet cell for each variable.
279
280
281 @node GET DATA /TYPE=PSQL
282 @subsection Postgres Database Queries
283
284 @display
285 GET DATA /TYPE=PSQL
286          /CONNECT=@{connection info@}
287          /SQL=@{query@}
288          [/ASSUMEDVARWIDTH=n]
289          [/UNENCRYPTED]
290          [/BSIZE=n].
291 @end display
292
293 @cindex postgres
294 @cindex databases
295
296 The PSQL type is used to import data from a postgres database server.
297 The server may be located locally or remotely.
298 Variables are automatically created based on the table column names 
299 or the names specified in the SQL query.
300 Postgres data types of high precision, will loose precision when 
301 imported into PSPP.
302 Not all the postgres data types are able to be represented in PSPP.
303 If a datum cannot be represented a warning will be issued and that 
304 datum will be set to SYSMIS.
305
306 The CONNECT subcommand is mandatory.
307 It is a string specifying the parameters of the database server from
308 which the data should be fetched.
309 The format of the string is given in the postgres manual
310 @url{http://www.postgresql.org/docs/8.0/static/libpq.html#LIBPQ-CONNECT}.
311
312 The SQL subcommand is mandatory.
313 It must be a valid SQL string to retrieve data from the database.
314
315 The ASSUMEDVARWIDTH subcommand specifies the maximum width of string
316 variables read  from the database.
317 If omitted, the default value is determined from the length of the 
318 string in the first value read for each variable.
319
320 The UNENCRYPTED subcommand allows data to be retrieved over an insecure
321 connection.
322 If the connection is not encrypted, and the UNENCRYPTED subcommand is not
323 given, then an error will occur.
324 Whether or not the connection is
325 encrypted depends upon the underlying psql library and the 
326 capabilities of the database server.
327
328 The BSIZE subcommand serves only to optimise the speed of data transfer.
329 It specifies an upper limit on
330 number of cases to fetch from the database at once.
331 The default value is 4096.
332 If your SQL statement fetches a large number of cases but only a small number of
333 variables, then the data transfer may be faster if you increase this value.
334 Conversely, if the number of variables is large, or if the machine on which 
335 PSPP is running has only a
336 small amount of memory, then a smaller value will be better.
337
338
339 The following syntax is an example:
340 @example
341 GET DATA /TYPE=PSQL
342      /CONNECT='host=example.com port=5432 dbname=product user=fred passwd=xxxx'
343      /SQL='select * from manufacturer'.
344 @end example
345
346
347 @node GET DATA /TYPE=TXT
348 @subsection Textual Data Files
349
350 @display
351 GET DATA /TYPE=TXT
352         /FILE=@{'file-name',file_handle@}
353         [/ARRANGEMENT=@{DELIMITED,FIXED@}]
354         [/FIRSTCASE=@{first_case@}]
355         [/IMPORTCASE=@{ALL,FIRST max_cases,PERCENT percent@}]
356         @dots{}additional subcommands depending on ARRANGEMENT@dots{}
357 @end display
358
359 @cindex text files
360 @cindex data files
361 When TYPE=TXT is specified, GET DATA reads data in a delimited or
362 fixed columnar format, much like DATA LIST (@pxref{DATA LIST}).
363
364 The FILE subcommand is mandatory.  Specify the file to be read as 
365 a string file name or (for textual data
366 only) a file handle (@pxref{File Handles}).
367
368 The ARRANGEMENT subcommand determines the file's basic format.
369 DELIMITED, the default setting, specifies that fields in the input
370 data are separated by spaces, tabs, or other user-specified
371 delimiters.  FIXED specifies that fields in the input data appear at
372 particular fixed column positions within records of a case.
373
374 By default, cases are read from the input file starting from the first
375 line.  To skip lines at the beginning of an input file, set FIRSTCASE
376 to the number of the first line to read: 2 to skip the first line, 3
377 to skip the first two lines, and so on.
378
379 IMPORTCASE can be used to limit the number of cases read from the
380 input file.  With the default setting, ALL, all cases in the file are
381 read.  Specify FIRST @i{max_cases} to read at most @i{max_cases} cases
382 from the file.  Use PERCENT @i{percent} to read only @i{percent}
383 percent, approximately, of the cases contained in the file.  (The
384 percentage is approximate, because there is no way to accurately count
385 the number of cases in the file without reading the entire file.  The
386 number of cases in some kinds of unusual files cannot be estimated;
387 PSPP will read all cases in such files.)
388
389 FIRSTCASE and IMPORTCASE may be used with delimited and fixed-format
390 data.  The remaining subcommands, which apply only to one of the two  file
391 arrangements, are described below.
392
393 @menu
394 * GET DATA /TYPE=TXT /ARRANGEMENT=DELIMITED::
395 * GET DATA /TYPE=TXT /ARRANGEMENT=FIXED::
396 @end menu
397
398 @node GET DATA /TYPE=TXT /ARRANGEMENT=DELIMITED
399 @subsubsection Reading Delimited Data
400
401 @display
402 GET DATA /TYPE=TXT
403         /FILE=@{'file-name',file_handle@}
404         [/ARRANGEMENT=@{DELIMITED,FIXED@}]
405         [/FIRSTCASE=@{first_case@}]
406         [/IMPORTCASE=@{ALL,FIRST max_cases,PERCENT percent@}]
407
408         /DELIMITERS="delimiters"
409         [/QUALIFIER="quotes" [/ESCAPE]]
410         [/DELCASE=@{LINE,VARIABLES n_variables@}]
411         /VARIABLES=del_var [del_var]@dots{}
412 where each del_var takes the form:
413         variable format
414 @end display
415
416 The GET DATA command with TYPE=TXT and ARRANGEMENT=DELIMITED reads
417 input data from text files in delimited format, where fields are
418 separated by a set of user-specified delimiters.  Its capabilities are
419 similar to those of DATA LIST FREE (@pxref{DATA LIST FREE}), with a
420 few enhancements.
421
422 The required FILE subcommand and optional FIRSTCASE and IMPORTCASE
423 subcommands are described above (@pxref{GET DATA /TYPE=TXT}).
424
425 DELIMITERS, which is required, specifies the set of characters that
426 may separate fields.  Each character in the string specified on
427 DELIMITERS separates one field from the next.  The end of a line also
428 separates fields, regardless of DELIMITERS.  Two consecutive
429 delimiters in the input yield an empty field, as does a delimiter at
430 the end of a line.  A space character as a delimiter is an exception:
431 consecutive spaces do not yield an empty field and neither does any
432 number of spaces at the end of a line.
433
434 To use a tab as a delimiter, specify @samp{\t} at the beginning of the
435 DELIMITERS string.  To use a backslash as a delimiter, specify
436 @samp{\\} as the first delimiter or, if a tab should also be a
437 delimiter, immediately following @samp{\t}.  To read a data file in
438 which each field appears on a separate line, specify the empty string
439 for DELIMITERS.
440
441 The optional QUALIFIER subcommand names one or more characters that
442 can be used to quote values within fields in the input.  A field that
443 begins with one of the specified quote characters ends at the next
444 matching quote.  Intervening delimiters become part of the field,
445 instead of terminating it.  The ability to specify more than one quote
446 character is a PSPP extension.
447
448 By default, a character specified on QUALIFIER cannot itself be
449 embedded within a field that it quotes, because the quote character
450 always terminates the quoted field.  With ESCAPE, however, a doubled
451 quote character within a quoted field inserts a single instance of the
452 quote into the field.  For example, if @samp{'} is specified on
453 QUALIFIER, then without ESCAPE @code{'a''b'} specifies a pair of
454 fields that contain @samp{a} and @samp{b}, but with ESCAPE it
455 specifies a single field that contains @samp{a'b}.  ESCAPE is a PSPP
456 extension.
457
458 The DELCASE subcommand controls how data may be broken across lines in
459 the data file.  With LINE, the default setting, each line must contain
460 all the data for exactly one case.  For additional flexibility, to
461 allow a single case to be split among lines or multiple cases to be
462 contained on a single line, specify VARIABLES @i{n_variables}, where
463 @i{n_variables} is the number of variables per case.
464
465 The VARIABLES subcommand is required and must be the last subcommand.
466 Specify the name of each variable and its input format (@pxref{Input
467 and Output Formats}) in the order they should be read from the input
468 file.
469
470 @subsubheading Examples
471
472 @noindent
473 On a Unix-like system, the @samp{/etc/passwd} file has a format
474 similar to this:
475
476 @example
477 root:$1$nyeSP5gD$pDq/:0:0:,,,:/root:/bin/bash
478 blp:$1$BrP/pFg4$g7OG:1000:1000:Ben Pfaff,,,:/home/blp:/bin/bash
479 john:$1$JBuq/Fioq$g4A:1001:1001:John Darrington,,,:/home/john:/bin/bash
480 jhs:$1$D3li4hPL$88X1:1002:1002:Jason Stover,,,:/home/jhs:/bin/csh
481 @end example
482
483 @noindent
484 The following syntax reads a file in the format used by
485 @samp{/etc/passwd}:
486
487 @c If you change this example, change the regression test in
488 @c tests/language/data-io/get-data.at to match.
489 @example
490 GET DATA /TYPE=TXT /FILE='/etc/passwd' /DELIMITERS=':'
491         /VARIABLES=username A20
492                    password A40
493                    uid F10
494                    gid F10
495                    gecos A40
496                    home A40
497                    shell A40.
498 @end example
499
500 @noindent
501 Consider the following data on used cars:
502
503 @example
504 model   year    mileage price   type    age
505 Civic   2002    29883   15900   Si      2
506 Civic   2003    13415   15900   EX      1
507 Civic   1992    107000  3800    n/a     12
508 Accord  2002    26613   17900   EX      1
509 @end example
510
511 @noindent
512 The following syntax can be used to read the used car data:
513
514 @c If you change this example, change the regression test in
515 @c tests/language/data-io/get-data.at to match.
516 @example
517 GET DATA /TYPE=TXT /FILE='cars.data' /DELIMITERS=' ' /FIRSTCASE=2
518         /VARIABLES=model A8
519                    year F4
520                    mileage F6
521                    price F5
522                    type A4
523                    age F2.
524 @end example
525
526 @noindent
527 Consider the following information on animals in a pet store:
528
529 @example
530 'Pet''s Name', "Age", "Color", "Date Received", "Price", "Height", "Type"
531 , (Years), , , (Dollars), ,
532 "Rover", 4.5, Brown, "12 Feb 2004", 80, '1''4"', "Dog"
533 "Charlie", , Gold, "5 Apr 2007", 12.3, "3""", "Fish"
534 "Molly", 2, Black, "12 Dec 2006", 25, '5"', "Cat"
535 "Gilly", , White, "10 Apr 2007", 10, "3""", "Guinea Pig"
536 @end example
537
538 @noindent
539 The following syntax can be used to read the pet store data:
540
541 @c If you change this example, change the regression test in
542 @c tests/language/data-io/get-data.at to match.
543 @example
544 GET DATA /TYPE=TXT /FILE='pets.data' /DELIMITERS=', ' /QUALIFIER='''"' /ESCAPE
545         /FIRSTCASE=3
546         /VARIABLES=name A10
547                    age F3.1
548                    color A5
549                    received EDATE10
550                    price F5.2
551                    height a5
552                    type a10.
553 @end example
554
555 @node GET DATA /TYPE=TXT /ARRANGEMENT=FIXED
556 @subsubsection Reading Fixed Columnar Data
557
558 @display
559 GET DATA /TYPE=TXT
560         /FILE=@{'file-name',file_handle@}
561         [/ARRANGEMENT=@{DELIMITED,FIXED@}]
562         [/FIRSTCASE=@{first_case@}]
563         [/IMPORTCASE=@{ALL,FIRST max_cases,PERCENT percent@}]
564
565         [/FIXCASE=n]
566         /VARIABLES fixed_var [fixed_var]@dots{}
567             [/rec# fixed_var [fixed_var]@dots{}]@dots{}
568 where each fixed_var takes the form:
569         variable start-end format
570 @end display
571
572 The GET DATA command with TYPE=TXT and ARRANGEMENT=FIXED reads input
573 data from text files in fixed format, where each field is located in
574 particular fixed column positions within records of a case.  Its
575 capabilities are similar to those of DATA LIST FIXED (@pxref{DATA LIST
576 FIXED}), with a few enhancements.
577
578 The required FILE subcommand and optional FIRSTCASE and IMPORTCASE
579 subcommands are described above (@pxref{GET DATA /TYPE=TXT}).
580
581 The optional FIXCASE subcommand may be used to specify the positive
582 integer number of input lines that make up each case.  The default
583 value is 1.
584
585 The VARIABLES subcommand, which is required, specifies the positions
586 at which each variable can be found.  For each variable, specify its
587 name, followed by its start and end column separated by @samp{-}
588 (e.g.@: @samp{0-9}), followed by the input format type (e.g.@:
589 @samp{F}).  For this command, columns are numbered starting from 0 at
590 the left column.  Introduce the variables in the second and later
591 lines of a case by a slash followed by the number of the line within
592 the case, e.g.@: @samp{/2} for the second line.
593
594 @subsubheading Examples
595
596 @noindent
597 Consider the following data on used cars:
598
599 @example
600 model   year    mileage price   type    age
601 Civic   2002    29883   15900   Si      2
602 Civic   2003    13415   15900   EX      1
603 Civic   1992    107000  3800    n/a     12
604 Accord  2002    26613   17900   EX      1
605 @end example
606
607 @noindent
608 The following syntax can be used to read the used car data:
609
610 @c If you change this example, change the regression test in
611 @c tests/language/data-io/get-data.at to match.
612 @example
613 GET DATA /TYPE=TXT /FILE='cars.data' /ARRANGEMENT=FIXED /FIRSTCASE=2
614         /VARIABLES=model 0-7 A
615                    year 8-15 F
616                    mileage 16-23 F
617                    price 24-31 F
618                    type 32-40 A
619                    age 40-47 F.
620 @end example
621
622 @node IMPORT
623 @section IMPORT
624 @vindex IMPORT
625
626 @display
627 IMPORT
628         /FILE='file-name'
629         /TYPE=@{COMM,TAPE@}
630         /DROP=var_list
631         /KEEP=var_list
632         /RENAME=(src_names=target_names)@dots{}
633 @end display
634
635 The @cmd{IMPORT} transformation clears the active file dictionary and
636 data and
637 replaces them with a dictionary and data from a system, portable file,
638 or scratch file.
639
640 The FILE subcommand, which is the only required subcommand, specifies
641 the portable file to be read as a file name string or a file handle
642 (@pxref{File Handles}).
643
644 The TYPE subcommand is currently not used.
645
646 DROP, KEEP, and RENAME follow the syntax used by @cmd{GET} (@pxref{GET}).
647
648 @cmd{IMPORT} does not cause the data to be read, only the dictionary.  The
649 data is read later, when a procedure is executed.
650
651 Use of @cmd{IMPORT} to read a system file or scratch file is a PSPP
652 extension.
653
654 @node SAVE
655 @section SAVE
656 @vindex SAVE
657
658 @display
659 SAVE
660         /OUTFILE=@{'file-name',file_handle@}
661         /UNSELECTED=@{RETAIN,DELETE@}
662         /@{COMPRESSED,UNCOMPRESSED@}
663         /PERMISSIONS=@{WRITEABLE,READONLY@}
664         /DROP=var_list
665         /KEEP=var_list
666         /VERSION=version
667         /RENAME=(src_names=target_names)@dots{}
668         /NAMES
669         /MAP
670 @end display
671
672 The @cmd{SAVE} procedure causes the dictionary and data in the active
673 file to
674 be written to a system file or scratch file.
675
676 OUTFILE is the only required subcommand.  Specify the system file or
677 scratch file to be written as a string file name or a file handle
678 (@pxref{File Handles}).
679
680 By default, cases excluded with FILTER are written to the system file.
681 These can be excluded by specifying DELETE on the UNSELECTED
682 subcommand.  Specifying RETAIN makes the default explicit.
683
684 The COMPRESS and UNCOMPRESS subcommand determine whether the saved
685 system file is compressed.  By default, system files are compressed.
686 This default can be changed with the SET command (@pxref{SET}).
687
688 The PERMISSIONS subcommand specifies permissions for the new system
689 file.  WRITEABLE, the default, creates the file with read and write
690 permission.  READONLY creates the file for read-only access.
691
692 By default, all the variables in the active file dictionary are written
693 to the system file.  The DROP subcommand can be used to specify a list
694 of variables not to be written.  In contrast, KEEP specifies variables
695 to be written, with all variables not specified not written.
696
697 Normally variables are saved to a system file under the same names they
698 have in the active file.  Use the RENAME subcommand to change these names.
699 Specify, within parentheses, a list of variable names followed by an
700 equals sign (@samp{=}) and the names that they should be renamed to.
701 Multiple parenthesized groups of variable names can be included on a
702 single RENAME subcommand.  Variables' names may be swapped using a
703 RENAME subcommand of the form @samp{/RENAME=(A B=B A)}.
704
705 Alternate syntax for the RENAME subcommand allows the parentheses to be
706 eliminated.  When this is done, only a single variable may be renamed at
707 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
708 deprecated.
709
710 DROP, KEEP, and RENAME are performed in left-to-right order.  They
711 each may be present any number of times.  @cmd{SAVE} never modifies
712 the active file.  DROP, KEEP, and RENAME only affect the system file
713 written to disk.
714
715 The VERSION subcommand specifies the version of the file format. Valid
716 versions are 2 and 3.  The default version is 3.  In version 2 system
717 files, variable names longer than 8 bytes will be truncated.  The two
718 versions are otherwise identical.
719
720 The NAMES and MAP subcommands are currently ignored.
721
722 @cmd{SAVE} causes the data to be read.  It is a procedure.
723
724 @node SAVE TRANSLATE
725 @section SAVE TRANSLATE
726 @vindex SAVE TRANSLATE
727
728 @display
729 SAVE TRANSLATE
730         /OUTFILE=@{'file-name',file_handle@}
731         /TYPE=@{CSV,TAB@}
732         [/REPLACE]
733         [/MISSING=@{IGNORE,RECODE@}]
734
735         [/DROP=var_list]
736         [/KEEP=var_list]
737         [/RENAME=(src_names=target_names)@dots{}]
738         [/UNSELECTED=@{RETAIN,DELETE@}]
739         [/MAP]
740
741         @dots{}additional subcommands depending on TYPE@dots{}
742 @end display
743
744 The @cmd{SAVE TRANSLATE} command is used to save data into various
745 formats understood by other applications.
746
747 The OUTFILE and TYPE subcommands are mandatory.  OUTFILE specifies the
748 file to be written, as a string file name or a file handle
749 (@pxref{File Handles}).  TYPE determines the type of the file or
750 source to read.  It must be one of the following:
751
752 @table @asis
753 @item CSV
754 Comma-separated value format,
755
756 @item TAB
757 Tab-delimited format.
758 @end table
759
760 By default, SAVE TRANSLATE will not overwrite an existing file.  Use
761 REPLACE to force an existing file to be overwritten.
762
763 With MISSING=IGNORE, the default, SAVE TRANSLATE treats user-missing
764 values as if they were not missing.  Specify MISSING=RECODE to output
765 numeric user-missing values like system-missing values and string
766 user-missing values as all spaces.
767
768 By default, all the variables in the active file dictionary are saved
769 to the system file, but DROP or KEEP can select a subset of variable
770 to save.  The RENAME subcommand can also be used to change the names
771 under which variables are saved.  UNSELECTED determines whether cases
772 filtered out by the FILTER command are written to the output file.
773 These subcommands have the same syntax and meaning as on the
774 @cmd{SAVE} command (@pxref{SAVE}).
775
776 Each supported file type has additional subcommands, explained in
777 separate sections below.
778
779 @cmd{SAVE TRANSLATE} causes the data to be read.  It is a procedure.
780
781 @menu
782 * SAVE TRANSLATE /TYPE=CSV and TYPE=TAB::
783 @end menu
784
785 @node SAVE TRANSLATE /TYPE=CSV and TYPE=TAB
786 @subsection Writing Comma- and Tab-Separated Data Files
787
788 @display
789 SAVE TRANSLATE
790         /OUTFILE=@{'file-name',file_handle@}
791         /TYPE=CSV
792         [/REPLACE]
793         [/MISSING=@{IGNORE,RECODE@}]
794
795         [/DROP=var_list]
796         [/KEEP=var_list]
797         [/RENAME=(src_names=target_names)@dots{}]
798         [/UNSELECTED=@{RETAIN,DELETE@}]
799
800         [/FIELDNAMES]
801         [/CELLS=@{VALUES,LABELS@}]
802         [/TEXTOPTIONS DELIMITER='delimiter']
803         [/TEXTOPTIONS QUALIFIER='qualifier']
804         [/TEXTOPTIONS DECIMAL=@{DOT,COMMA@}]
805         [/TEXTOPTIONS FORMAT=@{PLAIN,VARIABLE@}]
806 @end display
807
808 The SAVE TRANSLATE command with TYPE=CSV or TYPE=TAB writes data in a
809 comma- or tab-separated value format similar to that described by
810 RFC@tie{}4180.  Each variable becomes one output column, and each case
811 becomes one line of output.  If FIELDNAMES is specified, an additional
812 line at the top of the output file lists variable names.
813
814 The CELLS and TEXTOPTIONS FORMAT settings determine how values are
815 written to the output file:
816
817 @table @asis
818 @item CELLS=VALUES FORMAT=PLAIN (the default settings)
819 Writes variables to the output in ``plain'' formats that ignore the
820 details of variable formats.  Numeric values are written as plain
821 decimal numbers with enough digits to indicate their exact values in
822 machine representation.  Numeric values include @samp{e} followed by
823 an exponent if the exponent value would be less than -4 or greater
824 than 16.  Dates are written in MM/DD/YYYY format and times in HH:MM:SS
825 format.  WKDAY and MONTH values are written as decimal numbers.
826
827 Numeric values use, by default, the decimal point character set with
828 SET DECIMAL (@pxref{SET DECIMAL}).  Use DECIMAL=DOT or DECIMAL=COMMA
829 to force a particular decimal point character.
830
831 @item CELLS=VALUES FORMAT=VARIABLE
832 Writes variables using their print formats.  Leading and trailing
833 spaces are removed from numeric values, and trailing spaces are
834 removed from string values.
835
836 @item CELLS=LABEL FORMAT=PLAIN
837 @itemx CELLS=LABEL FORMAT=VARIABLE
838 Writes value labels where they exist, and otherwise writes the values
839 themselves as described above.
840 @end table
841
842 Regardless of CELLS and TEXTOPTIONS FORMAT, numeric system-missing
843 values are output as a single space.
844
845 For TYPE=TAB, tab characters delimit values.  For TYPE=CSV, the
846 TEXTOPTIONS DELIMITER and DECIMAL settings determine the character
847 that separate values within a line.  If DELIMITER is specified, then
848 the specified string separate values.  If DELIMITER is not specified,
849 then the default is a comma with DECIMAL=DOT or a semicolon with
850 DECIMAL=COMMA.  If DECIMAL is not given either, it is implied by the
851 decimal point character set with SET DECIMAL (@pxref{SET DECIMAL}).
852
853 The TEXTOPTIONS QUALIFIER setting specifies a character that is output
854 before and after a value that contains the delimiter character or the
855 qualifier character.  The default is a double quote (@samp{@@}).  A
856 qualifier character that appears within a value is doubled.
857
858 @node SYSFILE INFO
859 @section SYSFILE INFO
860 @vindex SYSFILE INFO
861
862 @display 
863 SYSFILE INFO FILE='file-name'.
864 @end display
865
866 @cmd{SYSFILE INFO} reads the dictionary in a system file and
867 displays the information in its dictionary.
868
869 Specify a file name or file handle.  @cmd{SYSFILE INFO} reads that file as
870 a system file and displays information on its dictionary.
871
872 @cmd{SYSFILE INFO} does not affect the current active file.
873
874 @node XEXPORT
875 @section XEXPORT
876 @vindex XEXPORT
877
878 @display
879 XEXPORT
880         /OUTFILE='file-name'
881         /DIGITS=n
882         /DROP=var_list
883         /KEEP=var_list
884         /RENAME=(src_names=target_names)@dots{}
885         /TYPE=@{COMM,TAPE@}
886         /MAP
887 @end display
888
889 The @cmd{EXPORT} transformation writes the active file dictionary and
890 data to a specified portable file.
891
892 This transformation is a PSPP extension.
893
894 It is similar to the @cmd{EXPORT} procedure, with two differences:
895
896 @itemize
897 @item
898 @cmd{XEXPORT} is a transformation, not a procedure.  It is executed when
899 the data is read by a procedure or procedure-like command.
900
901 @item
902 @cmd{XEXPORT} does not support the UNSELECTED subcommand.
903 @end itemize
904
905 @xref{EXPORT}, for more information.
906
907 @node XSAVE
908 @section XSAVE
909 @vindex XSAVE
910
911 @display
912 XSAVE
913         /OUTFILE='file-name'
914         /@{COMPRESSED,UNCOMPRESSED@}
915         /PERMISSIONS=@{WRITEABLE,READONLY@}
916         /DROP=var_list
917         /KEEP=var_list
918         /VERSION=version
919         /RENAME=(src_names=target_names)@dots{}
920         /NAMES
921         /MAP
922 @end display
923
924 The @cmd{XSAVE} transformation writes the active file dictionary and
925 data to a system file or scratch file.  It is similar to the @cmd{SAVE}
926 procedure, with two differences:
927
928 @itemize
929 @item
930 @cmd{XSAVE} is a transformation, not a procedure.  It is executed when
931 the data is read by a procedure or procedure-like command.
932
933 @item
934 @cmd{XSAVE} does not support the UNSELECTED subcommand.
935 @end itemize
936
937 @xref{SAVE}, for more information.