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