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