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