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