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