1 @node Data Input and Output
2 @chapter Data Input and Output
9 Data are the focus of the PSPP language.
10 Each datum belongs to a @dfn{case} (also called an @dfn{observation}).
11 Each case represents an individual or ``experimental unit''.
12 For example, in the results of a survey, the names of the respondents,
13 their sex, age, etc.@: and their responses are all data and the data
14 pertaining to single respondent is a case.
16 the PSPP commands for defining variables and reading and writing data.
17 There are alternative commands to read data from predefined sources
18 such as system files or databases (@xref{GET, GET DATA}.)
21 These commands tell PSPP how to read data, but the data will not
22 actually be read until a procedure is executed.
26 * BEGIN DATA:: Embed data within a syntax file.
27 * CLOSE FILE HANDLE:: Close a file handle.
28 * DATAFILE ATTRIBUTE:: Set custom attributes on data files.
29 * DATASET:: Manage multiple datasets.
30 * DATA LIST:: Fundamental data reading command.
31 * END CASE:: Output the current case.
32 * END FILE:: Terminate the current input program.
33 * FILE HANDLE:: Support for special file formats.
34 * INPUT PROGRAM:: Support for complex input programs.
35 * LIST:: List cases in the active dataset.
36 * NEW FILE:: Clear the active dataset.
37 * PRINT:: Display values in print formats.
38 * PRINT EJECT:: Eject the current page then print.
39 * PRINT SPACE:: Print blank lines.
40 * REREAD:: Take another look at the previous input line.
41 * REPEATING DATA:: Multiple cases on a single line.
42 * WRITE:: Display values in write formats.
49 @cindex Embedding data in syntax files
50 @cindex Data, embedding in syntax files
58 @cmd{BEGIN DATA} and @cmd{END DATA} can be used to embed raw ASCII
59 data in a PSPP syntax file. @cmd{DATA LIST} or another input
60 procedure must be used before @cmd{BEGIN DATA} (@pxref{DATA LIST}).
61 @cmd{BEGIN DATA} and @cmd{END DATA} must be used together. @cmd{END
62 DATA} must appear by itself on a single line, with no leading
63 white space and exactly one space between the words @code{END} and
64 @code{DATA}, like this:
70 @node CLOSE FILE HANDLE
71 @section CLOSE FILE HANDLE
74 CLOSE FILE HANDLE handle_name.
77 @cmd{CLOSE FILE HANDLE} disassociates the name of a file handle with a
78 given file. The only specification is the name of the handle to close.
82 The file named INLINE, which represents data entered between @cmd{BEGIN
83 DATA} and @cmd{END DATA}, cannot be closed. Attempts to close it with
84 @cmd{CLOSE FILE HANDLE} have no effect.
86 @cmd{CLOSE FILE HANDLE} is a PSPP extension.
88 @node DATAFILE ATTRIBUTE
89 @section DATAFILE ATTRIBUTE
90 @vindex DATAFILE ATTRIBUTE
94 ATTRIBUTE=name('value') [name('value')]@dots{}
95 ATTRIBUTE=name@b{[}index@b{]}('value') [name@b{[}index@b{]}('value')]@dots{}
96 DELETE=name [name]@dots{}
97 DELETE=name@b{[}index@b{]} [name@b{[}index@b{]}]@dots{}
100 @cmd{DATAFILE ATTRIBUTE} adds, modifies, or removes user-defined
101 attributes associated with the active dataset. Custom data file
102 attributes are not interpreted by PSPP, but they are saved as part of
103 system files and may be used by other software that reads them.
105 Use the ATTRIBUTE subcommand to add or modify a custom data file
106 attribute. Specify the name of the attribute as an identifier
107 (@pxref{Tokens}), followed by the desired value, in parentheses, as a
108 quoted string. Attribute names that begin with @code{$} are reserved
109 for PSPP's internal use, and attribute names that begin with @code{@@}
110 or @code{$@@} are not displayed by most PSPP commands that display
111 other attributes. Other attribute names are not treated specially.
113 Attributes may also be organized into arrays. To assign to an array
114 element, add an integer array index enclosed in square brackets
115 (@code{[} and @code{]}) between the attribute name and value. Array
116 indexes start at 1, not 0. An attribute array that has a single
117 element (number 1) is not distinguished from a non-array attribute.
119 Use the DELETE subcommand to delete an attribute. Specify an
120 attribute name by itself to delete an entire attribute, including all
121 array elements for attribute arrays. Specify an attribute name
122 followed by an array index in square brackets to delete a single
123 element of an attribute array. In the latter case, all the array
124 elements numbered higher than the deleted element are shifted down,
125 filling the vacated position.
127 To associate custom attributes with particular variables, instead of
128 with the entire active dataset, use @cmd{VARIABLE ATTRIBUTE}
129 (@pxref{VARIABLE ATTRIBUTE}) instead.
131 @cmd{DATAFILE ATTRIBUTE} takes effect immediately. It is not affected
132 by conditional and looping structures such as @cmd{DO IF} or
136 @section DATASET commands
140 DATASET NAME name [WINDOW=@{ASIS,FRONT@}].
141 DATASET ACTIVATE name [WINDOW=@{ASIS,FRONT@}].
142 DATASET COPY name [WINDOW=@{MINIMIZED,HIDDEN,FRONT@}].
143 DATASET DECLARE name [WINDOW=@{MINIMIZED,HIDDEN,FRONT@}].
144 DATASET CLOSE @{name,*,ALL@}.
148 The @cmd{DATASET} commands simplify use of multiple datasets within a
149 PSPP session. They allow datasets to be created and destroyed. At
150 any given time, most PSPP commands work with a single dataset, called
154 The DATASET NAME command gives the active dataset the specified name, or
155 if it already had a name, it renames it. If another dataset already
156 had the given name, that dataset is deleted.
158 @vindex DATASET ACTIVATE
159 The DATASET ACTIVATE command selects the named dataset, which must
160 already exist, as the active dataset. Before switching the active
161 dataset, any pending transformations are executed, as if @cmd{EXECUTE}
162 had been specified. If the active dataset is unnamed before
163 switching, then it is deleted and becomes unavailable after switching.
166 The DATASET COPY command creates a new dataset with the specified
167 name, whose contents are a copy of the active dataset. Any pending
168 transformations are executed, as if @cmd{EXECUTE} had been specified,
169 before making the copy. If a dataset with the given name already
170 exists, it is replaced. If the name is the name of the active
171 dataset, then the active dataset becomes unnamed.
173 @vindex DATASET DECLARE
174 The DATASET DECLARE command creates a new dataset that is initially
175 ``empty,'' that is, it has no dictionary or data. If a dataset with
176 the given name already exists, this has no effect. The new dataset
177 can be used with commands that support output to a dataset,
178 e.g. AGGREGATE (@pxref{AGGREGATE}).
180 @vindex DATASET CLOSE
181 The DATASET CLOSE command deletes a dataset. If the active dataset is
182 specified by name, or if @samp{*} is specified, then the active
183 dataset becomes unnamed. If a different dataset is specified by name,
184 then it is deleted and becomes unavailable. Specifying ALL deletes
185 all datasets except for the active dataset, which becomes unnamed.
187 @vindex DATASET DISPLAY
188 The DATASET DISPLAY command lists all the currently defined datasets.
190 Many DATASET commands accept an optional WINDOW subcommand. In the
191 PSPPIRE GUI, the value given for this subcommand influences how the
192 dataset's window is displayed. Outside the GUI, the WINDOW subcommand
193 has no effect. The valid values are:
197 Do not change how the window is displayed. This is the default for
198 DATASET NAME and DATASET ACTIVATE.
201 Raise the dataset's window to the top. Make it the default dataset
205 Display the window ``minimized'' to an icon. Prefer other datasets
206 for running syntax. This is the default for DATASET COPY and DATASET
210 Hide the dataset's window. Prefer other datasets for running syntax.
216 @cindex reading data from a file
217 @cindex data, reading from a file
218 @cindex data, embedding in syntax files
219 @cindex embedding data in syntax files
221 Used to read text or binary data, @cmd{DATA LIST} is the most
222 fundamental data-reading command. Even the more sophisticated input
223 methods use @cmd{DATA LIST} commands as a building block.
224 Understanding @cmd{DATA LIST} is important to understanding how to use
225 PSPP to read your data files.
227 There are two major variants of @cmd{DATA LIST}, which are fixed
228 format and free format. In addition, free format has a minor variant,
229 list format, which is discussed in terms of its differences from vanilla
232 Each form of @cmd{DATA LIST} is described in detail below.
234 @xref{GET DATA}, for a command that offers a few enhancements over
235 DATA LIST and that may be substituted for DATA LIST in many
239 * DATA LIST FIXED:: Fixed columnar locations for data.
240 * DATA LIST FREE:: Any spacing you like.
241 * DATA LIST LIST:: Each case must be on a single line.
244 @node DATA LIST FIXED
245 @subsection DATA LIST FIXED
246 @vindex DATA LIST FIXED
247 @cindex reading fixed-format data
248 @cindex fixed-format data, reading
249 @cindex data, fixed-format, reading
250 @cindex embedding fixed-format data
255 [FILE='file-name' [ENCODING='encoding']]
256 [RECORDS=record_count]
259 /[line_no] var_spec@dots{}
261 where each var_spec takes one of the forms
262 var_list start-end [type_spec]
263 var_list (fortran_spec)
266 @cmd{DATA LIST FIXED} is used to read data files that have values at fixed
267 positions on each line of single-line or multiline records. The
268 keyword FIXED is optional.
270 The FILE subcommand must be used if input is to be taken from an
271 external file. It may be used to specify a file name as a string or a
272 file handle (@pxref{File Handles}). If the FILE subcommand is not used,
273 then input is assumed to be specified within the command file using
274 @cmd{BEGIN DATA}@dots{}@cmd{END DATA} (@pxref{BEGIN DATA}).
275 The ENCODING subcommand may only be used if the FILE subcommand is also used.
276 It specifies the character encoding of the file.
278 The optional RECORDS subcommand, which takes a single integer as an
279 argument, is used to specify the number of lines per record. If RECORDS
280 is not specified, then the number of lines per record is calculated from
281 the list of variable specifications later in @cmd{DATA LIST}.
283 The END subcommand is only useful in conjunction with @cmd{INPUT
284 PROGRAM}. @xref{INPUT PROGRAM}, for details.
286 The optional SKIP subcommand specifies a number of records to skip at
287 the beginning of an input file. It can be used to skip over a row
288 that contains variable names, for example.
290 @cmd{DATA LIST} can optionally output a table describing how the data file
291 will be read. The TABLE subcommand enables this output, and NOTABLE
292 disables it. The default is to output the table.
294 The list of variables to be read from the data list must come last.
295 Each line in the data record is introduced by a slash (@samp{/}).
296 Optionally, a line number may follow the slash. Following, any number
297 of variable specifications may be present.
299 Each variable specification consists of a list of variable names
300 followed by a description of their location on the input line. Sets of
301 variables may be specified using the @code{DATA LIST} TO convention
303 Variables}). There are two ways to specify the location of the variable
304 on the line: columnar style and FORTRAN style.
306 In columnar style, the starting column and ending column for the field
307 are specified after the variable name, separated by a dash (@samp{-}).
308 For instance, the third through fifth columns on a line would be
309 specified @samp{3-5}. By default, variables are considered to be in
310 @samp{F} format (@pxref{Input and Output Formats}). (This default can be
311 changed; see @ref{SET} for more information.)
313 In columnar style, to use a variable format other than the default,
314 specify the format type in parentheses after the column numbers. For
315 instance, for alphanumeric @samp{A} format, use @samp{(A)}.
317 In addition, implied decimal places can be specified in parentheses
318 after the column numbers. As an example, suppose that a data file has a
319 field in which the characters @samp{1234} should be interpreted as
320 having the value 12.34. Then this field has two implied decimal places,
321 and the corresponding specification would be @samp{(2)}. If a field
322 that has implied decimal places contains a decimal point, then the
323 implied decimal places are not applied.
325 Changing the variable format and adding implied decimal places can be
326 done together; for instance, @samp{(N,5)}.
328 When using columnar style, the input and output width of each variable is
329 computed from the field width. The field width must be evenly divisible
330 into the number of variables specified.
332 FORTRAN style is an altogether different approach to specifying field
333 locations. With this approach, a list of variable input format
334 specifications, separated by commas, are placed after the variable names
335 inside parentheses. Each format specifier advances as many characters
336 into the input line as it uses.
338 Implied decimal places also exist in FORTRAN style. A format
339 specification with @var{d} decimal places also has @var{d} implied
342 In addition to the standard format specifiers (@pxref{Input and Output
343 Formats}), FORTRAN style defines some extensions:
347 Advance the current column on this line by one character position.
349 @item @code{T}@var{x}
350 Set the current column on this line to column @var{x}, with column
351 numbers considered to begin with 1 at the left margin.
353 @item @code{NEWREC}@var{x}
354 Skip forward @var{x} lines in the current record, resetting the active
355 column to the left margin.
358 Any format specifier may be preceded by a number. This causes the
359 action of that format specifier to be repeated the specified number of
362 @item (@var{spec1}, @dots{}, @var{specN})
363 Group the given specifiers together. This is most useful when preceded
364 by a repeat count. Groups may be nested arbitrarily.
367 FORTRAN and columnar styles may be freely intermixed. Columnar style
368 leaves the active column immediately after the ending column
369 specified. Record motion using @code{NEWREC} in FORTRAN style also
370 applies to later FORTRAN and columnar specifiers.
373 * DATA LIST FIXED Examples:: Examples of DATA LIST FIXED.
376 @node DATA LIST FIXED Examples
377 @unnumberedsubsubsec Examples
382 DATA LIST TABLE /NAME 1-10 (A) INFO1 TO INFO3 12-17 (1).
391 Defines the following variables:
395 @code{NAME}, a 10-character-wide string variable, in columns 1
399 @code{INFO1}, a numeric variable, in columns 12 through 13.
402 @code{INFO2}, a numeric variable, in columns 14 through 15.
405 @code{INFO3}, a numeric variable, in columns 16 through 17.
408 The @code{BEGIN DATA}/@code{END DATA} commands cause three cases to be
412 Case NAME INFO1 INFO2 INFO3
413 1 John Smith 10 23 11
414 2 Bob Arnold 12 20 15
418 The @code{TABLE} keyword causes PSPP to print out a table
419 describing the four variables defined.
423 DAT LIS FIL="survey.dat"
424 /ID 1-5 NAME 7-36 (A) SURNAME 38-67 (A) MINITIAL 69 (A)
429 Defines the following variables:
433 @code{ID}, a numeric variable, in columns 1-5 of the first record.
436 @code{NAME}, a 30-character string variable, in columns 7-36 of the
440 @code{SURNAME}, a 30-character string variable, in columns 38-67 of
444 @code{MINITIAL}, a 1-character string variable, in column 69 of
448 Fifty variables @code{Q01}, @code{Q02}, @code{Q03}, @dots{}, @code{Q49},
449 @code{Q50}, all numeric, @code{Q01} in column 7, @code{Q02} in column 8,
450 @dots{}, @code{Q49} in column 55, @code{Q50} in column 56, all in the second
454 Cases are separated by a blank record.
456 Data is read from file @file{survey.dat} in the current directory.
458 This example shows keywords abbreviated to their first 3 letters.
463 @subsection DATA LIST FREE
464 @vindex DATA LIST FREE
468 [(@{TAB,'c'@}, @dots{})]
470 [FILE='file-name' [ENCODING='encoding']]
474 where each var_spec takes one of the forms
475 var_list [(type_spec)]
479 In free format, the input data is, by default, structured as a series
480 of fields separated by spaces, tabs, commas, or line breaks. Each
481 field's content may be unquoted, or it may be quoted with a pairs of
482 apostrophes (@samp{'}) or double quotes (@samp{"}). Unquoted white
483 space separates fields but is not part of any field. Any mix of
484 spaces, tabs, and line breaks is equivalent to a single space for the
485 purpose of separating fields, but consecutive commas will skip a
488 Alternatively, delimiters can be specified explicitly, as a
489 parenthesized, comma-separated list of single-character strings
490 immediately following FREE. The word TAB may also be used to specify
491 a tab character as a delimiter. When delimiters are specified
492 explicitly, only the given characters, plus line breaks, separate
493 fields. Furthermore, leading spaces at the beginnings of fields are
494 not trimmed, consecutive delimiters define empty fields, and no form
495 of quoting is allowed.
497 The NOTABLE and TABLE subcommands are as in @cmd{DATA LIST FIXED} above.
498 NOTABLE is the default.
500 The FILE and SKIP subcommands are as in @cmd{DATA LIST FIXED} above.
502 The variables to be parsed are given as a single list of variable names.
503 This list must be introduced by a single slash (@samp{/}). The set of
504 variable names may contain format specifications in parentheses
505 (@pxref{Input and Output Formats}). Format specifications apply to all
506 variables back to the previous parenthesized format specification.
508 In addition, an asterisk may be used to indicate that all variables
509 preceding it are to have input/output format @samp{F8.0}.
511 Specified field widths are ignored on input, although all normal limits
512 on field width apply, but they are honored on output.
515 @subsection DATA LIST LIST
516 @vindex DATA LIST LIST
520 [(@{TAB,'c'@}, @dots{})]
522 [FILE='file-name' [ENCODING='encoding']]
526 where each var_spec takes one of the forms
527 var_list [(type_spec)]
531 With one exception, @cmd{DATA LIST LIST} is syntactically and
532 semantically equivalent to @cmd{DATA LIST FREE}. The exception is
533 that each input line is expected to correspond to exactly one input
534 record. If more or fewer fields are found on an input line than
535 expected, an appropriate diagnostic is issued.
545 @cmd{END CASE} is used only within @cmd{INPUT PROGRAM} to output the
546 current case. @xref{INPUT PROGRAM}, for details.
556 @cmd{END FILE} is used only within @cmd{INPUT PROGRAM} to terminate
557 the current input program. @xref{INPUT PROGRAM}.
565 FILE HANDLE handle_name
570 For binary files in native encoding with fixed-length records:
571 FILE HANDLE handle_name
576 For binary files in native encoding with variable-length records:
577 FILE HANDLE handle_name
582 For binary files encoded in EBCDIC:
583 FILE HANDLE handle_name
586 /RECFORM=@{FIXED,VARIABLE,SPANNED@}
590 Use @cmd{FILE HANDLE} to associate a file handle name with a file and
591 its attributes, so that later commands can refer to the file by its
592 handle name. Names of text files can be specified directly on
593 commands that access files, so that @cmd{FILE HANDLE} is only needed when a
594 file is not an ordinary file containing lines of text. However,
595 @cmd{FILE HANDLE} may be used even for text files, and it may be
596 easier to specify a file's name once and later refer to it by an
599 Specify the file handle name as the identifier immediately following the
600 @cmd{FILE HANDLE} command name. The identifier INLINE is reserved for
601 representing data embedded in the syntax file (@pxref{BEGIN DATA}) The
602 file handle name must not already have been used in a previous
603 invocation of @cmd{FILE HANDLE}, unless it has been closed by an
604 intervening command (@pxref{CLOSE FILE HANDLE}).
606 The effect and syntax of FILE HANDLE depends on the selected MODE:
610 In CHARACTER mode, the default, the data file is read as a text file,
611 according to the local system's conventions, and each text line is
614 In CHARACTER mode only, tabs are expanded to spaces by input programs,
615 except by @cmd{DATA LIST FREE} with explicitly specified delimiters.
616 Each tab is 4 characters wide by default, but TABWIDTH (a PSPP
617 extension) may be used to specify an alternate width. Use a TABWIDTH
618 of 0 to suppress tab expansion.
621 In IMAGE mode, the data file is treated as a series of fixed-length
622 binary records. LRECL should be used to specify the record length in
623 bytes, with a default of 1024. On input, it is an error if an IMAGE
624 file's length is not a integer multiple of the record length. On
625 output, each record is padded with spaces or truncated, if necessary,
626 to make it exactly the correct length.
629 In BINARY mode, the data file is treated as a series of
630 variable-length binary records. LRECL may be specified, but its value
631 is ignored. The data for each record is both preceded and followed by
632 a 32-bit signed integer in little-endian byte order that specifies the
633 length of the record. (This redundancy permits records in these
634 files to be efficiently read in reverse order, although PSPP always
635 reads them in forward order.) The length does not include either
639 Mode 360 reads and writes files in formats first used for tapes in the
640 1960s on IBM mainframe operating systems and still supported today by
641 the modern successors of those operating systems. For more
642 information, see @cite{OS/400 Tape and Diskette Device Programming},
643 available on IBM's website.
645 Alphanumeric data in mode 360 files are encoded in EBCDIC. PSPP
646 translates EBCDIC to or from the host's native format as necessary on
647 input or output, using an ASCII/EBCDIC translation that is one-to-one,
648 so that a ``round trip'' from ASCII to EBCDIC back to ASCII, or vice
649 versa, always yields exactly the original data.
651 The RECFORM subcommand is required in mode 360. The precise file
652 format depends on its setting:
657 This record format is equivalent to IMAGE mode, except for EBCDIC
660 IBM documentation calls this @code{*F} (fixed-length, deblocked)
665 The file comprises a sequence of zero or more variable-length blocks.
666 Each block begins with a 4-byte @dfn{block descriptor word} (BDW).
667 The first two bytes of the BDW are an unsigned integer in big-endian
668 byte order that specifies the length of the block, including the BDW
669 itself. The other two bytes of the BDW are ignored on input and
670 written as zeros on output.
672 Following the BDW, the remainder of each block is a sequence of one or
673 more variable-length records, each of which in turn begins with a
674 4-byte @dfn{record descriptor word} (RDW) that has the same format as
675 the BDW. Following the RDW, the remainder of each record is the
678 The maximum length of a record in VARIABLE mode is 65,527 bytes:
679 65,535 bytes (the maximum value of a 16-bit unsigned integer), minus 4
680 bytes for the BDW, minus 4 bytes for the RDW.
682 In mode VARIABLE, LRECL specifies a maximum, not a fixed, record
683 length, in bytes. The default is 8,192.
685 IBM documentation calls this @code{*VB} (variable-length, blocked,
690 The file format is like that of VARIABLE mode, except that logical
691 records may be split among multiple physical records (called
692 @dfn{segments}) or blocks. In SPANNED mode, the third byte of each
693 RDW is called the segment control character (SCC). Odd SCC values
694 cause the segment to be appended to a record buffer maintained in
695 memory; even values also append the segment and then flush its
696 contents to the input procedure. Canonically, SCC value 0 designates
697 a record not spanned among multiple segments, and values 1 through 3
698 designate the first segment, the last segment, or an intermediate
699 segment, respectively, within a multi-segment record. The record
700 buffer is also flushed at end of file regardless of the final record's
703 The maximum length of a logical record in VARIABLE mode is limited
704 only by memory available to PSPP. Segments are limited to 65,527
705 bytes, as in VARIABLE mode.
707 This format is similar to what IBM documentation call @code{*VS}
708 (variable-length, deblocked, spanned) format.
711 In mode 360, fields of type A that extend beyond the end of a record
712 read from disk are padded with spaces in the host's native character
713 set, which are then translated from EBCDIC to the native character
714 set. Thus, when the host's native character set is based on ASCII,
715 these fields are effectively padded with character @code{X'80'}. This
716 wart is implemented for compatibility.
719 The NAME subcommand specifies the name of the file associated with the
720 handle. It is required in all modes but SCRATCH mode, in which its
724 @section INPUT PROGRAM
725 @vindex INPUT PROGRAM
729 @dots{} input commands @dots{}
733 @cmd{INPUT PROGRAM}@dots{}@cmd{END INPUT PROGRAM} specifies a
734 complex input program. By placing data input commands within @cmd{INPUT
735 PROGRAM}, PSPP programs can take advantage of more complex file
736 structures than available with only @cmd{DATA LIST}.
738 The first sort of extended input program is to simply put multiple @cmd{DATA
739 LIST} commands within the @cmd{INPUT PROGRAM}. This will cause all of
741 files to be read in parallel. Input will stop when end of file is
742 reached on any of the data files.
744 Transformations, such as conditional and looping constructs, can also be
745 included within @cmd{INPUT PROGRAM}. These can be used to combine input
746 from several data files in more complex ways. However, input will still
747 stop when end of file is reached on any of the data files.
749 To prevent @cmd{INPUT PROGRAM} from terminating at the first end of
751 the END subcommand on @cmd{DATA LIST}. This subcommand takes a
753 which should be a numeric scratch variable (@pxref{Scratch Variables}).
754 (It need not be a scratch variable but otherwise the results can be
755 surprising.) The value of this variable is set to 0 when reading the
756 data file, or 1 when end of file is encountered.
758 Two additional commands are useful in conjunction with @cmd{INPUT PROGRAM}.
759 @cmd{END CASE} is the first. Normally each loop through the
761 structure produces one case. @cmd{END CASE} controls exactly
762 when cases are output. When @cmd{END CASE} is used, looping from the end of
763 @cmd{INPUT PROGRAM} to the beginning does not cause a case to be output.
765 @cmd{END FILE} is the second. When the END subcommand is used on @cmd{DATA
766 LIST}, there is no way for the @cmd{INPUT PROGRAM} construct to stop
768 so an infinite loop results. @cmd{END FILE}, when executed,
769 stops the flow of input data and passes out of the @cmd{INPUT PROGRAM}
772 All this is very confusing. A few examples should help to clarify.
774 @c If you change this example, change the regression test1 in
775 @c tests/command/input-program.sh to match.
778 DATA LIST NOTABLE FILE='a.data'/X 1-10.
779 DATA LIST NOTABLE FILE='b.data'/Y 1-10.
784 The example above reads variable X from file @file{a.data} and variable
785 Y from file @file{b.data}. If one file is shorter than the other then
786 the extra data in the longer file is ignored.
788 @c If you change this example, change the regression test2 in
789 @c tests/command/input-program.sh to match.
795 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
798 DATA LIST NOTABLE END=#B FILE='b.data'/Y 1-10.
808 The above example reads variable X from @file{a.data} and variable Y from
809 @file{b.data}. If one file is shorter than the other then the missing
810 field is set to the system-missing value alongside the present value for
811 the remaining length of the longer file.
813 @c If you change this example, change the regression test3 in
814 @c tests/command/input-program.sh to match.
820 DATA LIST NOTABLE END=#B FILE='b.data'/X 1-10.
827 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
836 The above example reads data from file @file{a.data}, then from
837 @file{b.data}, and concatenates them into a single active dataset.
839 @c If you change this example, change the regression test4 in
840 @c tests/command/input-program.sh to match.
846 DATA LIST NOTABLE END=#EOF FILE='a.data'/X 1-10.
854 DATA LIST NOTABLE END=#EOF FILE='b.data'/X 1-10.
865 The above example does the same thing as the previous example, in a
868 @c If you change this example, make similar changes to the regression
869 @c test5 in tests/command/input-program.sh.
873 COMPUTE X=UNIFORM(10).
878 LIST/FORMAT=NUMBERED.
881 The above example causes an active dataset to be created consisting of 50
882 random variates between 0 and 10.
891 /CASES=FROM start_index TO end_index BY incr_index
892 /FORMAT=@{UNNUMBERED,NUMBERED@} @{WRAP,SINGLE@}
895 The @cmd{LIST} procedure prints the values of specified variables to the
898 The VARIABLES subcommand specifies the variables whose values are to be
899 printed. Keyword VARIABLES is optional. If VARIABLES subcommand is not
900 specified then all variables in the active dataset are printed.
902 The CASES subcommand can be used to specify a subset of cases to be
903 printed. Specify FROM and the case number of the first case to print,
904 TO and the case number of the last case to print, and BY and the number
905 of cases to advance between printing cases, or any subset of those
906 settings. If CASES is not specified then all cases are printed.
908 The FORMAT subcommand can be used to change the output format. NUMBERED
909 will print case numbers along with each case; UNNUMBERED, the default,
910 causes the case numbers to be omitted. The WRAP and SINGLE settings are
913 Case numbers start from 1. They are counted after all transformations
914 have been considered.
916 @cmd{LIST} attempts to fit all the values on a single line. If needed
917 to make them fit, variable names are displayed vertically. If values
918 cannot fit on a single line, then a multi-line format will be used.
920 @cmd{LIST} is a procedure. It causes the data to be read.
930 @cmd{NEW FILE} command clears the dictionary and data from the current
942 [/[line_no] arg@dots{}]
944 arg takes one of the following forms:
946 var_list start-end [type_spec]
947 var_list (fortran_spec)
951 The @cmd{PRINT} transformation writes variable data to the listing
952 file or an output file. @cmd{PRINT} is executed when a procedure
953 causes the data to be read. Follow @cmd{PRINT} by @cmd{EXECUTE} to
954 print variable data without invoking a procedure (@pxref{EXECUTE}).
956 All @cmd{PRINT} subcommands are optional. If no strings or variables
957 are specified, PRINT outputs a single blank line.
959 The OUTFILE subcommand specifies the file to receive the output. The
960 file may be a file name as a string or a file handle (@pxref{File
961 Handles}). If OUTFILE is not present then output will be sent to
962 PSPP's output listing file. When OUTFILE is present, a space is
963 inserted at beginning of each output line, even lines that otherwise
966 The RECORDS subcommand specifies the number of lines to be output. The
967 number of lines may optionally be surrounded by parentheses.
969 TABLE will cause the PRINT command to output a table to the listing file
970 that describes what it will print to the output file. NOTABLE, the
971 default, suppresses this output table.
973 Introduce the strings and variables to be printed with a slash
974 (@samp{/}). Optionally, the slash may be followed by a number
975 indicating which output line will be specified. In the absence of this
976 line number, the next line number will be specified. Multiple lines may
977 be specified using multiple slashes with the intended output for a line
978 following its respective slash.
980 Literal strings may be printed. Specify the string itself. Optionally
981 the string may be followed by a column number or range of column
982 numbers, specifying the location on the line for the string to be
983 printed. Otherwise, the string will be printed at the current position
986 Variables to be printed can be specified in the same ways as available
987 for @cmd{DATA LIST FIXED} (@pxref{DATA LIST FIXED}). In addition, a
989 list may be followed by an asterisk (@samp{*}), which indicates that the
990 variables should be printed in their dictionary print formats, separated
991 by spaces. A variable list followed by a slash or the end of command
992 will be interpreted the same way.
994 If a FORTRAN type specification is used to move backwards on the current
995 line, then text is written at that point on the line, the line will be
996 truncated to that length, although additional text being added will
997 again extend the line to that length.
1000 @section PRINT EJECT
1008 /[line_no] arg@dots{}
1010 arg takes one of the following forms:
1011 'string' [start-end]
1012 var_list start-end [type_spec]
1013 var_list (fortran_spec)
1017 @cmd{PRINT EJECT} advances to the beginning of a new output page in
1018 the listing file or output file. It can also output data in the same
1021 All @cmd{PRINT EJECT} subcommands are optional.
1023 Without OUTFILE, PRINT EJECT ejects the current page in
1024 the listing file, then it produces other output, if any is specified.
1026 With OUTFILE, PRINT EJECT writes its output to the specified file.
1027 The first line of output is written with @samp{1} inserted in the
1028 first column. Commonly, this is the only line of output. If
1029 additional lines of output are specified, these additional lines are
1030 written with a space inserted in the first column, as with PRINT.
1032 @xref{PRINT}, for more information on syntax and usage.
1035 @section PRINT SPACE
1039 PRINT SPACE OUTFILE='file-name' n_lines.
1042 @cmd{PRINT SPACE} prints one or more blank lines to an output file.
1044 The OUTFILE subcommand is optional. It may be used to direct output to
1045 a file specified by file name as a string or file handle (@pxref{File
1046 Handles}). If OUTFILE is not specified then output will be directed to
1049 n_lines is also optional. If present, it is an expression
1050 (@pxref{Expressions}) specifying the number of blank lines to be
1051 printed. The expression must evaluate to a nonnegative value.
1058 REREAD FILE=handle COLUMN=column.
1061 The @cmd{REREAD} transformation allows the previous input line in a
1063 already processed by @cmd{DATA LIST} or another input command to be re-read
1064 for further processing.
1066 The FILE subcommand, which is optional, is used to specify the file to
1067 have its line re-read. The file must be specified as the name of a file
1068 handle (@pxref{File Handles}). If FILE is not specified then the last
1069 file specified on @cmd{DATA LIST} will be assumed (last file specified
1070 lexically, not in terms of flow-of-control).
1072 By default, the line re-read is re-read in its entirety. With the
1073 COLUMN subcommand, a prefix of the line can be exempted from
1074 re-reading. Specify an expression (@pxref{Expressions}) evaluating to
1075 the first column that should be included in the re-read line. Columns
1076 are numbered from 1 at the left margin.
1078 Issuing @code{REREAD} multiple times will not back up in the data
1079 file. Instead, it will re-read the same line multiple times.
1081 @node REPEATING DATA
1082 @section REPEATING DATA
1083 @vindex REPEATING DATA
1091 /CONTINUED[=cont_start-cont_end]
1092 /ID=id_start-id_end=id_var
1094 /DATA=var_spec@dots{}
1096 where each var_spec takes one of the forms
1097 var_list start-end [type_spec]
1098 var_list (fortran_spec)
1101 @cmd{REPEATING DATA} parses groups of data repeating in
1102 a uniform format, possibly with several groups on a single line. Each
1103 group of data corresponds with one case. @cmd{REPEATING DATA} may only be
1104 used within an @cmd{INPUT PROGRAM} structure (@pxref{INPUT PROGRAM}).
1105 When used with @cmd{DATA LIST}, it
1106 can be used to parse groups of cases that share a subset of variables
1107 but differ in their other data.
1109 The STARTS subcommand is required. Specify a range of columns, using
1110 literal numbers or numeric variable names. This range specifies the
1111 columns on the first line that are used to contain groups of data. The
1112 ending column is optional. If it is not specified, then the record
1113 width of the input file is used. For the inline file (@pxref{BEGIN
1114 DATA}) this is 80 columns; for a file with fixed record widths it is the
1115 record width; for other files it is 1024 characters by default.
1117 The OCCURS subcommand is required. It must be a number or the name of a
1118 numeric variable. Its value is the number of groups present in the
1121 The DATA subcommand is required. It must be the last subcommand
1122 specified. It is used to specify the data present within each repeating
1123 group. Column numbers are specified relative to the beginning of a
1124 group at column 1. Data is specified in the same way as with @cmd{DATA LIST
1125 FIXED} (@pxref{DATA LIST FIXED}).
1127 All other subcommands are optional.
1129 FILE specifies the file to read, either a file name as a string or a
1130 file handle (@pxref{File Handles}). If FILE is not present then the
1131 default is the last file handle used on @cmd{DATA LIST} (lexically, not in
1132 terms of flow of control).
1134 By default @cmd{REPEATING DATA} will output a table describing how it will
1135 parse the input data. Specifying NOTABLE will disable this behavior;
1136 specifying TABLE will explicitly enable it.
1138 The LENGTH subcommand specifies the length in characters of each group.
1139 If it is not present then length is inferred from the DATA subcommand.
1140 LENGTH can be a number or a variable name.
1142 Normally all the data groups are expected to be present on a single
1143 line. Use the CONTINUED command to indicate that data can be continued
1144 onto additional lines. If data on continuation lines starts at the left
1145 margin and continues through the entire field width, no column
1146 specifications are necessary on CONTINUED. Otherwise, specify the
1147 possible range of columns in the same way as on STARTS.
1149 When data groups are continued from line to line, it is easy
1150 for cases to get out of sync through careless hand editing. The
1151 ID subcommand allows a case identifier to be present on each line of
1152 repeating data groups. @cmd{REPEATING DATA} will check for the same
1153 identifier on each line and report mismatches. Specify the range of
1154 columns that the identifier will occupy, followed by an equals sign
1155 (@samp{=}) and the identifier variable name. The variable must already
1156 have been declared with @cmd{NUMERIC} or another command.
1158 @cmd{REPEATING DATA} should be the last command given within an
1159 @cmd{INPUT PROGRAM}. It should not be enclosed within a @cmd{LOOP}
1160 structure (@pxref{LOOP}). Use @cmd{DATA LIST} before, not after,
1161 @cmd{REPEATING DATA}.
1172 /[line_no] arg@dots{}
1174 arg takes one of the following forms:
1175 'string' [start-end]
1176 var_list start-end [type_spec]
1177 var_list (fortran_spec)
1181 @code{WRITE} writes text or binary data to an output file.
1183 @xref{PRINT}, for more information on syntax and usage. @cmd{PRINT}
1184 and @cmd{WRITE} differ in only a few ways:
1188 @cmd{WRITE} uses write formats by default, whereas @cmd{PRINT} uses
1192 @cmd{PRINT} inserts a space between variables unless a format is
1193 explicitly specified, but @cmd{WRITE} never inserts space between
1194 variables in output.
1197 @cmd{PRINT} inserts a space at the beginning of each line that it
1198 writes to an output file (and @cmd{PRINT EJECT} inserts @samp{1} at
1199 the beginning of each line that should begin a new page), but
1200 @cmd{WRITE} does not.
1203 @cmd{PRINT} outputs the system-missing value according to its
1204 specified output format, whereas @cmd{WRITE} outputs the
1205 system-missing value as a field filled with spaces. Binary formats