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