Added the MATRIX DATA procedure.
[pspp] / doc / data-io.texi
1 @c (modify-syntax-entry ?_ "w")
2 @c (modify-syntax-entry ?' "'")
3 @c (modify-syntax-entry ?@ "'")
4
5
6 @node Data Input and Output
7 @chapter Data Input and Output
8 @cindex input
9 @cindex output
10 @cindex data
11 @cindex cases
12 @cindex observations
13
14 Data are the focus of the @pspp{} language.  
15 Each datum  belongs to a @dfn{case} (also called an @dfn{observation}).
16 Each case represents an individual or ``experimental unit''.
17 For example, in the results of a survey, the names of the respondents,
18 their sex, age, etc.@: and their responses are all data and the data
19 pertaining to single respondent is a case.
20 This chapter examines
21 the @pspp{} commands for defining variables and reading and writing data.
22 There are alternative commands to  read data from predefined sources
23 such as system files or databases (@xref{GET, GET DATA}.)
24
25 @quotation Note
26 These commands tell @pspp{} how to read data, but the data will not
27 actually be read until a procedure is executed.
28 @end quotation
29
30 @menu
31 * BEGIN DATA::                  Embed data within a syntax file.
32 * CLOSE FILE HANDLE::           Close a file handle.
33 * DATAFILE ATTRIBUTE::          Set custom attributes on data files.
34 * DATASET::                     Manage multiple datasets.
35 * DATA LIST::                   Fundamental data reading command.
36 * END CASE::                    Output the current case.
37 * END FILE::                    Terminate the current input program.
38 * FILE HANDLE::                 Support for special file formats.
39 * INPUT PROGRAM::               Support for complex input programs.
40 * LIST::                        List cases in the active dataset.
41 * NEW FILE::                    Clear the active dataset.
42 * MATRIX DATA::                 Defining matrix material for procedures.
43 * PRINT::                       Display values in print formats.
44 * PRINT EJECT::                 Eject the current page then print.
45 * PRINT SPACE::                 Print blank lines.
46 * REREAD::                      Take another look at the previous input line.
47 * REPEATING DATA::              Multiple cases on a single line.
48 * WRITE::                       Display values in write formats.
49 @end menu
50
51 @node BEGIN DATA
52 @section BEGIN DATA
53 @vindex BEGIN DATA
54 @vindex END DATA
55 @cindex Embedding data in syntax files
56 @cindex Data, embedding in syntax files
57
58 @display
59 BEGIN DATA.
60 @dots{}
61 END DATA.
62 @end display
63
64 @cmd{BEGIN DATA} and @cmd{END DATA} can be used to embed raw ASCII
65 data in a @pspp{} syntax file.  @cmd{DATA LIST} or another input
66 procedure must be used before @cmd{BEGIN DATA} (@pxref{DATA LIST}).
67 @cmd{BEGIN DATA} and @cmd{END DATA} must be used together.  @cmd{END
68 DATA} must appear by itself on a single line, with no leading
69 white space and exactly one space between the words @code{END} and
70 @code{DATA}, like this:
71
72 @example
73 END DATA.
74 @end example
75
76 @node CLOSE FILE HANDLE
77 @section CLOSE FILE HANDLE
78
79 @display
80 CLOSE FILE HANDLE @var{handle_name}.
81 @end display
82
83 @cmd{CLOSE FILE HANDLE} disassociates the name of a file handle with a
84 given file.  The only specification is the name of the handle to close.
85 Afterward
86 @cmd{FILE HANDLE}.
87
88 The file named INLINE, which represents data entered between @cmd{BEGIN
89 DATA} and @cmd{END DATA}, cannot be closed.  Attempts to close it with
90 @cmd{CLOSE FILE HANDLE} have no effect.
91
92 @cmd{CLOSE FILE HANDLE} is a @pspp{} extension.
93
94 @node DATAFILE ATTRIBUTE
95 @section DATAFILE ATTRIBUTE
96 @vindex DATAFILE ATTRIBUTE
97
98 @display
99 DATAFILE ATTRIBUTE
100          ATTRIBUTE=@var{name}('@var{value}') [@var{name}('@var{value}')]@dots{}
101          ATTRIBUTE=@var{name}@b{[}@var{index}@b{]}('@var{value}') [@var{name}@b{[}@var{index}@b{]}('@var{value}')]@dots{}
102          DELETE=@var{name} [@var{name}]@dots{}
103          DELETE=@var{name}@b{[}@var{index}@b{]} [@var{name}@b{[}@var{index}@b{]}]@dots{}
104 @end display
105
106 @cmd{DATAFILE ATTRIBUTE} adds, modifies, or removes user-defined
107 attributes associated with the active dataset.  Custom data file
108 attributes are not interpreted by @pspp{}, but they are saved as part of
109 system files and may be used by other software that reads them.
110
111 Use the @subcmd{ATTRIBUTE} subcommand to add or modify a custom data file
112 attribute.  Specify the name of the attribute as an identifier
113 (@pxref{Tokens}), followed by the desired value, in parentheses, as a
114 quoted string.  Attribute names that begin with @code{$} are reserved
115 for @pspp{}'s internal use, and attribute names that begin with @code{@@}
116 or @code{$@@} are not displayed by most @pspp{} commands that display
117 other attributes.  Other attribute names are not treated specially.
118
119 Attributes may also be organized into arrays.  To assign to an array
120 element, add an integer array index enclosed in square brackets
121 (@code{[} and @code{]}) between the attribute name and value.  Array
122 indexes start at 1, not 0.  An attribute array that has a single
123 element (number 1) is not distinguished from a non-array attribute.
124
125 Use the @subcmd{DELETE} subcommand to delete an attribute.  Specify an
126 attribute name by itself to delete an entire attribute, including all
127 array elements for attribute arrays.  Specify an attribute name
128 followed by an array index in square brackets to delete a single
129 element of an attribute array.  In the latter case, all the array
130 elements numbered higher than the deleted element are shifted down,
131 filling the vacated position.
132
133 To associate custom attributes with particular variables, instead of
134 with the entire active dataset, use @cmd{VARIABLE ATTRIBUTE}
135 (@pxref{VARIABLE ATTRIBUTE}) instead.
136
137 @cmd{DATAFILE ATTRIBUTE} takes effect immediately.  It is not affected
138 by conditional and looping structures such as @cmd{DO IF} or
139 @cmd{LOOP}.
140
141 @node DATASET
142 @section DATASET commands
143 @vindex DATASET
144
145 @display
146 DATASET NAME @var{name} [WINDOW=@{ASIS,FRONT@}].
147 DATASET ACTIVATE @var{name} [WINDOW=@{ASIS,FRONT@}].
148 DATASET COPY @var{name} [WINDOW=@{MINIMIZED,HIDDEN,FRONT@}].
149 DATASET DECLARE @var{name} [WINDOW=@{MINIMIZED,HIDDEN,FRONT@}].
150 DATASET CLOSE @{@var{name},*,ALL@}.
151 DATASET DISPLAY.
152 @end display
153
154 The @cmd{DATASET} commands simplify use of multiple datasets within a
155 @pspp{} session.  They allow datasets to be created and destroyed.  At
156 any given time, most @pspp{} commands work with a single dataset, called
157 the active dataset.
158
159 @vindex DATASET NAME
160 The DATASET NAME command gives the active dataset the specified name, or
161 if it already had a name, it renames it.  If another dataset already
162 had the given name, that dataset is deleted.
163
164 @vindex DATASET ACTIVATE
165 The DATASET ACTIVATE command selects the named dataset, which must
166 already exist, as the active dataset.  Before switching the active
167 dataset, any pending transformations are executed, as if @cmd{EXECUTE}
168 had been specified.  If the active dataset is unnamed before
169 switching, then it is deleted and becomes unavailable after switching.
170
171 @vindex DATASET COPY
172 The DATASET COPY command creates a new dataset with the specified
173 name, whose contents are a copy of the active dataset.  Any pending
174 transformations are executed, as if @cmd{EXECUTE} had been specified,
175 before making the copy.  If a dataset with the given name already
176 exists, it is replaced.  If the name is the name of the active
177 dataset, then the active dataset becomes unnamed.
178
179 @vindex DATASET DECLARE
180 The DATASET DECLARE command creates a new dataset that is initially
181 ``empty,'' that is, it has no dictionary or data.  If a dataset with
182 the given name already exists, this has no effect.  The new dataset
183 can be used with commands that support output to a dataset,
184 e.g. AGGREGATE (@pxref{AGGREGATE}).
185
186 @vindex DATASET CLOSE
187 The DATASET CLOSE command deletes a dataset.  If the active dataset is
188 specified by name, or if @samp{*} is specified, then the active
189 dataset becomes unnamed.  If a different dataset is specified by name,
190 then it is deleted and becomes unavailable.  Specifying ALL deletes
191 all datasets except for the active dataset, which becomes unnamed.
192
193 @vindex DATASET DISPLAY
194 The DATASET DISPLAY command lists all the currently defined datasets.
195
196 Many DATASET commands accept an optional @subcmd{WINDOW} subcommand.  In the
197 @pspp{}IRE GUI, the value given for this subcommand influences how the
198 dataset's window is displayed.  Outside the GUI, the @subcmd{WINDOW} subcommand
199 has no effect.  The valid values are:
200
201 @table @asis
202 @item ASIS
203 Do not change how the window is displayed.  This is the default for
204 DATASET NAME and DATASET ACTIVATE.
205
206 @item FRONT
207 Raise the dataset's window to the top.  Make it the default dataset
208 for running syntax.
209
210 @item MINIMIZED
211 Display the window ``minimized'' to an icon.  Prefer other datasets
212 for running syntax.  This is the default for DATASET COPY and DATASET
213 DECLARE.
214
215 @item HIDDEN
216 Hide the dataset's window.  Prefer other datasets for running syntax.
217 @end table
218
219 @node DATA LIST
220 @section DATA LIST
221 @vindex DATA LIST
222 @cindex reading data from a file
223 @cindex data, reading from a file
224 @cindex data, embedding in syntax files
225 @cindex embedding data in syntax files
226
227 Used to read text or binary data, @cmd{DATA LIST} is the most
228 fundamental data-reading command.  Even the more sophisticated input
229 methods use @cmd{DATA LIST} commands as a building block.
230 Understanding @cmd{DATA LIST} is important to understanding how to use
231 @pspp{} to read your data files.
232
233 There are two major variants of @cmd{DATA LIST}, which are fixed
234 format and free format.  In addition, free format has a minor variant,
235 list format, which is discussed in terms of its differences from vanilla
236 free format.
237
238 Each form of @cmd{DATA LIST} is described in detail below.
239
240 @xref{GET DATA}, for a command that offers a few enhancements over
241 DATA LIST and that may be substituted for DATA LIST in many
242 situations.
243
244 @menu
245 * DATA LIST FIXED::             Fixed columnar locations for data.
246 * DATA LIST FREE::              Any spacing you like.
247 * DATA LIST LIST::              Each case must be on a single line.
248 @end menu
249
250 @node DATA LIST FIXED
251 @subsection DATA LIST FIXED
252 @vindex DATA LIST FIXED
253 @cindex reading fixed-format data
254 @cindex fixed-format data, reading
255 @cindex data, fixed-format, reading
256 @cindex embedding fixed-format data
257
258 @display
259 DATA LIST [FIXED]
260         @{TABLE,NOTABLE@}
261         [FILE='@var{file_name}' [ENCODING='@var{encoding}']]
262         [RECORDS=@var{record_count}]
263         [END=@var{end_var}]
264         [SKIP=@var{record_count}]
265         /[line_no] @var{var_spec}@dots{}
266
267 where each @var{var_spec} takes one of the forms
268         @var{var_list} @var{start}-@var{end} [@var{type_spec}]
269         @var{var_list} (@var{fortran_spec})
270 @end display
271
272 @cmd{DATA LIST FIXED} is used to read data files that have values at fixed
273 positions on each line of single-line or multiline records.  The
274 keyword FIXED is optional.
275
276 The @subcmd{FILE} subcommand must be used if input is to be taken from an
277 external file.  It may be used to specify a file name as a string or a
278 file handle (@pxref{File Handles}).  If the @subcmd{FILE} subcommand is not used,
279 then input is assumed to be specified within the command file using
280 @cmd{BEGIN DATA}@dots{}@cmd{END DATA} (@pxref{BEGIN DATA}).
281 The @subcmd{ENCODING} subcommand may only be used if the @subcmd{FILE}
282 subcommand is also used.  It specifies the character encoding of the
283 file.  @xref{INSERT}, for information on supported encodings.
284
285 The optional @subcmd{RECORDS} subcommand, which takes a single integer as an
286 argument, is used to specify the number of lines per record.
287 If @subcmd{RECORDS}
288 is not specified, then the number of lines per record is calculated from
289 the list of variable specifications later in @cmd{DATA LIST}.
290
291 The @subcmd{END} subcommand is only useful in conjunction with @cmd{INPUT
292 PROGRAM}.  @xref{INPUT PROGRAM}, for details.
293
294 The optional @subcmd{SKIP} subcommand specifies a number of records to skip at
295 the beginning of an input file.  It can be used to skip over a row
296 that contains variable names, for example.
297
298 @cmd{DATA LIST} can optionally output a table describing how the data file
299 will be read.  The @subcmd{TABLE} subcommand enables this output, and
300 @subcmd{NOTABLE} disables it.  The default is to output the table.
301
302 The list of variables to be read from the data list must come last.
303 Each line in the data record is introduced by a slash (@samp{/}).
304 Optionally, a line number may follow the slash.  Following, any number
305 of variable specifications may be present.
306
307 Each variable specification consists of a list of variable names
308 followed by a description of their location on the input line.  Sets of
309 variables may be specified using the @cmd{DATA LIST} @subcmd{TO} convention
310 (@pxref{Sets of
311 Variables}).  There are two ways to specify the location of the variable
312 on the line: columnar style and FORTRAN style.
313
314 In columnar style, the starting column and ending column for the field
315 are specified after the variable name, separated by a dash (@samp{-}).
316 For instance, the third through fifth columns on a line would be
317 specified @samp{3-5}.  By default, variables are considered to be in
318 @samp{F} format (@pxref{Input and Output Formats}).  (This default can be
319 changed; see @ref{SET} for more information.)
320
321 In columnar style, to use a variable format other than the default,
322 specify the format type in parentheses after the column numbers.  For
323 instance, for alphanumeric @samp{A} format, use @samp{(A)}.  
324
325 In addition, implied decimal places can be specified in parentheses
326 after the column numbers.  As an example, suppose that a data file has a
327 field in which the characters @samp{1234} should be interpreted as
328 having the value 12.34.  Then this field has two implied decimal places,
329 and the corresponding specification would be @samp{(2)}.  If a field
330 that has implied decimal places contains a decimal point, then the
331 implied decimal places are not applied.
332
333 Changing the variable format and adding implied decimal places can be
334 done together; for instance, @samp{(N,5)}.
335
336 When using columnar style, the input and output width of each variable is
337 computed from the field width.  The field width must be evenly divisible
338 into the number of variables specified.
339
340 FORTRAN style is an altogether different approach to specifying field
341 locations.  With this approach, a list of variable input format
342 specifications, separated by commas, are placed after the variable names
343 inside parentheses.  Each format specifier advances as many characters
344 into the input line as it uses.
345
346 Implied decimal places also exist in FORTRAN style.  A format
347 specification with @var{d} decimal places also has @var{d} implied
348 decimal places.
349
350 In addition to the standard format specifiers (@pxref{Input and Output
351 Formats}), FORTRAN style defines some extensions:
352
353 @table @asis
354 @item @code{X}
355 Advance the current column on this line by one character position.
356
357 @item @code{T}@var{x}
358 Set the current column on this line to column @var{x}, with column
359 numbers considered to begin with 1 at the left margin.
360
361 @item @code{NEWREC}@var{x}
362 Skip forward @var{x} lines in the current record, resetting the active
363 column to the left margin.
364
365 @item Repeat count
366 Any format specifier may be preceded by a number.  This causes the
367 action of that format specifier to be repeated the specified number of
368 times.
369
370 @item (@var{spec1}, @dots{}, @var{specN})
371 Group the given specifiers together.  This is most useful when preceded
372 by a repeat count.  Groups may be nested arbitrarily.
373 @end table
374
375 FORTRAN and columnar styles may be freely intermixed.  Columnar style
376 leaves the active column immediately after the ending column
377 specified.  Record motion using @code{NEWREC} in FORTRAN style also
378 applies to later FORTRAN and columnar specifiers.
379  
380 @menu
381 * DATA LIST FIXED Examples::    Examples of DATA LIST FIXED.
382 @end menu
383
384 @node DATA LIST FIXED Examples
385 @unnumberedsubsubsec Examples
386
387 @enumerate
388 @item
389 @example
390 DATA LIST TABLE /NAME 1-10 (A) INFO1 TO INFO3 12-17 (1).
391
392 BEGIN DATA.
393 John Smith 102311
394 Bob Arnold 122015
395 Bill Yates  918 6
396 END DATA.
397 @end example
398
399 Defines the following variables:
400
401 @itemize @bullet
402 @item
403 @code{NAME}, a 10-character-wide string variable, in columns 1
404 through 10.
405
406 @item
407 @code{INFO1}, a numeric variable, in columns 12 through 13.
408
409 @item
410 @code{INFO2}, a numeric variable, in columns 14 through 15.
411
412 @item
413 @code{INFO3}, a numeric variable, in columns 16 through 17.
414 @end itemize
415
416 The @code{BEGIN DATA}/@code{END DATA} commands cause three cases to be
417 defined:
418
419 @example
420 Case   NAME         INFO1   INFO2   INFO3
421    1   John Smith     10      23      11
422    2   Bob Arnold     12      20      15
423    3   Bill Yates      9      18       6
424 @end example
425
426 The @code{TABLE} keyword causes @pspp{} to print out a table
427 describing the four variables defined.
428
429 @item
430 @example
431 DAT LIS FIL="survey.dat"
432         /ID 1-5 NAME 7-36 (A) SURNAME 38-67 (A) MINITIAL 69 (A)
433         /Q01 TO Q50 7-56
434         /.
435 @end example
436
437 Defines the following variables:
438
439 @itemize @bullet
440 @item
441 @code{ID}, a numeric variable, in columns 1-5 of the first record.
442
443 @item
444 @code{NAME}, a 30-character string variable, in columns 7-36 of the
445 first record.
446
447 @item
448 @code{SURNAME}, a 30-character string variable, in columns 38-67 of
449 the first record.
450
451 @item
452 @code{MINITIAL}, a 1-character string variable, in column 69 of
453 the first record.
454
455 @item
456 Fifty variables @code{Q01}, @code{Q02}, @code{Q03}, @dots{}, @code{Q49},
457 @code{Q50}, all numeric, @code{Q01} in column 7, @code{Q02} in column 8,
458 @dots{}, @code{Q49} in column 55, @code{Q50} in column 56, all in the second
459 record.
460 @end itemize
461
462 Cases are separated by a blank record.
463
464 Data is read from file @file{survey.dat} in the current directory.
465
466 This example shows keywords abbreviated to their first 3 letters.
467
468 @end enumerate
469
470 @node DATA LIST FREE
471 @subsection DATA LIST FREE
472 @vindex DATA LIST FREE
473
474 @display
475 DATA LIST FREE
476         [(@{TAB,'@var{c}'@}, @dots{})]
477         [@{NOTABLE,TABLE@}]
478         [FILE='@var{file_name}' [ENCODING='@var{encoding}']]
479         [SKIP=@var{record_cnt}]
480         /@var{var_spec}@dots{}
481
482 where each @var{var_spec} takes one of the forms
483         @var{var_list} [(@var{type_spec})]
484         @var{var_list} *
485 @end display
486
487 In free format, the input data is, by default, structured as a series
488 of fields separated by spaces, tabs, or line breaks.
489 If the current @subcmd{DECIMAL} separator is @subcmd{DOT} (@pxref{SET}),
490 then commas are also treated as field separators.
491 Each
492 field's content may be unquoted, or it may be quoted with a pairs of
493 apostrophes (@samp{'}) or double quotes (@samp{"}).  Unquoted white
494 space separates fields but is not part of any field.  Any mix of
495 spaces, tabs, and line breaks is equivalent to a single space for the
496 purpose of separating fields, but consecutive commas will skip a
497 field.
498
499 Alternatively, delimiters can be specified explicitly, as a
500 parenthesized, comma-separated list of single-character strings
501 immediately following FREE.  The word TAB may also be used to specify
502 a tab character as a delimiter.  When delimiters are specified
503 explicitly, only the given characters, plus line breaks, separate
504 fields.  Furthermore, leading spaces at the beginnings of fields are
505 not trimmed, consecutive delimiters define empty fields, and no form
506 of quoting is allowed.
507
508 The @subcmd{NOTABLE} and @subcmd{TABLE} subcommands are as in @cmd{DATA LIST FIXED} above.
509 @subcmd{NOTABLE} is the default.
510
511 The @subcmd{FILE}, @subcmd{SKIP}, and @subcmd{ENCODING} subcommands
512 are as in @cmd{DATA LIST FIXED} above.
513
514 The variables to be parsed are given as a single list of variable names.
515 This list must be introduced by a single slash (@samp{/}).  The set of
516 variable names may contain format specifications in parentheses
517 (@pxref{Input and Output Formats}).  Format specifications apply to all
518 variables back to the previous parenthesized format specification.  
519
520 In addition, an asterisk may be used to indicate that all variables
521 preceding it are to have input/output format @samp{F8.0}.
522
523 Specified field widths are ignored on input, although all normal limits
524 on field width apply, but they are honored on output.
525
526 @node DATA LIST LIST
527 @subsection DATA LIST LIST
528 @vindex DATA LIST LIST
529
530 @display
531 DATA LIST LIST
532         [(@{TAB,'@var{c}'@}, @dots{})]
533         [@{NOTABLE,TABLE@}]
534         [FILE='@var{file_name}' [ENCODING='@var{encoding}']]
535         [SKIP=@var{record_count}]
536         /@var{var_spec}@dots{}
537
538 where each @var{var_spec} takes one of the forms
539         @var{var_list} [(@var{type_spec})]
540         @var{var_list} *
541 @end display
542
543 With one exception, @cmd{DATA LIST LIST} is syntactically and
544 semantically equivalent to @cmd{DATA LIST FREE}.  The exception is
545 that each input line is expected to correspond to exactly one input
546 record.  If more or fewer fields are found on an input line than
547 expected, an appropriate diagnostic is issued.
548
549 @node END CASE
550 @section END CASE
551 @vindex END CASE
552
553 @display
554 END CASE.
555 @end display
556
557 @cmd{END CASE} is used only within @cmd{INPUT PROGRAM} to output the
558 current case.  @xref{INPUT PROGRAM}, for details.
559
560 @node END FILE
561 @section END FILE
562 @vindex END FILE
563
564 @display
565 END FILE.
566 @end display
567
568 @cmd{END FILE} is used only within @cmd{INPUT PROGRAM} to terminate
569 the current input program.  @xref{INPUT PROGRAM}.
570
571 @node FILE HANDLE
572 @section FILE HANDLE
573 @vindex FILE HANDLE
574
575 @display
576 For text files:
577         FILE HANDLE @var{handle_name}
578                 /NAME='@var{file_name}
579                 [/MODE=CHARACTER]
580                 [/ENDS=@{CR,CRLF@}]
581                 /TABWIDTH=@var{tab_width}
582                 [ENCODING='@var{encoding}']
583
584 For binary files in native encoding with fixed-length records:
585         FILE HANDLE @var{handle_name}
586                 /NAME='@var{file_name}'
587                 /MODE=IMAGE
588                 [/LRECL=@var{rec_len}]
589                 [ENCODING='@var{encoding}']
590
591 For binary files in native encoding with variable-length records:
592         FILE HANDLE @var{handle_name}
593                 /NAME='@var{file_name}'
594                 /MODE=BINARY
595                 [/LRECL=@var{rec_len}]
596                 [ENCODING='@var{encoding}']
597
598 For binary files encoded in EBCDIC:
599         FILE HANDLE @var{handle_name}
600                 /NAME='@var{file_name}'
601                 /MODE=360
602                 /RECFORM=@{FIXED,VARIABLE,SPANNED@}
603                 [/LRECL=@var{rec_len}]
604                 [ENCODING='@var{encoding}']
605 @end display
606
607 Use @cmd{FILE HANDLE} to associate a file handle name with a file and
608 its attributes, so that later commands can refer to the file by its
609 handle name.  Names of text files can be specified directly on
610 commands that access files, so that @cmd{FILE HANDLE} is only needed when a
611 file is not an ordinary file containing lines of text.  However,
612 @cmd{FILE HANDLE} may be used even for text files, and it may be
613 easier to specify a file's name once and later refer to it by an
614 abstract handle.
615
616 Specify the file handle name as the identifier immediately following the
617 @cmd{FILE HANDLE} command name.  The identifier INLINE is reserved for
618 representing data embedded in the syntax file (@pxref{BEGIN DATA}) The
619 file handle name must not already have been used in a previous
620 invocation of @cmd{FILE HANDLE}, unless it has been closed by an
621 intervening command (@pxref{CLOSE FILE HANDLE}).
622
623 The effect and syntax of @cmd{FILE HANDLE} depends on the selected MODE:
624
625 @itemize
626 @item
627 In CHARACTER mode, the default, the data file is read as a text file.
628 Each text line is read as one record.
629
630 In CHARACTER mode only, tabs are expanded to spaces by input programs,
631 except by @cmd{DATA LIST FREE} with explicitly specified delimiters.
632 Each tab is 4 characters wide by default, but TABWIDTH (a @pspp{}
633 extension) may be used to specify an alternate width.  Use a TABWIDTH
634 of 0 to suppress tab expansion.
635
636 A file written in CHARACTER mode by default uses the line ends of the
637 system on which PSPP is running, that is, on Windows, the default is
638 CR LF line ends, and on other systems the default is LF only.  Specify
639 ENDS as CR or CRLF to override the default.  PSPP reads files using
640 either convention on any kind of system, regardless of ENDS.
641
642 @item
643 In IMAGE mode, the data file is treated as a series of fixed-length
644 binary records.  LRECL should be used to specify the record length in
645 bytes, with a default of 1024.  On input, it is an error if an IMAGE
646 file's length is not a integer multiple of the record length.  On
647 output, each record is padded with spaces or truncated, if necessary,
648 to make it exactly the correct length.
649
650 @item
651 In BINARY mode, the data file is treated as a series of
652 variable-length binary records.  LRECL may be specified, but its value
653 is ignored.  The data for each record is both preceded and followed by
654 a 32-bit signed integer in little-endian byte order that specifies the
655 length of the record.  (This redundancy permits records in these
656 files to be efficiently read in reverse order, although @pspp{} always
657 reads them in forward order.)  The length does not include either
658 integer.
659
660 @item
661 Mode 360 reads and writes files in formats first used for tapes in the
662 1960s on IBM mainframe operating systems and still supported today by
663 the modern successors of those operating systems.  For more
664 information, see @cite{OS/400 Tape and Diskette Device Programming},
665 available on IBM's website.
666
667 Alphanumeric data in mode 360 files are encoded in EBCDIC.  @pspp{}
668 translates EBCDIC to or from the host's native format as necessary on
669 input or output, using an ASCII/EBCDIC translation that is one-to-one,
670 so that a ``round trip'' from ASCII to EBCDIC back to ASCII, or vice
671 versa, always yields exactly the original data.
672
673 The @subcmd{RECFORM} subcommand is required in mode 360.  The precise file
674 format depends on its setting:
675
676 @table @asis
677 @item F
678 @itemx FIXED
679 This record format is equivalent to IMAGE mode, except for EBCDIC
680 translation.
681
682 IBM documentation calls this @code{*F} (fixed-length, deblocked)
683 format.
684
685 @item V
686 @itemx VARIABLE
687 The file comprises a sequence of zero or more variable-length blocks.
688 Each block begins with a 4-byte @dfn{block descriptor word} (BDW).
689 The first two bytes of the BDW are an unsigned integer in big-endian
690 byte order that specifies the length of the block, including the BDW
691 itself.  The other two bytes of the BDW are ignored on input and
692 written as zeros on output.
693
694 Following the BDW, the remainder of each block is a sequence of one or
695 more variable-length records, each of which in turn begins with a
696 4-byte @dfn{record descriptor word} (RDW) that has the same format as
697 the BDW.  Following the RDW, the remainder of each record is the
698 record data.
699
700 The maximum length of a record in VARIABLE mode is 65,527 bytes:
701 65,535 bytes (the maximum value of a 16-bit unsigned integer), minus 4
702 bytes for the BDW, minus 4 bytes for the RDW.
703
704 In mode VARIABLE, LRECL specifies a maximum, not a fixed, record
705 length, in bytes.  The default is 8,192.
706
707 IBM documentation calls this @code{*VB} (variable-length, blocked,
708 unspanned) format.
709
710 @item VS
711 @itemx SPANNED
712 The file format is like that of VARIABLE mode, except that logical
713 records may be split among multiple physical records (called
714 @dfn{segments}) or blocks.  In SPANNED mode, the third byte of each
715 RDW is called the segment control character (SCC).  Odd SCC values
716 cause the segment to be appended to a record buffer maintained in
717 memory; even values also append the segment and then flush its
718 contents to the input procedure.  Canonically, SCC value 0 designates
719 a record not spanned among multiple segments, and values 1 through 3
720 designate the first segment, the last segment, or an intermediate
721 segment, respectively, within a multi-segment record.  The record
722 buffer is also flushed at end of file regardless of the final record's
723 SCC.
724
725 The maximum length of a logical record in VARIABLE mode is limited
726 only by memory available to @pspp{}.  Segments are limited to 65,527
727 bytes, as in VARIABLE mode.
728
729 This format is similar to what IBM documentation call @code{*VS}
730 (variable-length, deblocked, spanned) format.
731 @end table
732
733 In mode 360, fields of type A that extend beyond the end of a record
734 read from disk are padded with spaces in the host's native character
735 set, which are then translated from EBCDIC to the native character
736 set.  Thus, when the host's native character set is based on ASCII,
737 these fields are effectively padded with character @code{X'80'}.  This
738 wart is implemented for compatibility.
739 @end itemize
740
741 The @subcmd{NAME} subcommand specifies the name of the file associated with the
742 handle.  It is required in all modes but SCRATCH mode, in which its
743 use is forbidden.
744
745 The ENCODING subcommand specifies the encoding of text in the file.
746 For reading text files in CHARACTER mode, all of the forms described
747 for ENCODING on the INSERT command are supported (@pxref{INSERT}).
748 For reading in other file-based modes, encoding autodetection is not
749 supported; if the specified encoding requests autodetection then the
750 default encoding will be used.  This is also true when a file handle
751 is used for writing a file in any mode.
752
753 @node INPUT PROGRAM
754 @section INPUT PROGRAM
755 @vindex INPUT PROGRAM
756
757 @display
758 INPUT PROGRAM.
759 @dots{} input commands @dots{}
760 END INPUT PROGRAM.
761 @end display
762
763 @cmd{INPUT PROGRAM}@dots{}@cmd{END INPUT PROGRAM} specifies a
764 complex input program.  By placing data input commands within @cmd{INPUT
765 PROGRAM}, @pspp{} programs can take advantage of more complex file
766 structures than available with only @cmd{DATA LIST}.
767
768 The first sort of extended input program is to simply put multiple @cmd{DATA
769 LIST} commands within the @cmd{INPUT PROGRAM}.  This will cause all of
770 the data
771 files to be read in parallel.  Input will stop when end of file is
772 reached on any of the data files.
773
774 Transformations, such as conditional and looping constructs, can also be
775 included within @cmd{INPUT PROGRAM}.  These can be used to combine input
776 from several data files in more complex ways.  However, input will still
777 stop when end of file is reached on any of the data files.
778
779 To prevent @cmd{INPUT PROGRAM} from terminating at the first end of
780 file, use
781 the @subcmd{END} subcommand on @cmd{DATA LIST}.  This subcommand takes a
782 variable name,
783 which should be a numeric scratch variable (@pxref{Scratch Variables}).
784 (It need not be a scratch variable but otherwise the results can be
785 surprising.)  The value of this variable is set to 0 when reading the
786 data file, or 1 when end of file is encountered.
787
788 Two additional commands are useful in conjunction with @cmd{INPUT PROGRAM}.
789 @cmd{END CASE} is the first.  Normally each loop through the
790 @cmd{INPUT PROGRAM}
791 structure produces one case.  @cmd{END CASE} controls exactly
792 when cases are output.  When @cmd{END CASE} is used, looping from the end of
793 @cmd{INPUT PROGRAM} to the beginning does not cause a case to be output.
794
795 @cmd{END FILE} is the second.  When the @subcmd{END} subcommand is used on @cmd{DATA
796 LIST}, there is no way for the @cmd{INPUT PROGRAM} construct to stop
797 looping,
798 so an infinite loop results.  @cmd{END FILE}, when executed,
799 stops the flow of input data and passes out of the @cmd{INPUT PROGRAM}
800 structure.
801
802 @cmd{INPUT PROGRAM} must contain at least one @cmd{DATA LIST} or
803 @cmd{END FILE} command.
804
805 All this is very confusing.  A few examples should help to clarify.
806
807 @c If you change this example, change the regression test1 in
808 @c tests/command/input-program.sh to match.
809 @example
810 INPUT PROGRAM.
811         DATA LIST NOTABLE FILE='a.data'/X 1-10.
812         DATA LIST NOTABLE FILE='b.data'/Y 1-10.
813 END INPUT PROGRAM.
814 LIST.
815 @end example
816
817 The example above reads variable X from file @file{a.data} and variable
818 Y from file @file{b.data}.  If one file is shorter than the other then
819 the extra data in the longer file is ignored.
820
821 @c If you change this example, change the regression test2 in
822 @c tests/command/input-program.sh to match.
823 @example
824 INPUT PROGRAM.
825         NUMERIC #A #B.
826         
827         DO IF NOT #A.
828                 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
829         END IF.
830         DO IF NOT #B.
831                 DATA LIST NOTABLE END=#B FILE='b.data'/Y 1-10.
832         END IF.
833         DO IF #A AND #B.
834                 END FILE.
835         END IF.
836         END CASE.
837 END INPUT PROGRAM.
838 LIST.
839 @end example
840
841 The above example reads variable X from @file{a.data} and variable Y from
842 @file{b.data}.  If one file is shorter than the other then the missing
843 field is set to the system-missing value alongside the present value for
844 the remaining length of the longer file.
845
846 @c If you change this example, change the regression test3 in
847 @c tests/command/input-program.sh to match.
848 @example
849 INPUT PROGRAM.
850         NUMERIC #A #B.
851
852         DO IF #A.
853                 DATA LIST NOTABLE END=#B FILE='b.data'/X 1-10.
854                 DO IF #B.
855                         END FILE.
856                 ELSE.
857                         END CASE.
858                 END IF.
859         ELSE.
860                 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
861                 DO IF NOT #A.
862                         END CASE.
863                 END IF.
864         END IF.
865 END INPUT PROGRAM.
866 LIST.
867 @end example
868
869 The above example reads data from file @file{a.data}, then from
870 @file{b.data}, and concatenates them into a single active dataset.
871
872 @c If you change this example, change the regression test4 in
873 @c tests/command/input-program.sh to match.
874 @example
875 INPUT PROGRAM.
876         NUMERIC #EOF.
877
878         LOOP IF NOT #EOF.
879                 DATA LIST NOTABLE END=#EOF FILE='a.data'/X 1-10.
880                 DO IF NOT #EOF.
881                         END CASE.
882                 END IF.
883         END LOOP.
884
885         COMPUTE #EOF = 0.
886         LOOP IF NOT #EOF.
887                 DATA LIST NOTABLE END=#EOF FILE='b.data'/X 1-10.
888                 DO IF NOT #EOF.
889                         END CASE.
890                 END IF.
891         END LOOP.
892
893         END FILE.
894 END INPUT PROGRAM.
895 LIST.
896 @end example
897
898 The above example does the same thing as the previous example, in a
899 different way.
900
901 @c If you change this example, make similar changes to the regression
902 @c test5 in tests/command/input-program.sh.
903 @example
904 INPUT PROGRAM.
905         LOOP #I=1 TO 50.
906                 COMPUTE X=UNIFORM(10).
907                 END CASE.
908         END LOOP.
909         END FILE.
910 END INPUT PROGRAM.
911 LIST/FORMAT=NUMBERED.
912 @end example
913
914 The above example causes an active dataset to be created consisting of 50
915 random variates between 0 and 10.
916
917 @node LIST
918 @section LIST
919 @vindex LIST
920
921 @display
922 LIST
923         /VARIABLES=@var{var_list}
924         /CASES=FROM @var{start_index} TO @var{end_index} BY @var{incr_index}
925         /FORMAT=@{UNNUMBERED,NUMBERED@} @{WRAP,SINGLE@}
926 @end display
927
928 The @cmd{LIST} procedure prints the values of specified variables to the
929 listing file.
930
931 The @subcmd{VARIABLES} subcommand specifies the variables whose values are to be
932 printed.  Keyword VARIABLES is optional.  If @subcmd{VARIABLES} subcommand is not
933 specified then all variables in the active dataset are printed.
934
935 The @subcmd{CASES} subcommand can be used to specify a subset of cases to be
936 printed.  Specify @subcmd{FROM} and the case number of the first case to print,
937 @subcmd{TO} and the case number of the last case to print, and @subcmd{BY} and the number
938 of cases to advance between printing cases, or any subset of those
939 settings.  If @subcmd{CASES} is not specified then all cases are printed.
940
941 The @subcmd{FORMAT} subcommand can be used to change the output format.  @subcmd{NUMBERED}
942 will print case numbers along with each case; @subcmd{UNNUMBERED}, the default,
943 causes the case numbers to be omitted.  The @subcmd{WRAP} and @subcmd{SINGLE} settings are
944 currently not used.
945
946 Case numbers start from 1.  They are counted after all transformations
947 have been considered.
948
949 @cmd{LIST} is a procedure.  It causes the data to be read.
950
951 @node NEW FILE
952 @section NEW FILE
953 @vindex NEW FILE
954
955 @display
956 NEW FILE.
957 @end display
958
959 @cmd{NEW FILE} command clears the dictionary and data from the current
960 active dataset.
961
962 @node MATRIX DATA
963 @section MATRIX DATA
964 @vindex MATRIX DATA
965
966 @display
967 MATRIX DATA
968         VARIABLES = @var{columns}
969         [eFILE='@var{file_name}'| INLINE @}
970         [/FORMAT= [@{LIST | FREE@}]
971                   [@{UPPER | LOWER | FULL@}]
972                   [@{DIAGONAL | NODIAGONAL@}]]
973         [/SPLIT= @var{split_variables}].
974 @end display
975
976 The @cmd{MATRIX DATA} command is used to input data in the form of matrices
977 which can subsequently be used by other commands.  If the
978 @subcmd{FILE} is omitted or takes the value @samp{INLINE} then the command
979 should immediately followed by @cmd{BEGIN DATA}, @xref{BEGIN DATA}.
980
981 There is one mandatory subcommand, @i{viz:} @subcmd{VARIABLES}, which defines
982 the @var{columns} of the matrix.
983 Normally, the @var{columns} should include an item called @samp{ROWTYPE_}.
984 The @samp{ROWTYPE_} column is used to specify the purpose of a row in the
985 matrix.
986
987 @example
988 matrix data
989     variables = rowtype_ var01 TO var08.
990
991 begin data.
992 mean  24.3  5.4  69.7  20.1  13.4  2.7  27.9  3.7
993 sd    5.7   1.5  23.5  5.8   2.8   4.5  5.4   1.5
994 n     92    92   92    92    92    92   92    92
995 corr 1.00
996 corr .18  1.00
997 corr -.22  -.17  1.00
998 corr .36  .31  -.14  1.00
999 corr .27  .16  -.12  .22  1.00
1000 corr .33  .15  -.17  .24  .21  1.00
1001 corr .50  .29  -.20  .32  .12  .38  1.00
1002 corr .17  .29  -.05  .20  .27  .20  .04  1.00
1003 end data.
1004 @end example
1005
1006 In the above example, the first three rows have ROWTYPE_ values of
1007 @samp{mean}, @samp{sd}, and @samp{n}.  These indicate that the rows
1008 contain mean values, standard deviations and counts, respectively.
1009 All subsequent rows have a ROWTYPE_ of @samp{corr} which indicates
1010 that the values are correlation coefficients.
1011
1012 Note that in this example, the upper right values of the @samp{corr}
1013 values are blank, and in each case, the rightmost value is unity.
1014 This is because, the
1015 @subcmd{FORMAT} subcommand defaults to @samp{LOWER DIAGONAL},
1016 which indicates that only the lower triangle is provided in the data.
1017 The opposite triangle is automatically inferred.  One could instead
1018 specify the upper triangle as follows:
1019
1020
1021 @example
1022 matrix data
1023     variables = rowtype_ var01 TO var08
1024     /format = upper nodiagonal.
1025
1026 begin data.
1027 mean  24.3 5.4  69.7  20.1  13.4  2.7  27.9  3.7
1028 sd    5.7  1.5  23.5  5.8   2.8   4.5  5.4   1.5
1029 n     92    92   92    92    92    92   92    92
1030 corr         .17  .50  -.33  .27  .36  -.22  .18
1031 corr               .29  .29  -.20  .32  .12  .38
1032 corr                    .05  .20  -.15  .16  .21
1033 corr                         .20  .32  -.17  .12
1034 corr                              .27  .12  -.24
1035 corr                                  -.20  -.38
1036 corr                                         .04
1037 end data.
1038 @end example
1039
1040 In this example the @samp{NODIAGONAL} keyword is used.  Accordingly
1041 the diagonal values of the matrix are omitted.  This implies that
1042 there is one less @samp{corr} line than there are variables.
1043 If the @samp{FULL} option is passed to the @subcmd{FORMAT} subcommand,
1044 then all the matrix elements must be provided, including the diagonal
1045 elements.
1046
1047 In the preceding examples, each matrix row has been specified on a
1048 single line.  If you pass the keyword @var{FREE} to @subcmd{FORMAT}
1049 then the data may be data for several matrix rows may be specified on
1050 the same line, or a single row may be split across lines.
1051
1052 The @subcmd{SPLIT} is used to indicate that variables are to be
1053 considered as split variables.  For example, the following
1054 defines two matrices using the variable @samp{S1} to distinguish
1055 between them.
1056
1057 @example
1058 matrix data
1059     variables = s1 rowtype_  var01 TO var04
1060     /split = s1
1061     /format = full diagonal.
1062
1063 begin data
1064 0 mean 34 35 36 37
1065 0 sd   22 11 55 66
1066 0 n    99 98 99 92
1067 0 corr 1 9 8 7
1068 0 corr 9 1 6 5
1069 0 corr 8 6 1 4
1070 0 corr 7 5 4 1
1071 1 mean 44 45 34 39
1072 1 sd   23 15 51 46
1073 1 n    98 34 87 23
1074 1 corr 1 2 3 4
1075 1 corr 2 1 5 6
1076 1 corr 3 5 1 7
1077 1 corr 4 6 7 1
1078 end data.
1079 @end example
1080
1081 @node PRINT
1082 @section PRINT
1083 @vindex PRINT
1084
1085 @display
1086 PRINT 
1087         [OUTFILE='@var{file_name}']
1088         [RECORDS=@var{n_lines}]
1089         [@{NOTABLE,TABLE@}]
1090         [ENCODING='@var{encoding}']
1091         [/[@var{line_no}] @var{arg}@dots{}]
1092
1093 @var{arg} takes one of the following forms:
1094         '@var{string}' [@var{start}]
1095         @var{var_list} @var{start}-@var{end} [@var{type_spec}]
1096         @var{var_list} (@var{fortran_spec})
1097         @var{var_list} *
1098 @end display
1099
1100 The @cmd{PRINT} transformation writes variable data to the listing
1101 file or an output file.  @cmd{PRINT} is executed when a procedure
1102 causes the data to be read.  Follow @cmd{PRINT} by @cmd{EXECUTE} to
1103 print variable data without invoking a procedure (@pxref{EXECUTE}).
1104
1105 All @cmd{PRINT} subcommands are optional.  If no strings or variables
1106 are specified, @cmd{PRINT} outputs a single blank line.
1107
1108 The @subcmd{OUTFILE} subcommand specifies the file to receive the output.  The
1109 file may be a file name as a string or a file handle (@pxref{File
1110 Handles}).  If @subcmd{OUTFILE} is not present then output will be sent to
1111 @pspp{}'s output listing file.  When @subcmd{OUTFILE} is present, a space is
1112 inserted at beginning of each output line, even lines that otherwise
1113 would be blank.
1114
1115 The @subcmd{ENCODING} subcommand may only be used if the
1116 @subcmd{OUTFILE} subcommand is also used.  It specifies the character
1117 encoding of the file.  @xref{INSERT}, for information on supported
1118 encodings.
1119
1120 The @subcmd{RECORDS} subcommand specifies the number of lines to be output.  The
1121 number of lines may optionally be surrounded by parentheses.
1122
1123 @subcmd{TABLE} will cause the @cmd{PRINT} command to output a table to the listing file
1124 that describes what it will print to the output file.  @subcmd{NOTABLE}, the
1125 default, suppresses this output table.
1126
1127 Introduce the strings and variables to be printed with a slash
1128 (@samp{/}).  Optionally, the slash may be followed by a number
1129 indicating which output line will be specified.  In the absence of this
1130 line number, the next line number will be specified.  Multiple lines may
1131 be specified using multiple slashes with the intended output for a line
1132 following its respective slash.
1133
1134 Literal strings may be printed.  Specify the string itself.
1135 Optionally the string may be followed by a column number, specifying
1136 the column on the line where the string should start.  Otherwise, the
1137 string will be printed at the current position on the line.
1138
1139 Variables to be printed can be specified in the same ways as available
1140 for @cmd{DATA LIST FIXED} (@pxref{DATA LIST FIXED}).  In addition, a
1141 variable
1142 list may be followed by an asterisk (@samp{*}), which indicates that the
1143 variables should be printed in their dictionary print formats, separated
1144 by spaces.  A variable list followed by a slash or the end of command
1145 will be interpreted the same way.
1146
1147 If a FORTRAN type specification is used to move backwards on the current
1148 line, then text is written at that point on the line, the line will be
1149 truncated to that length, although additional text being added will
1150 again extend the line to that length.
1151
1152 @node PRINT EJECT
1153 @section PRINT EJECT
1154 @vindex PRINT EJECT
1155
1156 @display
1157 PRINT EJECT 
1158         OUTFILE='@var{file_name}'
1159         RECORDS=@var{n_lines}
1160         @{NOTABLE,TABLE@}
1161         /[@var{line_no}] @var{arg}@dots{}
1162
1163 @var{arg} takes one of the following forms:
1164         '@var{string}' [@var{start}-@var{end}]
1165         @var{var_list} @var{start}-@var{end} [@var{type_spec}]
1166         @var{var_list} (@var{fortran_spec})
1167         @var{var_list} *
1168 @end display
1169
1170 @cmd{PRINT EJECT} advances to the beginning of a new output page in
1171 the listing file or output file.  It can also output data in the same
1172 way as @cmd{PRINT}.
1173
1174 All @cmd{PRINT EJECT} subcommands are optional.
1175
1176 Without @subcmd{OUTFILE}, @cmd{PRINT EJECT} ejects the current page in
1177 the listing file, then it produces other output, if any is specified.
1178
1179 With @subcmd{OUTFILE}, @cmd{PRINT EJECT} writes its output to the specified file.
1180 The first line of output is written with @samp{1} inserted in the
1181 first column.  Commonly, this is the only line of output.  If
1182 additional lines of output are specified, these additional lines are
1183 written with a space inserted in the first column, as with @subcmd{PRINT}.
1184
1185 @xref{PRINT}, for more information on syntax and usage.
1186
1187 @node PRINT SPACE
1188 @section PRINT SPACE
1189 @vindex PRINT SPACE
1190
1191 @display
1192 PRINT SPACE [OUTFILE='file_name'] [ENCODING='@var{encoding}'] [n_lines].
1193 @end display
1194
1195 @cmd{PRINT SPACE} prints one or more blank lines to an output file.
1196
1197 The @subcmd{OUTFILE} subcommand is optional.  It may be used to direct output to
1198 a file specified by file name as a string or file handle (@pxref{File
1199 Handles}).  If OUTFILE is not specified then output will be directed to
1200 the listing file.
1201
1202 The @subcmd{ENCODING} subcommand may only be used if @subcmd{OUTFILE}
1203 is also used.  It specifies the character encoding of the file.
1204 @xref{INSERT}, for information on supported encodings.
1205
1206 n_lines is also optional.  If present, it is an expression
1207 (@pxref{Expressions}) specifying the number of blank lines to be
1208 printed.  The expression must evaluate to a nonnegative value.
1209
1210 @node REREAD
1211 @section REREAD
1212 @vindex REREAD
1213
1214 @display
1215 REREAD [FILE=handle] [COLUMN=column] [ENCODING='@var{encoding}'].
1216 @end display
1217
1218 The @cmd{REREAD} transformation allows the previous input line in a
1219 data file
1220 already processed by @cmd{DATA LIST} or another input command to be re-read
1221 for further processing.
1222
1223 The @subcmd{FILE} subcommand, which is optional, is used to specify the file to
1224 have its line re-read.  The file must be specified as the name of a file
1225 handle (@pxref{File Handles}).  If FILE is not specified then the last
1226 file specified on @cmd{DATA LIST} will be assumed (last file specified
1227 lexically, not in terms of flow-of-control).
1228
1229 By default, the line re-read is re-read in its entirety.  With the
1230 @subcmd{COLUMN} subcommand, a prefix of the line can be exempted from
1231 re-reading.  Specify an expression (@pxref{Expressions}) evaluating to
1232 the first column that should be included in the re-read line.  Columns
1233 are numbered from 1 at the left margin.
1234
1235 The @subcmd{ENCODING} subcommand may only be used if the @subcmd{FILE}
1236 subcommand is also used.  It specifies the character encoding of the
1237 file.   @xref{INSERT}, for information on supported encodings.
1238
1239 Issuing @code{REREAD} multiple times will not back up in the data
1240 file.  Instead, it will re-read the same line multiple times.
1241
1242 @node REPEATING DATA
1243 @section REPEATING DATA
1244 @vindex REPEATING DATA
1245
1246 @display
1247 REPEATING DATA
1248         /STARTS=@var{start}-@var{end}
1249         /OCCURS=@var{n_occurs}
1250         /FILE='@var{file_name}'
1251         /LENGTH=@var{length}
1252         /CONTINUED[=@var{cont_start}-@var{cont_end}]
1253         /ID=@var{id_start}-@var{id_end}=@var{id_var}
1254         /@{TABLE,NOTABLE@}
1255         /DATA=@var{var_spec}@dots{}
1256
1257 where each @var{var_spec} takes one of the forms
1258         @var{var_list} @var{start}-@var{end} [@var{type_spec}]
1259         @var{var_list} (@var{fortran_spec})
1260 @end display
1261
1262 @cmd{REPEATING DATA} parses groups of data repeating in
1263 a uniform format, possibly with several groups on a single line.  Each
1264 group of data corresponds with one case.  @cmd{REPEATING DATA} may only be
1265 used within an @cmd{INPUT PROGRAM} structure (@pxref{INPUT PROGRAM}).
1266 When used with @cmd{DATA LIST}, it
1267 can be used to parse groups of cases that share a subset of variables
1268 but differ in their other data.
1269
1270 The @subcmd{STARTS} subcommand is required.  Specify a range of columns, using
1271 literal numbers or numeric variable names.  This range specifies the
1272 columns on the first line that are used to contain groups of data.  The
1273 ending column is optional.  If it is not specified, then the record
1274 width of the input file is used.  For the inline file (@pxref{BEGIN
1275 DATA}) this is 80 columns; for a file with fixed record widths it is the
1276 record width; for other files it is 1024 characters by default.
1277
1278 The @subcmd{OCCURS} subcommand is required.  It must be a number or the name of a
1279 numeric variable.  Its value is the number of groups present in the
1280 current record.
1281
1282 The @subcmd{DATA} subcommand is required.  It must be the last subcommand
1283 specified.  It is used to specify the data present within each repeating
1284 group.  Column numbers are specified relative to the beginning of a
1285 group at column 1.  Data is specified in the same way as with @cmd{DATA LIST
1286 FIXED} (@pxref{DATA LIST FIXED}).
1287
1288 All other subcommands are optional.
1289
1290 FILE specifies the file to read, either a file name as a string or a
1291 file handle (@pxref{File Handles}).  If FILE is not present then the
1292 default is the last file handle used on @cmd{DATA LIST} (lexically, not in
1293 terms of flow of control).
1294
1295 By default @cmd{REPEATING DATA} will output a table describing how it will
1296 parse the input data.  Specifying @subcmd{NOTABLE} will disable this behavior;
1297 specifying TABLE will explicitly enable it.
1298
1299 The @subcmd{LENGTH} subcommand specifies the length in characters of each group.
1300 If it is not present then length is inferred from the @subcmd{DATA} subcommand.
1301 LENGTH can be a number or a variable name.
1302
1303 Normally all the data groups are expected to be present on a single
1304 line.  Use the @subcmd{CONTINUED} command to indicate that data can be continued
1305 onto additional lines.  If data on continuation lines starts at the left
1306 margin and continues through the entire field width, no column
1307 specifications are necessary on @subcmd{CONTINUED}.  Otherwise, specify the
1308 possible range of columns in the same way as on STARTS.
1309
1310 When data groups are continued from line to line, it is easy
1311 for cases to get out of sync through careless hand editing.  The
1312 @subcmd{ID} subcommand allows a case identifier to be present on each line of
1313 repeating data groups.  @cmd{REPEATING DATA} will check for the same
1314 identifier on each line and report mismatches.  Specify the range of
1315 columns that the identifier will occupy, followed by an equals sign
1316 (@samp{=}) and the identifier variable name.  The variable must already
1317 have been declared with @cmd{NUMERIC} or another command.
1318
1319 @cmd{REPEATING DATA} should be the last command given within an
1320 @cmd{INPUT PROGRAM}.  It should not be enclosed within a @cmd{LOOP}
1321 structure (@pxref{LOOP}).  Use @cmd{DATA LIST} before, not after,
1322 @cmd{REPEATING DATA}.
1323
1324 @node WRITE
1325 @section WRITE
1326 @vindex WRITE
1327
1328 @display
1329 WRITE 
1330         OUTFILE='@var{file_name}'
1331         RECORDS=@var{n_lines}
1332         @{NOTABLE,TABLE@}
1333         /[@var{line_no}] @var{arg}@dots{}
1334
1335 @var{arg} takes one of the following forms:
1336         '@var{string}' [@var{start}-@var{end}]
1337         @var{var_list} @var{start}-@var{end} [@var{type_spec}]
1338         @var{var_list} (@var{fortran_spec})
1339         @var{var_list} *
1340 @end display
1341
1342 @code{WRITE} writes text or binary data to an output file.  
1343
1344 @xref{PRINT}, for more information on syntax and usage.  @cmd{PRINT}
1345 and @cmd{WRITE} differ in only a few ways:
1346
1347 @itemize @bullet
1348 @item
1349 @cmd{WRITE} uses write formats by default, whereas @cmd{PRINT} uses
1350 print formats.
1351
1352 @item
1353 @cmd{PRINT} inserts a space between variables unless a format is
1354 explicitly specified, but @cmd{WRITE} never inserts space between
1355 variables in output.
1356
1357 @item
1358 @cmd{PRINT} inserts a space at the beginning of each line that it
1359 writes to an output file (and @cmd{PRINT EJECT} inserts @samp{1} at
1360 the beginning of each line that should begin a new page), but
1361 @cmd{WRITE} does not.
1362
1363 @item
1364 @cmd{PRINT} outputs the system-missing value according to its
1365 specified output format, whereas @cmd{WRITE} outputs the
1366 system-missing value as a field filled with spaces.  Binary formats
1367 are an exception.
1368 @end itemize