ae10ec7aa1dbbc49383e9914320cb3bc2ba37f24
[pspp-builds.git] / doc / files.texi
1 @node System and Portable Files
2 @chapter System Files and Portable Files
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 * MATCH FILES::                 Merge system files.
14 * SAVE::                        Write to a system file.
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/command/get-data-txt-examples.sh 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/command/get-data-txt-examples.sh 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/command/get-data-txt-examples.sh 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/command/get-data-txt-examples.sh 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 MATCH FILES
655 @section MATCH FILES
656 @vindex MATCH FILES
657
658 @display
659 MATCH FILES
660         /@{FILE,TABLE@}=@{*,'file-name'@}
661         /RENAME=(src_names=target_names)@dots{}
662         /IN=var_name
663
664         /BY=var_list
665         /DROP=var_list
666         /KEEP=var_list
667         /FIRST=var_name
668         /LAST=var_name
669         /MAP
670 @end display
671
672 @cmd{MATCH FILES} merges one or more system, portable, or scratch files,
673 optionally
674 including the active file.  Cases with the same values for BY
675 variables are combined into a single case.  Cases with different
676 values are output in order.  Thus, multiple sorted files are
677 combined into a single sorted file based on the value of the BY
678 variables.  The results of the merge become the new active file.
679
680 Specify FILE with a system, portable, or scratch file as a file name
681 string or file handle
682 (@pxref{File Handles}), or with an asterisk (@samp{*}) to
683 indicate the current active file.  The files specified on FILE are
684 merged together based on the BY variables, or combined case-by-case if
685 BY is not specified.
686
687 Specify TABLE with a file to use it as a @dfn{table
688 lookup file}.  Cases in table lookup files are not used up after
689 they've been used once.  This means that data in table lookup files can
690 correspond to any number of cases in FILE files.  Table lookup files
691 correspond to lookup tables in traditional relational database systems.
692 If a table lookup file contains more than one case with a given set of
693 BY variables, only the first case is used.
694
695 Any number of FILE and TABLE subcommands may be specified.
696 Ordinarily, at least two FILE subcommands, or one FILE and at least
697 one TABLE, should be specified.  Each instance of FILE or TABLE can be
698 followed by any sequence of RENAME subcommands.  These have the same
699 form and meaning as the corresponding subcommands of @cmd{GET}
700 (@pxref{GET}), but apply only to variables in the given file.
701
702 Each FILE or TABLE may optionally be followed by an IN subcommand,
703 which creates a numeric variable with the specified name and format
704 F1.0.  The IN variable takes value 1 in a case if the given file
705 contributed a row to the merged file, 0 otherwise.  The DROP, KEEP,
706 and RENAME subcommands do not affect IN variables.
707
708 When more than one FILE or TABLE contains a variable with a given
709 name, those variables must all have the same type (numeric or string)
710 and, for string variables, the same width.  This rules applies to
711 variable names after renaming with RENAME; thus, RENAME can be used to
712 resolve conflicts.
713
714 FILE and TABLE must be specified at the beginning of the command, with
715 any RENAME or IN specifications immediately after the corresponding
716 FILE or TABLE.  These subcommands are followed by BY, DROP, KEEP,
717 FIRST, LAST, and MAP.
718
719 The BY subcommand specifies a list of variables that are used to match
720 cases from each of the files.  When TABLE or IN is used, BY is
721 required; otherwise, it is optional.  When BY is specified, all the
722 files named on FILE and TABLE subcommands must be sorted in ascending
723 order of the BY variables.  Variables belonging to files that are not
724 present for the current case are set to the system-missing value for
725 numeric variables or spaces for string variables.
726
727 The DROP and KEEP subcommands allow variables to be dropped from or
728 reordered within the new active file.  These subcommands have the same
729 form and meaning as the corresponding subcommands of @cmd{GET}
730 (@pxref{GET}).  They apply to the new active file as a whole, not to
731 individual input files.  The variable names specified on DROP and KEEP
732 are those after any renaming with RENAME.
733
734 The optional FIRST and LAST subcommands name variables that @cmd{MATCH
735 FILES} adds to the active file.  The new variables are numeric with
736 print and write format F1.0.  The value of the FIRST variable is 1 in
737 the first case with a given set of values for the BY variables, and 0
738 in other cases.  Similarly, the LAST variable is 1 in the last case
739 with a given of BY values, and 0 in other cases.
740
741 @cmd{MATCH FILES} may not be specified following @cmd{TEMPORARY}
742 (@pxref{TEMPORARY}) if the active file is used as an input source.
743
744 Use of portable or scratch files on @cmd{MATCH FILES} is a PSPP
745 extension.
746
747 @node SAVE
748 @section SAVE
749 @vindex SAVE
750
751 @display
752 SAVE
753         /OUTFILE=@{'file-name',file_handle@}
754         /UNSELECTED=@{RETAIN,DELETE@}
755         /@{COMPRESSED,UNCOMPRESSED@}
756         /PERMISSIONS=@{WRITEABLE,READONLY@}
757         /DROP=var_list
758         /KEEP=var_list
759         /VERSION=version
760         /RENAME=(src_names=target_names)@dots{}
761         /NAMES
762         /MAP
763 @end display
764
765 The @cmd{SAVE} procedure causes the dictionary and data in the active
766 file to
767 be written to a system file or scratch file.
768
769 OUTFILE is the only required subcommand.  Specify the system file or
770 scratch file to be written as a string file name or a file handle
771 (@pxref{File Handles}).
772
773 By default, cases excluded with FILTER are written to the system file.
774 These can be excluded by specifying DELETE on the UNSELECTED
775 subcommand.  Specifying RETAIN makes the default explicit.
776
777 The COMPRESS and UNCOMPRESS subcommand determine whether the saved
778 system file is compressed.  By default, system files are compressed.
779 This default can be changed with the SET command (@pxref{SET}).
780
781 The PERMISSIONS subcommand specifies permissions for the new system
782 file.  WRITEABLE, the default, creates the file with read and write
783 permission.  READONLY creates the file for read-only access.
784
785 By default, all the variables in the active file dictionary are written
786 to the system file.  The DROP subcommand can be used to specify a list
787 of variables not to be written.  In contrast, KEEP specifies variables
788 to be written, with all variables not specified not written.
789
790 Normally variables are saved to a system file under the same names they
791 have in the active file.  Use the RENAME subcommand to change these names.
792 Specify, within parentheses, a list of variable names followed by an
793 equals sign (@samp{=}) and the names that they should be renamed to.
794 Multiple parenthesized groups of variable names can be included on a
795 single RENAME subcommand.  Variables' names may be swapped using a
796 RENAME subcommand of the form @samp{/RENAME=(A B=B A)}.
797
798 Alternate syntax for the RENAME subcommand allows the parentheses to be
799 eliminated.  When this is done, only a single variable may be renamed at
800 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
801 deprecated.
802
803 DROP, KEEP, and RENAME are performed in left-to-right order.  They
804 each may be present any number of times.  @cmd{SAVE} never modifies
805 the active file.  DROP, KEEP, and RENAME only affect the system file
806 written to disk.
807
808 The VERSION subcommand specifies the version of the file format. Valid
809 versions are 2 and 3.  The default version is 3.  In version 2 system
810 files, variable names longer than 8 bytes will be truncated.  The two
811 versions are otherwise identical.
812
813 The NAMES and MAP subcommands are currently ignored.
814
815 @cmd{SAVE} causes the data to be read.  It is a procedure.
816
817 @node SYSFILE INFO
818 @section SYSFILE INFO
819 @vindex SYSFILE INFO
820
821 @display 
822 SYSFILE INFO FILE='file-name'.
823 @end display
824
825 @cmd{SYSFILE INFO} reads the dictionary in a system file and
826 displays the information in its dictionary.
827
828 Specify a file name or file handle.  @cmd{SYSFILE INFO} reads that file as
829 a system file and displays information on its dictionary.
830
831 @cmd{SYSFILE INFO} does not affect the current active file.
832
833 @node XEXPORT
834 @section XEXPORT
835 @vindex XEXPORT
836
837 @display
838 XEXPORT
839         /OUTFILE='file-name'
840         /DIGITS=n
841         /DROP=var_list
842         /KEEP=var_list
843         /RENAME=(src_names=target_names)@dots{}
844         /TYPE=@{COMM,TAPE@}
845         /MAP
846 @end display
847
848 The @cmd{EXPORT} transformation writes the active file dictionary and
849 data to a specified portable file.
850
851 This transformation is a PSPP extension.
852
853 It is similar to the @cmd{EXPORT} procedure, with two differences:
854
855 @itemize
856 @item
857 @cmd{XEXPORT} is a transformation, not a procedure.  It is executed when
858 the data is read by a procedure or procedure-like command.
859
860 @item
861 @cmd{XEXPORT} does not support the UNSELECTED subcommand.
862 @end itemize
863
864 @xref{EXPORT}, for more information.
865
866 @node XSAVE
867 @section XSAVE
868 @vindex XSAVE
869
870 @display
871 XSAVE
872         /OUTFILE='file-name'
873         /@{COMPRESSED,UNCOMPRESSED@}
874         /PERMISSIONS=@{WRITEABLE,READONLY@}
875         /DROP=var_list
876         /KEEP=var_list
877         /VERSION=version
878         /RENAME=(src_names=target_names)@dots{}
879         /NAMES
880         /MAP
881 @end display
882
883 The @cmd{XSAVE} transformation writes the active file dictionary and
884 data to a system file or scratch file.  It is similar to the @cmd{SAVE}
885 procedure, with two differences:
886
887 @itemize
888 @item
889 @cmd{XSAVE} is a transformation, not a procedure.  It is executed when
890 the data is read by a procedure or procedure-like command.
891
892 @item
893 @cmd{XSAVE} does not support the UNSELECTED subcommand.
894 @end itemize
895
896 @xref{SAVE}, for more information.
897 @setfilename ignored