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".
10 @c (modify-syntax-entry ?_ "w")
11 @c (modify-syntax-entry ?' "'")
12 @c (modify-syntax-entry ?@ "'")
15 @node Data Input and Output
16 @chapter Data Input and Output
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.
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}.)
35 These commands tell @pspp{} how to read data, but the data will not
36 actually be read until a procedure is executed.
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.
64 @cindex Embedding data in syntax files
65 @cindex Data, embedding in syntax files
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:
85 @node CLOSE FILE HANDLE
86 @section CLOSE FILE HANDLE
89 CLOSE FILE HANDLE @var{handle_name}.
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.
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.
101 @cmd{CLOSE FILE HANDLE} is a @pspp{} extension.
103 @node DATAFILE ATTRIBUTE
104 @section DATAFILE ATTRIBUTE
105 @vindex 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{}
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.
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.
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.
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.
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.
146 @cmd{DATAFILE ATTRIBUTE} takes effect immediately. It is not affected
147 by conditional and looping structures such as @cmd{DO IF} or
151 @section DATASET commands
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@}.
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
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.
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.
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.
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}).
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.
202 @vindex DATASET DISPLAY
203 The DATASET DISPLAY command lists all the currently defined datasets.
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:
212 Do not change how the window is displayed. This is the default for
213 DATASET NAME and DATASET ACTIVATE.
216 Raise the dataset's window to the top. Make it the default dataset
220 Display the window ``minimized'' to an icon. Prefer other datasets
221 for running syntax. This is the default for DATASET COPY and DATASET
225 Hide the dataset's window. Prefer other datasets for running syntax.
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
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.
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
247 Each form of @cmd{DATA LIST} is described in detail below.
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
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.
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
270 [FILE='@var{file_name}' [ENCODING='@var{encoding}']]
271 [RECORDS=@var{record_count}]
273 [SKIP=@var{record_count}]
274 /[line_no] @var{var_spec}@dots{}
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})
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.
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.
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.
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}.
300 The @subcmd{END} subcommand is only useful in conjunction with @cmd{INPUT
301 PROGRAM}. @xref{INPUT PROGRAM}, for details.
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.
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.
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.
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
320 Variables}). There are two ways to specify the location of the variable
321 on the line: columnar style and FORTRAN style.
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.)
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)}.
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.
342 Changing the variable format and adding implied decimal places can be
343 done together; for instance, @samp{(N,5)}.
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.
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.
355 Implied decimal places also exist in FORTRAN style. A format
356 specification with @var{d} decimal places also has @var{d} implied
359 In addition to the standard format specifiers (@pxref{Input and Output
360 Formats}), FORTRAN style defines some extensions:
364 Advance the current column on this line by one character position.
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.
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.
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
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.
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.
390 * DATA LIST FIXED Examples:: Examples of DATA LIST FIXED.
393 @node DATA LIST FIXED Examples
394 @unnumberedsubsubsec Examples
399 DATA LIST TABLE /NAME 1-10 (A) INFO1 TO INFO3 12-17 (1).
408 Defines the following variables:
412 @code{NAME}, a 10-character-wide string variable, in columns 1
416 @code{INFO1}, a numeric variable, in columns 12 through 13.
419 @code{INFO2}, a numeric variable, in columns 14 through 15.
422 @code{INFO3}, a numeric variable, in columns 16 through 17.
425 The @code{BEGIN DATA}/@code{END DATA} commands cause three cases to be
429 Case NAME INFO1 INFO2 INFO3
430 1 John Smith 10 23 11
431 2 Bob Arnold 12 20 15
435 The @code{TABLE} keyword causes @pspp{} to print out a table
436 describing the four variables defined.
440 DAT LIS FIL="survey.dat"
441 /ID 1-5 NAME 7-36 (A) SURNAME 38-67 (A) MINITIAL 69 (A)
446 Defines the following variables:
450 @code{ID}, a numeric variable, in columns 1-5 of the first record.
453 @code{NAME}, a 30-character string variable, in columns 7-36 of the
457 @code{SURNAME}, a 30-character string variable, in columns 38-67 of
461 @code{MINITIAL}, a 1-character string variable, in column 69 of
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
471 Cases are separated by a blank record.
473 Data is read from file @file{survey.dat} in the current directory.
475 This example shows keywords abbreviated to their first 3 letters.
480 @subsection DATA LIST FREE
481 @vindex DATA LIST FREE
485 [(@{TAB,'@var{c}'@}, @dots{})]
487 [FILE='@var{file_name}' [ENCODING='@var{encoding}']]
488 [SKIP=@var{record_cnt}]
489 /@var{var_spec}@dots{}
491 where each @var{var_spec} takes one of the forms
492 @var{var_list} [(@var{type_spec})]
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.
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
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.
517 The @subcmd{NOTABLE} and @subcmd{TABLE} subcommands are as in @cmd{DATA LIST FIXED} above.
518 @subcmd{NOTABLE} is the default.
520 The @subcmd{FILE}, @subcmd{SKIP}, and @subcmd{ENCODING} subcommands
521 are as in @cmd{DATA LIST FIXED} above.
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.
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}.
532 Specified field widths are ignored on input, although all normal limits
533 on field width apply, but they are honored on output.
536 @subsection DATA LIST LIST
537 @vindex DATA LIST LIST
541 [(@{TAB,'@var{c}'@}, @dots{})]
543 [FILE='@var{file_name}' [ENCODING='@var{encoding}']]
544 [SKIP=@var{record_count}]
545 /@var{var_spec}@dots{}
547 where each @var{var_spec} takes one of the forms
548 @var{var_list} [(@var{type_spec})]
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.
566 @cmd{END CASE} is used only within @cmd{INPUT PROGRAM} to output the
567 current case. @xref{INPUT PROGRAM}, for details.
577 @cmd{END FILE} is used only within @cmd{INPUT PROGRAM} to terminate
578 the current input program. @xref{INPUT PROGRAM}.
586 FILE HANDLE @var{handle_name}
587 /NAME='@var{file_name}
590 /TABWIDTH=@var{tab_width}
591 [ENCODING='@var{encoding}']
593 For binary files in native encoding with fixed-length records:
594 FILE HANDLE @var{handle_name}
595 /NAME='@var{file_name}'
597 [/LRECL=@var{rec_len}]
598 [ENCODING='@var{encoding}']
600 For binary files in native encoding with variable-length records:
601 FILE HANDLE @var{handle_name}
602 /NAME='@var{file_name}'
604 [/LRECL=@var{rec_len}]
605 [ENCODING='@var{encoding}']
607 For binary files encoded in EBCDIC:
608 FILE HANDLE @var{handle_name}
609 /NAME='@var{file_name}'
611 /RECFORM=@{FIXED,VARIABLE,SPANNED@}
612 [/LRECL=@var{rec_len}]
613 [ENCODING='@var{encoding}']
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
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}).
632 The effect and syntax of @cmd{FILE HANDLE} depends on the selected MODE:
636 In CHARACTER mode, the default, the data file is read as a text file.
637 Each text line is read as one record.
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.
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.
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.
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
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.
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.
682 The @subcmd{RECFORM} subcommand is required in mode 360. The precise file
683 format depends on its setting:
688 This record format is equivalent to IMAGE mode, except for EBCDIC
691 IBM documentation calls this @code{*F} (fixed-length, deblocked)
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.
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
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.
713 In mode VARIABLE, LRECL specifies a maximum, not a fixed, record
714 length, in bytes. The default is 8,192.
716 IBM documentation calls this @code{*VB} (variable-length, blocked,
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
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.
738 This format is similar to what IBM documentation call @code{*VS}
739 (variable-length, deblocked, spanned) format.
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.
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
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.
763 @section INPUT PROGRAM
764 @vindex INPUT PROGRAM
768 @dots{} input commands @dots{}
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}.
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
780 files to be read in parallel. Input will stop when end of file is
781 reached on any of the data files.
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.
788 To prevent @cmd{INPUT PROGRAM} from terminating at the first end of
790 the @subcmd{END} subcommand on @cmd{DATA LIST}. This subcommand takes a
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.
797 Two additional commands are useful in conjunction with @cmd{INPUT PROGRAM}.
798 @cmd{END CASE} is the first. Normally each loop through the
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.
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
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}
811 @cmd{INPUT PROGRAM} must contain at least one @cmd{DATA LIST} or
812 @cmd{END FILE} command.
814 All this is very confusing. A few examples should help to clarify.
816 @c If you change this example, change the regression test1 in
817 @c tests/command/input-program.sh to match.
820 DATA LIST NOTABLE FILE='a.data'/X 1-10.
821 DATA LIST NOTABLE FILE='b.data'/Y 1-10.
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.
830 @c If you change this example, change the regression test2 in
831 @c tests/command/input-program.sh to match.
837 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
840 DATA LIST NOTABLE END=#B FILE='b.data'/Y 1-10.
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.
855 @c If you change this example, change the regression test3 in
856 @c tests/command/input-program.sh to match.
862 DATA LIST NOTABLE END=#B FILE='b.data'/X 1-10.
869 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
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.
881 @c If you change this example, change the regression test4 in
882 @c tests/command/input-program.sh to match.
888 DATA LIST NOTABLE END=#EOF FILE='a.data'/X 1-10.
896 DATA LIST NOTABLE END=#EOF FILE='b.data'/X 1-10.
907 The above example does the same thing as the previous example, in a
910 @c If you change this example, make similar changes to the regression
911 @c test5 in tests/command/input-program.sh.
915 COMPUTE X=UNIFORM(10).
920 LIST/FORMAT=NUMBERED.
923 The above example causes an active dataset to be created consisting of 50
924 random variates between 0 and 10.
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@}
937 The @cmd{LIST} procedure prints the values of specified variables to the
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.
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.
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
955 Case numbers start from 1. They are counted after all transformations
956 have been considered.
958 @cmd{LIST} is a procedure. It causes the data to be read.
968 @cmd{NEW FILE} command clears the dictionary and data from the current
977 VARIABLES = @var{columns}
978 [FILE='@var{file_name}'| INLINE @}
979 [/FORMAT= [@{LIST | FREE@}]
980 [@{UPPER | LOWER | FULL@}]
981 [@{DIAGONAL | NODIAGONAL@}]]
983 [/SPLIT= @var{split_variables}].
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}.
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
999 variables = rowtype_ var01 TO var08.
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
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
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.
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:
1033 variables = rowtype_ var01 TO var08
1034 /format = upper nodiagonal.
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
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
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.
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}.
1069 variables = rowtype_ var01 TO var04
1070 /format = upper nodiagonal
1080 produces an effect identical to
1083 variables = rowtype_ var01 TO var04
1084 /format = upper nodiagonal
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
1103 variables = s1 rowtype_ var01 TO var04
1105 /format = full diagonal.
1131 [OUTFILE='@var{file_name}']
1132 [RECORDS=@var{n_lines}]
1134 [ENCODING='@var{encoding}']
1135 [/[@var{line_no}] @var{arg}@dots{}]
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})
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}).
1149 All @cmd{PRINT} subcommands are optional. If no strings or variables
1150 are specified, @cmd{PRINT} outputs a single blank line.
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
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
1164 The @subcmd{RECORDS} subcommand specifies the number of lines to be output. The
1165 number of lines may optionally be surrounded by parentheses.
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.
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.
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.
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
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.
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.
1197 @section PRINT EJECT
1202 OUTFILE='@var{file_name}'
1203 RECORDS=@var{n_lines}
1205 /[@var{line_no}] @var{arg}@dots{}
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})
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
1218 All @cmd{PRINT EJECT} subcommands are optional.
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.
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}.
1229 @xref{PRINT}, for more information on syntax and usage.
1232 @section PRINT SPACE
1236 PRINT SPACE [OUTFILE='file_name'] [ENCODING='@var{encoding}'] [n_lines].
1239 @cmd{PRINT SPACE} prints one or more blank lines to an output file.
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
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.
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.
1259 REREAD [FILE=handle] [COLUMN=column] [ENCODING='@var{encoding}'].
1262 The @cmd{REREAD} transformation allows the previous input line in a
1264 already processed by @cmd{DATA LIST} or another input command to be re-read
1265 for further processing.
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).
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.
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.
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.
1286 @node REPEATING DATA
1287 @section REPEATING DATA
1288 @vindex 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}
1299 /DATA=@var{var_spec}@dots{}
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})
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.
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.
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
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}).
1332 All other subcommands are optional.
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).
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.
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.
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.
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.
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}.
1374 OUTFILE='@var{file_name}'
1375 RECORDS=@var{n_lines}
1377 /[@var{line_no}] @var{arg}@dots{}
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})
1386 @code{WRITE} writes text or binary data to an output file.
1388 @xref{PRINT}, for more information on syntax and usage. @cmd{PRINT}
1389 and @cmd{WRITE} differ in only a few ways:
1393 @cmd{WRITE} uses write formats by default, whereas @cmd{PRINT} uses
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.
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.
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