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