checkin of 0.3.0
[pspp-builds.git] / doc / pspp.texi
1 \input texinfo @c -*- texinfo -*-
2 @c %**start of header
3 @setfilename pspp.info
4 @settitle PSPP
5 @set TIMESTAMP Time-stamp: <2000-01-02 22:32:14 blp>
6 @set EDITION 0.2
7 @set VERSION 0.2
8 @c For double-sided printing, uncomment:
9 @c @setchapternewpage odd
10 @c %**end of header
11
12 @iftex
13 @finalout
14 @end iftex
15
16 @ifinfo
17 @format
18 START-INFO-DIR-ENTRY
19 * PSPP: (pspp).             Statistical analysis package.
20 END-INFO-DIR-ENTRY
21 @end format
22
23 PSPP, for statistical analysis of sampled data, by Ben Pfaff.
24
25 This file documents PSPP, a statistical package for analysis of
26 sampled data that uses a command language compatible with SPSS.
27
28 Copyright (C) 1996-9, 2000 Free Software Foundation, Inc.
29
30 This version of the PSPP documentation is consistent with version 2 of
31 ``texinfo.tex''.
32
33 Permission is granted to make and distribute verbatim copies of this
34 manual provided the copyright notice and this permission notice are
35 preserved on all copies.
36
37 @ignore
38 Permission is granted to process this file through TeX and print the
39 results, provided the printed document carries copying permission notice
40 identical to this one except for the removal of this paragraph (this
41 paragraph not being relevant to the printed manual).
42
43 @end ignore
44 Permission is granted to copy and distribute modified versions of this
45 manual under the conditions for verbatim copying, provided that the
46 entire resulting derived work is distributed under the terms of a
47 permission notice identical to this one.
48
49 Permission is granted to copy and distribute translations of this
50 manual into another language, under the above condition for modified 
51 versions, except that this permission notice may be stated in a 
52 translation approved by the Free Software Foundation.
53 @end ifinfo
54
55 @titlepage
56 @title PSPP
57 @subtitle A System for Statistical Analysis
58 @subtitle Edition @value{EDITION}, for PSPP version @value{VERSION}
59 @author by Ben Pfaff
60
61 @page
62 @vskip 0pt plus 1filll
63
64 PSPP Copyright @copyright{} 1997, 1998 Free Software Foundation, Inc.
65
66 Permission is granted to make and distribute verbatim copies of this
67 manual provided the copyright notice and this permission notice are
68 preserved on all copies.
69
70 Permission is granted to copy and distribute modified versions of this
71 manual under the conditions for verbatim copying, provided that the
72 entire derived work is distributed under the terms of a permission
73 notice identical to this one.
74
75 Permission is granted to copy and distribute translations of this manual
76 into another language, under the above conditions for modified versions,
77 except that this permission notice may be stated in a translation
78 approved by the Foundation.
79 @end titlepage
80
81 @node Top, Introduction, (dir), (dir)
82 @ifinfo
83 @top PSPP
84
85 This file documents the PSPP package for statistical analysis of sampled
86 data.  This is edition @value{EDITION}, for PSPP version
87 @value{VERSION}, last modified at @value{TIMESTAMP}.
88
89 @end ifinfo
90
91 @menu
92 * Introduction::                Description of the package.
93 * License::                     Your rights and obligations.
94 * Credits::                     Acknowledgement of authors.
95
96 * Installation::                How to compile and install PSPP.
97 * Configuration::               Configuring PSPP.
98 * Invocation::                  Starting and running PSPP.
99
100 * Language::                    Basics of the PSPP command language.
101 * Expressions::                 Numeric and string expression syntax.
102
103 * Data Input and Output::       Reading data from user files.
104 * System and Portable Files::   Dealing with system & portable files.
105 * Variable Attributes::         Adjusting and examining variables.
106 * Data Manipulation::           Simple operations on data.
107 * Data Selection::              Select certain cases for analysis.
108 * Conditionals and Looping::    Doing things many times or not at all.
109 * Statistics::                  Basic statistical procedures.
110 * Utilities::                   Other commands.
111 * Not Implemented::             What's not here yet
112
113 * Data File Format::            Format of PSPP system files.
114 * Portable File Format::        Format of PSPP portable files.
115 * q2c Input Format::            Format of syntax accepted by q2c.
116
117 * Bugs::                        Known problems; submitting bug reports.
118
119 * Function Index::              Index of PSPP functions for expressions.
120 * Concept Index::               Index of concepts.
121 * Command Index::               Index of PSPP procedures.
122
123 @end menu
124
125 @node Introduction, License, Top, Top
126 @chapter Introduction
127 @cindex introduction
128
129 @cindex PSPP language
130 @cindex language, PSPP
131 PSPP is a tool for statistical analysis of sampled data.  It reads a
132 syntax file and a data file, analyzes the data, and writes the results
133 to a listing file or to standard output.
134
135 The language accepted by PSPP is similar to those accepted by SPSS
136 statistical products.  The details of PSPP's language are given
137 later in this manual.
138
139 @cindex files, PSPP
140 @cindex output, PSPP
141 @cindex PostScript
142 @cindex graphics
143 @cindex Ghostscript
144 @cindex Free Software Foundation
145 PSPP produces output in two forms: tables and charts.  Both of these can
146 be written in several formats; currently, ASCII, PostScript, and HTML
147 are supported.  In the future, more drivers, such as PCL and X Window
148 System drivers, may be developed.  For now, Ghostscript, available from
149 the Free Software Foundation, may be used to convert PostScript chart
150 output to other formats.
151
152 The current version of PSPP, @value{VERSION}, is woefully incomplete in
153 terms of its statistical procedure support.  PSPP is a work in progress.
154 The author hopes to support fully support all features in the products
155 that PSPP replaces, eventually.  The author welcomes questions,
156 comments, donations, and code submissions.  @xref{Bugs,,Submitting Bug
157 Reports}, for instructions on contacting the author.
158
159 @node License, Credits, Introduction, Top
160 @chapter Your rights and obligations
161 @cindex license
162 @cindex your rights and obligations
163 @cindex rights, your
164 @cindex obligations, your
165
166 @cindex Free Software Foundation
167 @cindex GNU General Public License
168 @cindex General Public License
169 @cindex GPL
170 @cindex distribution
171 @cindex redistribution
172 Most of PSPP is distributed under the GNU General Public
173 License.  The General Public License says, in effect, that you may
174 modify and distribute PSPP as you like, as long as you grant the
175 same rights to others.  It also states that you must provide source code
176 when you distribute PSPP, or, if you obtained PSPP
177 source code from an anonymous ftp site, give out the name of that site.
178
179 The General Public License is given in full in the source distribution
180 as file @file{COPYING}.  In Debian GNU/Linux, this file is also
181 available as file @file{/usr/doc/copyright/GPL}.
182
183 To quote the GPL itself:
184
185 @quotation
186 This program is free software; you can redistribute it and/or modify it
187 under the terms of the GNU General Public License as published by the
188 Free Software Foundation; either version 2 of the License, or (at your
189 option) any later version.
190
191 This program is distributed in the hope that it will be useful, but
192 WITHOUT ANY WARRANTY; without even the implied warranty of
193 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
194 General Public License for more details.
195
196 You should have received a copy of the GNU General Public License along
197 with this program; if not, write to the Free Software Foundation, Inc.,
198 675 Mass Ave, Cambridge, MA 02139, USA.
199 @end quotation
200
201 @node Credits, Installation, License, Top
202 @chapter Credits
203 @cindex credits
204 @cindex authors
205
206 @cindex Minton, Claire
207 @cindex @cite{Cat's Cradle}
208 @cindex Vonnegut, Kurt, Jr.
209 @cindex quotations
210 @quotation
211 I'm always embarrassed when I see an index an author has made of his own
212 work.  It's a shameless exhibition---to the @i{trained} eye.  Never
213 index your own book.
214
215 ---Claire Minton, @cite{Cat's Cradle}, Kurt Vonnegut, Jr.
216 @end quotation
217
218 @cindex Pfaff, Ben
219 Most of PSPP, as well as this manual (including the indices),
220 was written by Ben Pfaff.  @xref{Contacting the Author}, for
221 instructions on contacting the author.
222
223 @cindex Covington, Michael A.
224 @cindex Van Zandt, James
225 @cindex @file{ftp.cdrom.com}
226 @cindex @file{/pub/algorithms/c/julcal10}
227 @cindex @file{julcal.c}
228 @cindex @file{julcal.h}
229 The PSPP source code incorporates @code{julcal10} originally
230 written by Michael A. Covington and translated into C by Jim Van Zandt.
231 The original package can be found in directory
232 @file{ftp://ftp.cdrom.com/pub/algorithms/c/julcal10}.  The entire
233 contents of that directory constitute the package.  The files actually
234 used in PSPP are @code{julcal.c} and @code{julcal.h}.
235
236 @node Installation, Configuration, Credits, Top
237 @chapter Installing PSPP
238 @cindex installation
239 @cindex PSPP, installing
240
241 @cindex GNU C compiler
242 @cindex gcc
243 @cindex compiler, recommended
244 @cindex compiler, gcc
245 PSPP conforms to the GNU Coding Standards.  PSPP is written in, and
246 requires for proper operation, ANSI/ISO C.  You might want to
247 additionally note the following points:
248
249 @itemize @bullet
250 @item
251 The compiler and linker must allow for significance of several
252 characters in external identifiers.  The exact number is unknown but at
253 least 31 is recommended.
254
255 @item
256 The @code{int} type must be 32 bits or wider.
257
258 @item
259 The recommended compiler is gcc 2.7.2.1 or later, but any ANSI compiler
260 will do if it fits the above criteria.
261 @end itemize
262
263 Many UNIX variants should work out-of-the-box, as PSPP uses GNU
264 autoconf to detect differences between environments.  Please report any
265 problems with compilation of PSPP under UNIX and UNIX-like operating
266 systems---portability is a major concern of the author.
267
268 The pages below give specific instructions for installing PSPP
269 on each type of system mentioned above.
270
271 @menu
272 * UNIX installation::           Installing on UNIX-like environments.
273 @end menu
274
275 @node UNIX installation,  , Installation, Installation
276 @section UNIX installation
277 @cindex UNIX, installing PSPP under
278 @cindex installation, under UNIX
279 @noindent
280 To install PSPP under a UNIX-like operating system, follow the steps
281 below in order.  Some of the text below was taken directly from various
282 Free Software Foundation sources.
283
284 @enumerate
285 @item
286 @code{cd} to the directory containing the PSPP source.
287
288 @cindex configure, GNU
289 @cindex GNU configure
290 @item
291 Type @samp{./configure} to configure for your particular operating
292 system and compiler.  Running @code{configure} takes a while.  While
293 running, it displays some messages telling which features it is checking
294 for.
295
296 You can optionally supply some options to @code{configure} in order to
297 give it hints about how to do its job.  Type @code{./configure --help}
298 to see a list of options.  One of the most useful options is
299 @samp{--with-checker}, which enables the use of the Checker memory
300 debugger under supported operating systems.  Checker must already be
301 installed to use this option.  Do not use @samp{--with-checker} if you
302 are not debugging PSPP itself.
303
304 @cindex @file{Makefile}
305 @cindex @file{config.h}
306 @cindex @file{pref.h}
307 @cindex makefile
308 @item
309 (optional) Edit @file{Makefile}, @file{config.h}, and @file{pref.h}.
310 These files are produced by @code{configure}.  Note that most PSPP
311 settings can be changed at runtime.
312
313 @file{pref.h} is only generated by @code{configure} if it does not
314 already exist.  (It's copied from @file{prefh.orig}.)
315
316 @cindex compiling
317 @item
318 Type @samp{make} to compile the package.  If there are any errors during
319 compilation, try to fix them.  If modifications are necessary to compile
320 correctly under your configuration, contact the author.
321 @xref{Bugs,,Submitting Bug Reports}, for details.
322
323 @cindex self-tests, running
324 @item
325 Type @samp{make check} to run self-tests on the compiled PSPP package.
326
327 @cindex installation
328 @cindex PSPP, installing
329 @cindex @file{/usr/local/share/pspp/}
330 @cindex @file{/usr/local/bin/}
331 @cindex @file{/usr/local/info/}
332 @cindex documentation, installing
333 @item
334 Become the superuser and type @samp{make install} to install the
335 PSPP binaries, by default in @file{/usr/local/bin/}.  The
336 directory @file{/usr/local/share/pspp/} is created and populated with
337 files needed by PSPP at runtime.  This step will also cause the
338 PSPP documentation to be installed in @file{/usr/local/info/},
339 but only if that directory already exists.
340
341 @item
342 (optional) Type @samp{make clean} to delete the PSPP binaries
343 from the source tree.
344 @end enumerate
345
346 @node Configuration, Invocation, Installation, Top
347 @chapter Configuring PSPP
348 @cindex configuration
349 @cindex PSPP, configuring
350
351 PSPP has dozens of configuration possibilities and hundreds of
352 settings.  This is both a bane and a blessing.  On one hand, it's
353 possible to easily accommodate diverse ranges of setups.  But, on the
354 other, the multitude of possibilities can overwhelm the casual user.
355 Fortunately, the configuration mechanisms are profusely described in the
356 sections below@enddots{}
357
358 @menu
359 * File locations::              How PSPP finds config files.
360 * Configuration techniques::    Many different methods of configuration@enddots{}
361 * Configuration files::         How configuration files are read.
362 * Environment variables::       All about environment variables.
363 * Output devices::              Describing your terminal(s) and printer(s).
364 * PostScript driver class::     Configuration of PostScript devices.
365 * ASCII driver class::          Configuration of character-code devices.
366 * HTML driver class::           Configuration for HTML output.
367 * Miscellaneous configuring::   Even more configuration variables.
368 * Improving output quality::    Hints for producing ever-more-lovely output.
369 @end menu
370
371 @node File locations, Configuration techniques, Configuration, Configuration
372 @section Locating configuration files
373
374 PSPP uses the same method to find most of its configuration files:
375
376 @enumerate
377 @item
378 The @dfn{base name} of the file being sought is determined.
379
380 @item
381 The path to search is determined.  
382
383 @item
384 Each directory in the search path, from left to right, is searched for a
385 file with the name of the base name.  The first occurrence is read
386 as the configuration file.
387 @end enumerate
388
389 The first two steps are elaborated below for the sake of our pedantic
390 friends.
391
392 @enumerate
393 @item
394 A @dfn{base name} is a file name lacking an absolute directory
395 reference.  Some examples of base names are: @file{ps-encodings},
396 @file{devices}, @file{devps/DESC} (under UNIX), @file{devps\DESC} (under
397 M$ environments).
398
399 Determining the base name is a two-step process:
400
401 @enumerate a
402 @item
403 If the appropriate environment variable is defined, the value of that
404 variable is used (@pxref{Environment variables}).  For instance, when
405 searching for the output driver initialization file, the variable
406 examined is @code{STAT_OUTPUT_INIT_FILE}.
407
408 @item
409 Otherwise, the compiled-in default is used.  For example, when searching
410 for the output driver initialization file, the default base name is
411 @file{devices}.
412 @end enumerate
413
414 @strong{Please note:} If a user-specified base name does contain an
415 absolute directory reference, as in a file name like
416 @file{/home/pfaff/fonts/TR}, no path is searched---the file name is used
417 exactly as given---and the algorithm terminates.
418
419 @item
420 The path is the first of the following that is defined:
421
422 @itemize @bullet
423 @item
424 A variable definition for the path given in the user environment.  This
425 is a PSPP-specific environment variable name; for instance,
426 @code{STAT_OUTPUT_INIT_PATH}.
427
428 @item 
429 In some cases, another, less-specific environment variable is checked.
430 For instance, when searching for font files, the PostScript driver first
431 checks for a variable with name @code{STAT_GROFF_FONT_PATH}, then for
432 one with name @code{GROFF_FONT_PATH}.  (However, font searching has its
433 own list of esoteric search rules.)
434
435 @item
436 The configuration file path, which is itself determined by the
437 following rules:
438
439 @enumerate a
440 @item
441 If the command line contains an option of the form @samp{-B @var{path}}
442 or @samp{--config-dir=@var{path}}, then the value given on the
443 rightmost occurrence of such an option is used.
444
445 @item
446 Otherwise, if the environment variable @code{STAT_CONFIG_PATH} is
447 defined, the value of that variable is used.
448
449 @item
450 Otherwise, the compiled-in fallback default is used.  On UNIX machines,
451 the default fallback path is
452
453 @enumerate 1
454 @item
455 @file{~/.pspp}
456
457 @item
458 @file{/usr/local/lib/pspp}
459
460 @item
461 @file{/usr/lib/pspp}
462 @end enumerate
463
464 On DOS machines, the default fallback path is:
465
466 @enumerate 1
467 @item
468 All the paths from the DOS search path in the @samp{PATH} environment
469 variable, in left-to-right order.
470
471 @item
472 @file{C:\PSPP}, as a last resort.
473 @end enumerate
474
475 Note that the installer of PSPP can easily change this default
476 fallback path; thus the above should not be taken as gospel.
477 @end enumerate
478 @end itemize
479 @end enumerate
480
481 As a final note: Under DOS, directories given in paths are delimited by
482 semicolons (@samp{;}); under UNIX, directories are delimited by colons
483 (@samp{:}).  This corresponds with the standard path delimiter under
484 these OSes.
485
486 @node Configuration techniques, Configuration files, File locations, Configuration
487 @section Configuration techniques
488
489 There are many ways that PSPP can be configured.  These are
490 described in the list below.  Values given by earlier items take
491 precedence over those given by later items.
492
493 @enumerate
494 @item
495 Syntax commands that modify settings, such as @code{SET}.
496
497 @item
498 Command-line options.  @xref{Invocation}.
499
500 @item
501 PSPP-specific environment variable contents.  @xref{Environment
502 variables}.
503
504 @item
505 General environment variable contents.  @xref{Environment variables}.
506
507 @item
508 Configuration file contents.  @xref{Configuration files}.
509
510 @item
511 Fallback defaults.
512 @end enumerate
513
514 Some of the above may not apply to a particular setting.  For instance,
515 the current pager (such as @samp{more}, @samp{most}, or @samp{less})
516 cannot be determined by configuration file contents because there is no
517 appropriate configuration file.
518
519 @node Configuration files, Environment variables, Configuration techniques, Configuration
520 @section Configuration files
521
522 Most configuration files have a common form:
523
524 @itemize @bullet
525 @item
526 Each line forms a separate command or directive.  This means that lines
527 cannot be broken up, unless they are spliced together with a trailing
528 backslash, as described below.
529
530 @item
531 Before anything else is done, trailing whitespace is removed.
532
533 @item
534 When a line ends in a backslash (@samp{\}), the backslash is removed,
535 and the next line is read and appended to the current line.
536
537 @itemize @minus
538 @item
539 Whitespace preceding the backslash is retained.
540
541 @item
542 This rule continues to be applied until the line read does not end in a
543 backslash.
544
545 @item
546 It is an error if the last line in the file ends in a backslash.
547 @end itemize
548
549 @item
550 Comments are introduced by an octothorpe (#), and continue until the
551 end of the line.
552
553 @itemize @minus
554 @item
555 An octothorpe inside balanced pairs of double quotation marks (@samp{"})
556 or single quotation marks (@samp{'}) does not introduce a comment.
557
558 @item
559 The backslash character can be used inside balanced quotes of either
560 type to escape the following character as a literal character.  
561
562 (This is distinct from the use of a backslash as a line-splicing
563 character.)
564
565 @item
566 Line splicing takes place before comment removal.
567 @end itemize
568
569 @item
570 Blank lines, and lines that contain only whitespace, are ignored.
571 @end itemize
572
573 @node Environment variables, Output devices, Configuration files, Configuration
574 @section Environment variables
575
576 You may think the concept of environment variables is a fairly simple
577 one.  However, the author of PSPP has found a way to complicate
578 even something so simple.  Environment variables are further described
579 in the sections below:
580
581 @menu
582 * Variable values::             Values of variables are determined this way.
583 * Environment substitutions::   How environment substitutions are made.
584 * Predefined variables::        A few variables are automatically defined.
585 @end menu
586
587 @node Variable values, Environment substitutions, Environment variables, Environment variables
588 @subsection Values of environment variables
589
590 Values for environment variables are obtained by the following means,
591 which are arranged in order of decreasing precedence:
592
593 @enumerate
594 @item
595 Command-line options.  @xref{Invocation}.
596
597 @item
598 The @file{environment} configuration file---more on this below.
599
600 @item
601 Actual environment variables (defined in the shell or other parent
602 process).
603 @end enumerate
604
605 The @file{environment} configuration file is located through application
606 of the usual algorithm for configuration files (@pxref{File locations}),
607 except that its contents do not affect the search path used to find
608 @file{environment} itself.  Use of @file{environment} is discouraged on
609 systems that allow an arbitrarily large environment; it is supported for
610 use on systems like MS-DOS that limit environment size.
611
612 @file{environment} is composed of lines having the form
613 @samp{@var{key}=@var{value}}, where @var{key} and the equals sign
614 (@samp{=}) are required, and @var{value} is optional.  If @var{value} is
615 given, variable @var{key} is given that value; if @var{value} is absent,
616 variable @var{key} is undefined (deleted).  Variables may not be defined
617 with a null value.
618
619 Environment substitutions are performed on each line in the file
620 (@pxref{Environment substitutions}).
621
622 See @ref{Configuration files}, for more details on formatting of the
623 environment configuration file.
624
625 @quotation
626 @strong{Please note:} Support for @file{environment} is not yet
627 implemented.
628 @end quotation
629
630 @node Environment substitutions, Predefined variables, Variable values, Environment variables
631 @subsection Environment substitutions
632
633 Much of the power of environment variables lies in the way that they may
634 be substituted into configuration files.  Variable substitutions are
635 described below.
636
637 The line is scanned from left to right.  In this scan, all characters
638 other than dollar signs (@samp{$}) are retained unmolested.  Dollar
639 signs, however, introduce an environment variable reference.  References
640 take three forms:
641
642 @table @code
643 @item $@var{var}
644 Replaced by the value of environment variable @var{var}, determined as
645 specified in @ref{Variable values}.  @var{var} must be one of the
646 following:
647
648 @itemize @bullet
649 @item
650 One or more letters.
651
652 @item
653 Exactly one nonalphabetic character.  This may not be a left brace
654 (@samp{@{}).
655 @end itemize
656
657 @item $@{@var{var}@}
658 Same as above, but @var{var} may contain any character (except
659 @samp{@}}).
660
661 @item $$
662 Replaced by a single dollar sign.
663 @end table
664
665 Undefined variables expand to a empty value.
666
667 @node Predefined variables,  , Environment substitutions, Environment variables
668 @subsection Predefined environment variables
669
670 There are two environment variables predefined for use in environment
671 substitutions:
672
673 @table @samp
674 @item VER
675 Defined as the version number of PSPP, as a string, in a format
676 something like @samp{0.9.4}.
677
678 @item ARCH
679 Defined as the host architecture of PSPP, as a string, in standard
680 cpu-manufacturer-OS format.  For instance, Debian GNU/Linux 1.1 on an
681 Intel machine defines this as @samp{i586-unknown-linux}.  This is
682 somewhat dependent on the system used to compile PSPP.
683 @end table
684
685 Nothing prevents these values from being overridden, although it's a
686 good idea not to do so.
687
688 @node Output devices, PostScript driver class, Environment variables, Configuration
689 @section Output devices
690
691 Configuring output devices is the most complicated aspect of configuring
692 PSPP.  The output device configuration file is named
693 @file{devices}.  It is searched for using the usual algorithm for
694 finding configuration files (@pxref{File locations}).  Each line in the
695 file is read in the usual manner for configuration files
696 (@pxref{Configuration files}).
697
698 Lines in @file{devices} are divided into three categories, described
699 briefly in the table below:
700
701 @table @i
702 @item driver category definitions
703 Define a driver in terms of other drivers.
704
705 @item macro definitions
706 Define environment variables local to the the output driver
707 configuration file.
708
709 @item device definitions
710 Describe the configuration of an output device.
711 @end table
712
713 The following sections further elaborate the contents of the
714 @file{devices} file.
715
716 @menu
717 * Driver categories::           How to organize the driver namespace.
718 * Macro definitions::           Environment variables local to @file{devices}.
719 * Device definitions::          Output device descriptions.
720 * Dimensions::                  Lengths, widths, sizes, @enddots{}
721 * papersize::                   Letter, legal, A4, envelope, @enddots{}
722 * Distinguishing line types::   Details on @file{devices} parsing.
723 * Tokenizing lines::            Dividing @file{devices} lines into tokens.
724 @end menu
725
726 @node Driver categories, Macro definitions, Output devices, Output devices
727 @subsection Driver categories
728
729 Drivers can be divided into categories.  Drivers are specified by their
730 names, or by the names of the categories that they are contained in.
731 Only certain drivers are enabled each time PSPP is run; by
732 default, these are the drivers in the category `default'.  To enable a
733 different set of drivers, use the @samp{-o @var{device}} command-line
734 option (@pxref{Invocation}).
735
736 Categories are specified with a line of the form
737 @samp{@var{category}=@var{driver1} @var{driver2} @var{driver3} @var{@dots{}}
738 @var{driver@var{n}}}.  This line specifies that the category
739 @var{category} is composed of drivers named @var{driver1},
740 @var{driver2}, and so on.  There may be any number of drivers in the
741 category, from zero on up.
742
743 Categories may also be specified on the command line
744 (@pxref{Invocation}).
745
746 This is all you need to know about categories.  If you're still curious,
747 read on.
748
749 First of all, the term `categories' is a bit of a misnomer.  In fact,
750 the internal representation is nothing like the hierarchy that the term
751 seems to imply: a linear list is used to keep track of the enabled
752 drivers.
753
754 When PSPP first begins reading @file{devices}, this list contains
755 the name of any drivers or categories specified on the command line, or
756 the single item `default' if none were specified.
757
758 Each time a category definition is specified, the list is searched for
759 an item with the value of @var{category}.  If a matching item is found,
760 it is deleted.  If there was a match, the list of drivers (@var{driver1}
761 through @var{driver@var{n}}) is then appended to the list.
762
763 Each time a driver definition line is encountered, the list is searched.
764 If the list contains an item with that driver's name, the driver is
765 enabled and the item is deleted from the list.  Otherwise, the driver
766 is not enabled.
767
768 It is an error if the list is not empty when the end of @file{devices}
769 is reached.
770
771 @node Macro definitions, Device definitions, Driver categories, Output devices
772 @subsection Macro definitions
773
774 Macro definitions take the form @samp{define @var{macroname}
775 @var{definition}}.  In such a macro definition, the environment variable
776 @var{macroname} is defined to expand to the value @var{definition}.
777 Before the definition is made, however, any macros used in
778 @var{definition} are expanded.
779
780 Please note the following nuances of macro usage:
781
782 @itemize @bullet
783 @item
784 For the purposes of this section, @dfn{macro} and @dfn{environment
785 variable} are synonyms.
786
787 @item
788 Macros may not take arguments.
789
790 @item
791 Macros may not recurse.
792
793 @item
794 Macros are just environment variable definitions like other environment
795 variable definitions, with the exception that they are limited in scope
796 to the @file{devices} configuration file.
797
798 @item
799 Macros override other all environment variables of the same name (within
800 the scope of @file{devices}).
801
802 @item
803 Earlier macro definitions for a particular @var{key} override later
804 ones.  In particular, macro definitions on the command line override
805 those in the device definition file.  @xref{Non-option Arguments}.
806
807 @item
808 There are two predefined macros, whose values are determined at runtime:
809
810 @table @samp
811 @item viewwidth
812 Defined as the width of the console screen, in columns of text.
813
814 @item viewlength
815 Defined as the length of the console screen, in lines of text.
816 @end table
817 @end itemize
818
819 @node Device definitions, Dimensions, Macro definitions, Output devices
820 @subsection Driver definitions
821
822 Driver definitions are the ultimate purpose of the @file{devices}
823 configuration file.  These are where the real action is.  Driver
824 definitions tell PSPP where it should send its output.
825
826 Each driver definition line is divided into four fields.  These fields
827 are delimited by colons (@samp{:}).  Each line is subjected to
828 environment variable interpolation before it is processed further
829 (@pxref{Environment substitutions}).  From left to right, the four
830 fields are, in brief:
831
832 @table @i
833 @item driver name
834 A unique identifier, used to determine whether to enable the driver.
835
836 @item class name
837 One of the predefined driver classes supported by PSPP.  The
838 currently supported driver classes include `postscript' and `ascii'.
839
840 @item device type(s)
841 Zero or more of the following keywords, delimited by spaces:
842
843 @table @code
844 @item screen
845
846 Indicates that the device is a screen display.  This may reduce the
847 amount of buffering done by the driver, to make interactive use more
848 convenient.
849
850 @item printer
851
852 Indicates that the device is a printer.
853
854 @item listing
855
856 Indicates that the device is a listing file.
857 @end table
858
859 These options are just hints to PSPP and do not cause the output to be
860 directed to the screen, or to the printer, or to a listing file---those
861 must be set elsewhere in the options.  They are used primarily to decide
862 which devices should be enabled at any given time.  @xref{SET}, for more
863 information.
864
865 @item options
866 An optional set of options to pass to the driver itself.  The exact
867 format for the options varies among drivers.
868 @end table
869
870 The driver is enabled if:
871
872 @enumerate
873 @item
874 Its driver name is specified on the command line, or
875
876 @item
877 It's in a category specified on the command line, or
878
879 @item
880 If no categories or driver names are specified on the command line, it
881 is in category @code{default}.
882 @end enumerate
883
884 For more information on driver names, see @ref{Driver categories}.
885
886 The class name must be one of those supported by PSPP.  The
887 classes supported depend on the options with which PSPP was
888 compiled.  See later sections in this chapter for descriptions of the
889 available driver classes.
890
891 Options are dependent on the driver.  See the driver descriptions for
892 details.
893
894 @node Dimensions, papersize, Device definitions, Output devices
895 @subsection Dimensions
896
897 Quite often in configuration it is necessary to specify a length or a
898 size.  PSPP uses a common syntax for all such, calling them
899 collectively by the name @dfn{dimensions}.
900
901 @itemize @bullet
902 @item
903 You can specify dimensions in decimal form (@samp{12.5}) or as
904 fractions, either as mixed numbers (@samp{12-1/2}) or raw fractions
905 (@samp{25/2}).
906
907 @item 
908 A number of different units are available.  These are suffixed to the
909 numeric part of the dimension.  There must be no spaces between the
910 number and the unit.  The available units are identical to those offered
911 by the popular typesetting system @TeX{}:
912
913 @table @code
914 @item in
915 inch (1 @code{in} = 2.54 @code{cm})
916
917 @item "
918 inch (1 @code{in} = 2.54 @code{cm})
919
920 @item pt
921 printer's point (1 @code{in} = 72.27 @code{pt})
922
923 @item pc
924 pica (12 @code{pt} = 1 @code{pc})
925
926 @item bp
927 PostScript point (1 @code{in} = 72 @code{bp})
928
929 @item cm
930 centimeter
931
932 @item mm
933 millimeter (10 @code{mm} = 1 @code{cm})
934
935 @item dd
936 didot point (1157 @code{dd} = 1238 @code{pt})
937
938 @item cc
939 cicero (1 @code{cc} = 12 @code{dd})
940
941 @item sp
942 scaled point (65536 @code{sp} = 1 @code{pt})
943 @end table
944
945 @item
946 If no explicit unit is given, a DWIM@footnote{Do What I Mean}
947 ``feature'' attempts to guess the best unit:
948
949 @itemize @minus
950 @item
951 Numbers less than 50 are assumed to be in inches.
952
953 @item
954 Numbers 50 or greater are assumed to be in millimeters.
955 @end itemize
956 @end itemize
957
958 @node papersize, Distinguishing line types, Dimensions, Output devices
959 @subsection Paper sizes
960
961 Output drivers usually deal with some sort of hardcopy media.  This
962 media is called @dfn{paper} by the drivers, though in reality it could
963 be a transparency or film or thinly veiled sarcasm.  To make it easier
964 for you to deal with paper, PSPP allows you to have (of course!) a
965 configuration file that gives symbolic names, like ``letter'' or
966 ``legal'' or ``a4'', to paper sizes, rather than forcing you to use
967 cryptic numbers like ``8-1/2 x 11'' or ``210 by 297''.  Surprisingly
968 enough, this configuration file is named @file{papersize}.
969 @xref{Configuration files}.
970
971 When PSPP tries to connect a symbolic paper name to a paper size, it
972 reads and parses each non-comment line in the file, in order.  The first
973 field on each line must be a symbolic paper name in double quotes.
974 Paper names may not contain double quotes.  Paper names are not
975 case-sensitive: @samp{legal} and @samp{Legal} are equivalent.
976
977 If a match is found for the paper name, the rest of the line is parsed.
978 If it is found to be a pair of dimensions (@pxref{Dimensions}) separated
979 by either @samp{x} or @samp{by}, then those are taken to be the paper
980 size, in order of width followed by length.  There @emph{must} be at
981 least one space on each side of @samp{x} or @samp{by}.
982
983 Otherwise the line must be of the form
984 @samp{"@var{paper-1}"="@var{paper-2}"}.  In this case the target of the
985 search becomes paper name @var{paper-2} and the search through the file
986 continues.
987
988 @node Distinguishing line types, Tokenizing lines, papersize, Output devices
989 @subsection How lines are divided into types
990
991 The lines in @file{devices} are distinguished in the following manner:
992
993 @enumerate
994 @item
995 Leading whitespace is removed.
996
997 @item
998 If the resulting line begins with the exact string @code{define},
999 followed by one or more whitespace characters, the line is processed as
1000 a macro definition.
1001
1002 @item
1003 Otherwise, the line is scanned for the first instance of a colon
1004 (@samp{:}) or an equals sign (@samp{=}).
1005
1006 @item
1007 If a colon is encountered first, the line is processed as a driver
1008 definition.
1009
1010 @item
1011 Otherwise, if an equals sign is encountered, the line is processed as a
1012 macro definition.
1013
1014 @item
1015 Otherwise, the line is ill-formed.
1016 @end enumerate
1017
1018 @node Tokenizing lines,  , Distinguishing line types, Output devices
1019 @subsection How lines are divided into tokens
1020
1021 Each driver definition line is run through a simple tokenizer.  This
1022 tokenizer recognizes two basic types of tokens.
1023
1024 The first type is an equals sign (@samp{=}).  Equals signs are both
1025 delimiters between tokens and tokens in themselves.
1026
1027 The second type is an identifier or string token.  Identifiers and
1028 strings are equivalent after tokenization, though they are written
1029 differently.  An identifier is any string of characters other than
1030 whitespace or equals sign.
1031
1032 A string is introduced by a single- or double-quote character (@samp{'}
1033 or @samp{"}) and, in general, continues until the next occurrence of
1034 that same character.  The following standard C escapes can also be
1035 embedded within strings:
1036
1037 @table @code
1038 @item \'
1039 A single-quote (@samp{'}).
1040
1041 @item \"
1042 A double-quote (@samp{"}).
1043
1044 @item \?
1045 A question mark (@samp{?}).  Included for hysterical raisins.
1046
1047 @item \\
1048 A backslash (@samp{\}).
1049
1050 @item \a
1051 Audio bell (ASCII 7).
1052
1053 @item \b
1054 Backspace (ASCII 8).
1055
1056 @item \f
1057 Formfeed (ASCII 12).
1058
1059 @item \n
1060 Newline (ASCII 10)
1061
1062 @item \r
1063 Carriage return (ASCII 13).
1064
1065 @item \t
1066 Tab (ASCII 9).
1067
1068 @item \v
1069 Vertical tab (ASCII 11).
1070
1071 @item \@var{o}@var{o}@var{o}
1072 Each @samp{o} must be an octal digit.  The character is the one having
1073 the octal value specified.  Any number of octal digits is read and
1074 interpreted; only the lower 8 bits are used.
1075
1076 @item \x@var{h}@var{h}
1077 Each @samp{h} must be a hex digit.  The character is the one having the
1078 hexadecimal value specified.  Any number of hex digits is read and
1079 interpreted; only the lower 8 bits are used.
1080 @end table
1081
1082 Tokens, outside of quoted strings, are delimited by whitespace or equals
1083 signs.
1084
1085 @node PostScript driver class, ASCII driver class, Output devices, Configuration
1086 @section The PostScript driver class
1087
1088 The @code{postscript} driver class is used to produce output that is
1089 acceptable to PostScript printers and to PC-based PostScript
1090 interpreters such as Ghostscript.  Continuing a long tradition,
1091 PSPP's PostScript driver is configurable to the point of
1092 absurdity.
1093
1094 There are actually two PostScript drivers.  The first one,
1095 @samp{postscript}, produces ordinary DSC-compliant PostScript output.
1096 The second one @samp{epsf}, produces an Encapsulated PostScript file.
1097 The two drivers are otherwise identical in configuration and in
1098 operation.
1099
1100 The PostScript driver is described in further detail below.
1101
1102 @menu
1103 * PS output options::           Output file options.
1104 * PS page options::             Paper, margins, scaling & rotation, more!
1105 * PS file options::             Configuration files.
1106 * PS font options::             Default fonts, font options.
1107 * PS line options::             Line widths, options.
1108 * Prologue::                    Details on the PostScript prologue.
1109 * Encodings::                   Details on PostScript font encodings.
1110 @end menu
1111
1112 @node PS output options, PS page options, PostScript driver class, PostScript driver class
1113 @subsection PostScript output options
1114
1115 These options deal with the form of the output and the output file
1116 itself:
1117
1118 @table @code
1119 @item output-file=@var{filename}
1120
1121 File to which output should be sent.  This can be an ordinary filename
1122 (i.e., @code{"pspp.ps"}), a pipe filename (i.e., @code{"|lpr"}), or
1123 stdout (@code{"-"}).  Default: @code{"pspp.ps"}.
1124
1125 @item color=@var{boolean}
1126
1127 Most of the time black-and-white PostScript devices are smart enough to
1128 map colors to shades themselves.  However, you can cause the PSPP
1129 output driver to do an ugly simulation of this in its own driver by
1130 turning @code{color} off.  Default: @code{on}.
1131
1132 This is a boolean setting, as are many settings in the PostScript
1133 driver.  Valid positive boolean values are @samp{on}, @samp{true},
1134 @samp{yes}, and nonzero integers.  Negative boolean values are
1135 @samp{off}, @samp{false}, @samp{no}, and zero.
1136
1137 @item data=@var{data-type}
1138
1139 One of @code{clean7bit}, @code{clean8bit}, or @code{binary}.  This
1140 controls what characters will be written to the output file.  PostScript
1141 produced with @code{clean7bit} can be transmitted over 7-bit
1142 transmission channels that use ASCII control characters for line
1143 control.  @code{clean8bit} is similar but allows characters above 127 to
1144 be written to the output file.  @code{binary} allows any character in
1145 the output file.  Default: @code{clean7bit}.
1146
1147 @item line-ends=@var{line-end-type}
1148
1149 One of @code{cr}, @code{lf}, or @code{crlf}.  This controls what is used
1150 for newline in the output file.  Default: @code{cr}.
1151
1152 @item optimize-line-size=@var{level}
1153
1154 Either @code{0} or @code{1}.  If @var{level} is @code{1}, then short
1155 line segments will be collected and merged into longer ones.  This
1156 reduces output file size but requires more time and memory.  A
1157 @var{level} of @code{0} has the advantage of being better for
1158 interactive environments.  @code{1} is the default unless the
1159 @code{screen} flag is set; in that case, the default is @code{0}.
1160
1161 @item optimize-text-size=@var{level}
1162
1163 One of @code{0}, @code{1}, or @code{2}, each higher level representing
1164 correspondingly more aggressive space savings for text in the output
1165 file and requiring correspondingly more time and memory.  Unfortunately
1166 the levels presently are all the same.  @code{1} is the default unless
1167 the @code{screen} flag is set; in that case, the default is @code{0}.
1168 @end table
1169
1170 @node PS page options, PS file options, PS output options, PostScript driver class
1171 @subsection PostScript page options
1172
1173 These options affect page setup:
1174
1175 @table @code
1176 @item headers=@var{boolean}
1177
1178 Controls whether the standard headers showing the time and date and
1179 title and subtitle are printed at the top of each page.  Default:
1180 @code{on}.
1181
1182 @item paper-size=@var{paper-size}
1183
1184 Paper size, either as a symbolic name (i.e., @code{letter} or @code{a4})
1185 or specific measurements (i.e., @code{8-1/2x11} or @code{"210 x 297"}.
1186 @xref{papersize, , Paper sizes}.  Default: @code{letter}.
1187
1188 @item orientation=@var{orientation}
1189
1190 Either @code{portrait} or @code{landscape}.  Default: @code{portrait}.
1191
1192 @item left-margin=@var{dimension}
1193 @itemx right-margin=@var{dimension}
1194 @itemx top-margin=@var{dimension}
1195 @itemx bottom-margin=@var{dimension}
1196
1197 Sets the margins around the page.  The headers, if enabled, are not
1198 included in the margins; they are in addition to the margins.  For a
1199 description of dimensions, see @ref{Dimensions}.  Default: @code{0.5in}.
1200
1201 @end table
1202
1203 @node PS file options, PS font options, PS page options, PostScript driver class
1204 @subsection PostScript file options
1205
1206 Oh, my.  You don't really want to know about the way that the PostScript
1207 driver deals with files, do you?  Well I suppose you're entitled, but I
1208 warn you right now: it's not pretty.  Here goes@enddots{}
1209
1210 First let's look at the options that are available:
1211
1212 @table @code
1213
1214 @item font-dir=@var{font-directory}
1215
1216 Sets the font directory.  Default: @code{devps}.
1217
1218 @item prologue-file=@var{prologue-file-name}
1219
1220 Sets the name of the PostScript prologue file.  You can write your own
1221 prologue, though I have no idea why you'd want to: see @ref{Prologue}.
1222 Default: @code{ps-prologue}.
1223
1224 @item device-file=@var{device-file-name}
1225
1226 Sets the name of the Groff-format device description file.  The
1227 PostScript driver reads this in order to know about the scaling of fonts
1228 and so on.  The format of such files is described in groff_font(5),
1229 included with Groff.  Default: @code{DESC}.
1230
1231 @item encoding-file=@var{encoding-file-name}
1232
1233 Sets the name of the encoding file.  This file contains a list of all
1234 font encodings that will be needed so that the driver can put all of
1235 them at the top of the prologue.  @xref{Encodings}.  Default:
1236 @code{ps-encodings}.
1237
1238 If the specified encoding file cannot be found, this error will be
1239 silently ignored, since most people do not need any encodings besides
1240 the ones that can be found using @code{auto-encodings}, described below.
1241
1242 @item auto-encode=@var{boolean}
1243
1244 When enabled, the font encodings needed by the default proportional- and
1245 fixed-pitch fonts will automatically be dumped to the PostScript
1246 output.  Otherwise, it is assumed that the user has an encoding file
1247 and knows how to use it (@pxref{Encodings}).  There is probably no good
1248 reason to turn off this convenient feature.  Default: @code{on}.
1249
1250 @end table
1251
1252 Next I suppose it's time to describe the search algorithm.  When the
1253 PostScript driver needs a file, whether that file be a font, a
1254 PostScript prologue, or what you will, it searches in this manner:
1255
1256 @enumerate
1257
1258 @item
1259 Constructs a path by taking the first of the following that is defined:
1260
1261 @enumerate a
1262
1263 @item
1264 Environment variable @code{STAT_GROFF_FONT_PATH}.  @xref{Environment
1265 variables}.
1266
1267 @item
1268 Environment variable @code{GROFF_FONT_PATH}.
1269
1270 @item
1271 The compiled-in fallback default.
1272 @end enumerate
1273
1274 @item
1275 Constructs a base name from concatenating, in order, the font directory,
1276 a path separator (@samp{/} or @samp{\}), and the file to be found.  A
1277 typical base name would be something like @code{devps/ps-encodings}.
1278
1279 @item
1280 Searches for the base name in the path constructed above.  If the file
1281 is found, the algorithm terminates.
1282
1283 @item
1284 Searches for the base name in the standard configuration path.  See
1285 @ref{File locations}, for more details.  If the file is found, the
1286 algorithm terminates.
1287
1288 @item
1289 At this point we remove the font directory and path separator from the
1290 base name.  Now the base name is simply the file to be found, i.e.,
1291 @code{ps-encodings}.
1292
1293 @item
1294 Searches for the base name in the path constructed in the first step.
1295 If the file is found, the algorithm terminates.
1296
1297 @item
1298 Searches for the base name in the standard configuration path.  If the
1299 file is found, the algorithm terminates.
1300
1301 @item
1302 The algorithm terminates unsuccessfully.
1303 @end enumerate
1304
1305 So, as you see, there are several ways to configure the PostScript
1306 drivers.  Careful selection of techniques can make the configuration
1307 very flexible indeed.
1308
1309 @node PS font options, PS line options, PS file options, PostScript driver class
1310 @subsection PostScript font options
1311
1312 The list of available font options is short and sweet:
1313
1314 @table @code
1315 @item prop-font=@var{font-name}
1316
1317 Sets the default proportional font.  The name should be that of a
1318 PostScript font.  Default: @code{"Helvetica"}.
1319
1320 @item fixed-font=@var{font-name}
1321
1322 Sets the default fixed-pitch font.  The name should be that of a
1323 PostScript font.  Default: @code{"Courier"}.
1324
1325 @item font-size=@var{font-size}
1326
1327 Sets the size of the default fonts, in thousandths of a point.  Default:
1328 @code{10000}.
1329
1330 @end table
1331
1332 @node PS line options, Prologue, PS font options, PostScript driver class
1333 @subsection PostScript line options
1334
1335 Most tables contain lines, or rules, between cells.  Some features of
1336 the way that lines are drawn in PostScript tables are user-definable:
1337
1338 @table @code
1339
1340 @item line-style=@var{style}
1341
1342 Sets the style used for lines used to divide tables into sections.
1343 @var{style} must be either @code{thick}, in which case thick lines are
1344 used, or @var{double}, in which case double lines are used.  Default:
1345 @code{thick}.
1346
1347 @item line-gutter=@var{dimension}
1348
1349 Sets the line gutter, which is the amount of whitespace on either side
1350 of lines that border text or graphics objects.  @xref{Dimensions}.
1351 Default: @code{0.5pt}.
1352
1353 @item line-spacing=@var{dimension}
1354
1355 Sets the line spacing, which is the amount of whitespace that separates
1356 lines that are side by side, as in a double line.  Default:
1357 @code{0.5pt}.
1358
1359 @item line-width=@var{dimension}
1360
1361 Sets the width of a typical line used in tables.  Default: @code{0.5pt}.
1362
1363 @item line-width-thick=@var{dimension}
1364
1365 Sets the width of a thick line used in tables.  Not used if
1366 @code{line-style} is set to @code{thick}.  Default: @code{1.5pt}.
1367
1368 @end table
1369
1370 @node Prologue, Encodings, PS line options, PostScript driver class
1371 @subsection The PostScript prologue
1372
1373 Most PostScript files that are generated mechanically by programs
1374 consist of two parts: a prologue and a body.  The prologue is generally
1375 a collection of boilerplate.  Only the body differs greatly between
1376 two outputs from the same program.
1377  
1378 This is also the strategy used in the PSPP PostScript driver.  In
1379 general, the prologue supplied with PSPP will be more than sufficient.
1380 In this case, you will not need to read the rest of this section.
1381 However, hackers might want to know more.  Read on, if you fall into
1382 this category.
1383
1384 The prologue is dumped into the output stream essentially unmodified.
1385 However, two actions are performed on its lines.  First, certain lines
1386 may be omitted as specified in the prologue file itself.  Second,
1387 variables are substituted.
1388
1389 The following lines are omitted:
1390
1391 @enumerate
1392 @item
1393 All lines that contain three bangs in a row (@code{!!!}).
1394
1395 @item
1396 Lines that contain @code{!eps}, if the PostScript driver is producing
1397 ordinary PostScript output.  Otherwise an EPS file is being produced,
1398 and the line is included in the output, although everything following
1399 @code{!eps} is deleted.
1400
1401 @item
1402 Lines that contain @code{!ps}, if the PostScript driver is producing EPS
1403 output.  Otherwise, ordinary PostScript is being produced, and the line
1404 is included in the output, although everything following @code{!ps} is
1405 deleted.
1406 @end enumerate
1407
1408 The following are the variables that are substituted.  Only the
1409 variables listed are substituted; environment variables are not.
1410 @xref{Environment substitutions}.
1411
1412 @table @code
1413 @item bounding-box
1414
1415 The page bounding box, in points, as four space-separated numbers.  For
1416 U.S. letter size paper, this is @samp{0 0 612 792}.
1417
1418 @item creator
1419
1420 PSPP version as a string: @samp{GNU PSPP 0.1b}, for example.
1421
1422 @item date
1423
1424 Date the file was created.  Example: @samp{Tue May 21 13:46:22 1991}.
1425
1426 @item data
1427
1428 Value of the @code{data} PostScript driver option, as one of the strings
1429 @samp{Clean7Bit}, @samp{Clean8Bit}, or @samp{Binary}.
1430
1431 @item orientation
1432
1433 Page orientation, as one of the strings @code{Portrait} or
1434 @code{Landscape}.
1435
1436 @item user
1437
1438 Under multiuser OSes, the user's login name, taken either from the
1439 environment variable @code{LOGNAME} or, if that fails, the result of the
1440 C library function @code{getlogin()}.  Defaults to @samp{nobody}.
1441
1442 @item host
1443
1444 System hostname as reported by @code{gethostname()}.  Defaults to
1445 @samp{nowhere}.
1446
1447 @item prop-font
1448
1449 Name of the default proportional font, prefixed by the word
1450 @samp{font} and a space.  Example: @samp{font Times-Roman}.
1451
1452 @item fixed-font
1453
1454 Name of the default fixed-pitch font, prefixed by the word @samp{font}
1455 and a space.
1456
1457 @item scale-factor
1458
1459 The page scaling factor as a floating-point number.  Example:
1460 @code{1.0}.  Note that this is also passed as an argument to the BP
1461 macro.
1462
1463 @item paper-length
1464 @item paper-width
1465
1466 The paper length and paper width, respectively, in thousandths of a
1467 point.  Note that these are also passed as arguments to the BP macro.
1468
1469 @item left-margin
1470 @item top-margin
1471
1472 The left margin and top margin, respectively, in thousandths of a
1473 point.  Note that these are also passed as arguments to the BP macro.
1474
1475 @item title
1476
1477 Document title as a string.  This is not the title specified in the
1478 PSPP syntax file.  A typical title is the word @samp{PSPP} followed
1479 by the syntax file name in parentheses.  Example: @samp{PSPP
1480 (<stdin>)}.
1481
1482 @item source-file
1483
1484 PSPP syntax file name.  Example: @samp{mary96/first.stat}.
1485
1486 @end table
1487
1488 Any other questions about the PostScript prologue can best be answered
1489 by examining the default prologue or the PSPP source.
1490
1491 @node Encodings,  , Prologue, PostScript driver class
1492 @subsection PostScript encodings
1493
1494 PostScript fonts often contain many more than 256 characters, in order
1495 to accommodate foreign language characters and special symbols.
1496 PostScript uses @dfn{encodings} to map these onto single-byte symbol
1497 sets.  Each font can have many different encodings applied to it.
1498
1499 PSPP's PostScript driver needs to know which encoding to apply to each
1500 font.  It can determine this from the information encapsulated in the
1501 Groff font description that it reads.  However, there is an additional
1502 problem---for efficiency, the PostScript driver needs to have a complete
1503 list of all encodings that will be used in the entire session @emph{when
1504 it opens the output file}.  For this reason, it can't use the
1505 information built into the fonts because it doesn't know which fonts
1506 will be used.
1507
1508 As a stopgap solution, there are two mechanisms for specifying which
1509 encodings will be used.  The first mechanism is automatic and it is the
1510 only one that most PSPP users will ever need.  The second mechanism is
1511 manual, but it is more flexible.  Either mechanism or both may be used
1512 at one time.
1513
1514 The first mechanism is activated by the @samp{auto-encode} driver option
1515 (@pxref{PS file options}).  When enabled, @samp{auto-encode} causes the
1516 PostScript driver to include the encodings used by the default
1517 proportional and fixed-pitch fonts (@pxref{PS font options}).  Many
1518 PSPP output files will only need these encodings.
1519
1520 The second mechanism is the file specified by the @samp{encoding-file}
1521 option (@pxref{PS file options}).  If it exists, this file must consist
1522 of lines in PSPP configuration-file format (@pxref{Configuration
1523 files}).  Each line that is not a comment should name a PostScript
1524 encoding to include in the output.
1525
1526 It is not an error if an encoding is included more than once, by either
1527 mechanism.  It will appear only once in the output.  It is also not an
1528 error if an encoding is included in the output but never used.  It
1529 @emph{is} an error if an encoding is used but not included by one of
1530 these mechanisms.  In this case, the built-in PostScript encoding
1531 @samp{ISOLatin1Encoding} is substituted.
1532
1533 @node ASCII driver class, HTML driver class, PostScript driver class, Configuration
1534 @section The ASCII driver class
1535
1536 The ASCII driver class produces output that can be displayed on a
1537 terminal or output to printers.  All of its options are highly
1538 configurable.  The ASCII driver has class name @samp{ascii}.
1539
1540 The ASCII driver is described in further detail below.
1541
1542 @menu
1543 * ASCII output options::        Output file options.
1544 * ASCII page options::          Page size, margins, more.
1545 * ASCII font options::          Box character, bold & italics.
1546 @end menu
1547
1548 @node ASCII output options, ASCII page options, ASCII driver class, ASCII driver class
1549 @subsection ASCII output options
1550
1551 @table @code
1552 @item output-file=@var{filename}
1553
1554 File to which output should be sent.  This can be an ordinary filename
1555 (i.e., @code{"pspp.ps"}), a pipe filename (i.e., @code{"|lpr"}), or
1556 stdout (@code{"-"}).  Default: @code{"pspp.list"}.
1557
1558 @item char-set=@var{char-set-type}
1559
1560 One of @samp{ascii} or @samp{latin1}.  This has no effect on output at
1561 the present time.  Default: @code{ascii}.
1562
1563 @item form-feed-string=@var{form-feed-value}
1564
1565 The string written to the output to cause a formfeed.  See also
1566 @code{paginate}, described below, for a related setting.  Default:
1567 @code{"\f"}.
1568
1569 @item newline-string=@var{newline-value}
1570
1571 The string written to the output to cause a newline (carriage return
1572 plus linefeed).  The default, which can be specified explicitly with
1573 @code{newline-string=default}, is to use the system-dependent newline
1574 sequence by opening the output file in text mode.  This is usually the
1575 right choice.
1576
1577 However, @code{newline-string} can be set to any string.  When this is
1578 done, the output file is opened in binary mode.
1579
1580 @item paginate=@var{boolean}
1581
1582 If set, a formfeed (as set in @code{form-feed-string}, described above)
1583 will be written to the device after every page.  Default: @code{on}.
1584
1585 @item tab-width=@var{tab-width-value}
1586
1587 The distance between tab stops for this device.  If set to 0, tabs will
1588 not be used in the output.  Default: @code{8}.
1589
1590 @item init=@var{initialization-string}.
1591
1592 String written to the device before anything else, at the beginning of
1593 the output.  Default: @code{""} (the empty string).
1594
1595 @item done=@var{finalization-string}.
1596
1597 String written to the device after everything else, at the end of the
1598 output.  Default: @code{""} (the empty string).
1599 @end table
1600
1601 @node ASCII page options, ASCII font options, ASCII output options, ASCII driver class
1602 @subsection ASCII page options
1603
1604 These options affect page setup:
1605
1606 @table @code
1607 @item headers=@var{boolean}
1608
1609 If enabled, two lines of header information giving title and subtitle,
1610 page number, date and time, and PSPP version are printed at the top of
1611 every page.  These two lines are in addition to any top margin
1612 requested.  Default: @code{on}.
1613
1614 @item length=@var{line-count}
1615
1616 Physical length of a page, in lines.  Headers and margins are subtracted
1617 from this value.  Default: @code{66}.
1618
1619 @item width=@var{character-count}
1620
1621 Physical width of a page, in characters.  Margins are subtracted from
1622 this value.  Default: @code{130}.
1623
1624 @item lpi=@var{lines-per-inch}
1625
1626 Number of lines per vertical inch.  Not currently used.  Default: @code{6}.
1627
1628 @item cpi=@var{characters-per-inch}
1629
1630 Number of characters per horizontal inch.  Not currently used.  Default:
1631 @code{10}.
1632
1633 @item left-margin=@var{left-margin-width}
1634
1635 Width of the left margin, in characters.  PSPP subtracts this value
1636 from the page width.  Default: @code{0}.
1637
1638 @item right-margin=@var{right-margin-width}
1639
1640 Width of the right margin, in characters.  PSPP subtracts this value
1641 from the page width.  Default: @code{0}.
1642
1643 @item top-margin=@var{top-margin-lines}
1644
1645 Length of the top margin, in lines.  PSPP subtracts this value from
1646 the page length.  Default: @code{2}.
1647
1648 @item bottom-margin=@var{bottom-margin-lines}
1649
1650 Length of the bottom margin, in lines.  PSPP subtracts this value from
1651 the page length.  Default: @code{2}.
1652
1653 @end table
1654
1655 @node ASCII font options,  , ASCII page options, ASCII driver class
1656 @subsection ASCII font options
1657
1658 These are the ASCII font options:
1659
1660 @table @code
1661 @item box[@var{line-type}]=@var{box-chars}
1662
1663 The characters used for lines in tables produced by the ASCII driver can
1664 be changed using this option.  @var{line-type} is used to indicate which
1665 type of line to change; @var{box-chars} is the character or string of
1666 characters to use for this type of line.
1667
1668 @var{line-type} must be a 4-digit number in base 4.  The digits are in
1669 the order `right', `bottom', `left', `top'.  The four possibilities for
1670 each digit are:
1671
1672 @table @asis
1673 @item 0
1674 No line.
1675
1676 @item 1
1677 Single line.
1678
1679 @item 2
1680 Double line.
1681
1682 @item 3
1683 Special device-defined line, if one is available; otherwise, a double
1684 line.
1685 @end table
1686
1687 Examples:
1688
1689 @table @code
1690 @item box[0101]="|"
1691
1692 Sets @samp{|} as the character to use for a single-width line with
1693 bottom and top components.
1694
1695 @item box[2222]="#"
1696
1697 Sets @samp{#} as the character to use for the intersection of four
1698 double-width lines, one each from the top, bottom, left and right.
1699
1700 @item box[1100]="\xda"
1701
1702 Sets @samp{"\xda"}, which under MS-DOG is a box character suitable for
1703 the top-left corner of a box, as the character for the intersection of
1704 two single-width lines, one each from the right and bottom.
1705
1706 @end table
1707
1708 Defaults:
1709
1710 @itemize @bullet
1711 @item
1712 @code{box[0000]=" "}
1713
1714 @item
1715 @code{box[1000]="-"}
1716 @*@code{box[0010]="-"}
1717 @*@code{box[1010]="-"}
1718
1719 @item
1720 @code{box[0100]="|"}
1721 @*@code{box[0001]="|"}
1722 @*@code{box[0101]="|"}
1723
1724 @item
1725 @code{box[2000]="="}
1726 @*@code{box[0020]="="}
1727 @*@code{box[2020]="="}
1728
1729 @item
1730 @code{box[0200]="#"}
1731 @*@code{box[0002]="#"}
1732 @*@code{box[0202]="#"}
1733
1734 @item
1735 @code{box[3000]="="}
1736 @*@code{box[0030]="="}
1737 @*@code{box[3030]="="}
1738
1739 @item
1740 @code{box[0300]="#"}
1741 @*@code{box[0003]="#"}
1742 @*@code{box[0303]="#"}
1743
1744 @item
1745 For all others, @samp{+} is used unless there are double lines or
1746 special lines, in which case @samp{#} is used.
1747 @end itemize
1748
1749 @item italic-on=@var{italic-on-string}
1750
1751 Character sequence written to turn on italics or underline printing.  If
1752 this is set to @code{overstrike}, then the driver will simulate
1753 underlining by overstriking with underscore characters (@samp{_}) in the
1754 manner described by @code{overstrike-style} and
1755 @code{carriage-return-style}.  Default: @code{overstrike}.
1756
1757 @item italic-off=@var{italic-off-string}
1758
1759 Character sequence to turn off italics or underline printing.  Default:
1760 @code{""} (the empty string).
1761
1762 @item bold-on=@var{bold-on-string}
1763
1764 Character sequence written to turn on bold or emphasized printing.  If
1765 set to @code{overstrike}, then the driver will simulated bold printing
1766 by overstriking characters in the manner described by
1767 @code{overstrike-style} and @code{carriage-return-style}.  Default:
1768 @code{overstrike}.
1769
1770 @item bold-off=@var{bold-off-string}
1771
1772 Character sequence to turn off bold or emphasized printing.  Default:
1773 @code{""} (the empty string).
1774
1775 @item bold-italic-on=@var{bold-italic-on-string}
1776
1777 Character sequence written to turn on bold-italic printing.  If set to
1778 @code{overstrike}, then the driver will simulate bold-italics by
1779 overstriking twice, once with the character, a second time with an
1780 underscore (@samp{_}) character, in the manner described by
1781 @code{overstrike-style} and @code{carriage-return-style}.  Default:
1782 @code{overstrike}.
1783
1784 @item bold-italic-off=@var{bold-italic-off-string}
1785
1786 Character sequence to turn off bold-italic printing.  Default: @code{""}
1787 (the empty string).
1788
1789 @item overstrike-style=@var{overstrike-option}
1790
1791 Either @code{single} or @code{line}:
1792
1793 @itemize @bullet
1794 @item
1795 If @code{single} is selected, then, to overstrike a line of text, the
1796 output driver will output a character, backspace, overstrike, output a
1797 character, backspace, overstrike, and so on along a line.
1798
1799 @item
1800 If @code{line} is selected then the output driver will output an entire
1801 line, then backspace or emit a carriage return (as indicated by
1802 @code{carriage-return-style}), then overstrike the entire line at once.
1803 @end itemize
1804
1805 @code{single} is recommended for use with ttys and programs that
1806 understand overstriking in text files, such as the pager @code{less}.
1807 @code{single} will also work with printer devices but results in rapid
1808 back-and-forth motions of the printhead that can cause the printer to
1809 physically overheat!
1810
1811 @code{line} is recommended for use with printer devices.  Most programs
1812 that understand overstriking in text files will not properly deal with
1813 @code{line} mode.  
1814
1815 Default: @code{single}.
1816
1817 @item carriage-return-style=@var{carriage-return-type}
1818
1819 Either @code{bs} or @code{cr}.  This option applies only when one or
1820 more of the font commands is set to @code{overstrike} and, at the same
1821 time, @code{overstrike-style} is set to @code{line}.
1822
1823 @itemize @bullet
1824 @item
1825 If @code{bs} is selected then the driver will return to the beginning of
1826 a line by emitting a sequence of backspace characters (ASCII 8).
1827
1828 @item
1829 If @code{cr} is selected then the driver will return to the beginning of
1830 a line by emitting a single carriage-return character (ASCII 13).
1831 @end itemize
1832
1833 Although @code{cr} is preferred as being more compact, @code{bs} is more
1834 general since some devices do not interpret carriage returns in the
1835 desired manner.  Default: @code{bs}.
1836 @end table
1837
1838 @node HTML driver class, Miscellaneous configuring, ASCII driver class, Configuration
1839 @section The HTML driver class
1840
1841 The @code{html} driver class is used to produce output for viewing in
1842 tables-capable web browsers such as Emacs' w3-mode.  Its configuration
1843 is very simple.  Currently, the output has a very plain format.  In the
1844 future, further work may be done on improving the output appearance.
1845
1846 There are few options for use with the @code{html} driver class:
1847
1848 @table @code
1849 @item output-file=@var{filename}
1850
1851 File to which output should be sent.  This can be an ordinary filename
1852 (i.e., @code{"pspp.ps"}), a pipe filename (i.e., @code{"|lpr"}), or
1853 stdout (@code{"-"}).  Default: @code{"pspp.html"}.
1854
1855 @item prologue-file=@var{prologue-file-name}
1856
1857 Sets the name of the PostScript prologue file.  You can write your own
1858 prologue if you want to customize colors or other settings: see
1859 @ref{HTML Prologue}.  Default: @code{html-prologue}.
1860 @end table
1861
1862 @menu
1863 * HTML Prologue::               Format of the HTML prologue file.
1864 @end menu
1865
1866 @node HTML Prologue,  , HTML driver class, HTML driver class
1867 @subsection The HTML prologue
1868
1869 HTML files that are generated by PSPP consist of two parts: a prologue
1870 and a body.  The prologue is a collection of boilerplate.  Only the body
1871 differs greatly between two outputs.  You can tune the colors and other
1872 attributes of the output by editing the prologue.
1873  
1874 The prologue is dumped into the output stream essentially unmodified.
1875 However, two actions are performed on its lines.  First, certain lines
1876 may be omitted as specified in the prologue file itself.  Second,
1877 variables are substituted.
1878
1879 The following lines are omitted:
1880
1881 @enumerate
1882 @item
1883 All lines that contain three bangs in a row (@code{!!!}).
1884
1885 @item
1886 Lines that contain @code{!title}, if no title is set for the output.  If
1887 a title is set, then the characters @code{!title} are removed before the
1888 line is output.
1889
1890 @item
1891 Lines that contain @code{!subtitle}, if no subtitle is set for the
1892 output.  If a subtitle is set, then the characters @code{!subtitle} are
1893 removed before the line is output.
1894 @end enumerate
1895
1896 The following are the variables that are substituted.  Only the
1897 variables listed are substituted; environment variables are not.
1898 @xref{Environment substitutions}.
1899
1900 @table @code
1901 @item generator
1902
1903 PSPP version as a string: @samp{GNU PSPP 0.1b}, for example.
1904
1905 @item date
1906
1907 Date the file was created.  Example: @samp{Tue May 21 13:46:22 1991}.
1908
1909 @item user
1910
1911 Under multiuser OSes, the user's login name, taken either from the
1912 environment variable @code{LOGNAME} or, if that fails, the result of the
1913 C library function @code{getlogin()}.  Defaults to @samp{nobody}.
1914
1915 @item host
1916
1917 System hostname as reported by @code{gethostname()}.  Defaults to
1918 @samp{nowhere}.
1919
1920 @item title
1921
1922 Document title as a string.  This is the title specified in the PSPP
1923 syntax file.
1924
1925 @item subtitle
1926
1927 Document subtitle as a string.  
1928
1929 @item source-file
1930
1931 PSPP syntax file name.  Example: @samp{mary96/first.stat}.
1932 @end table
1933
1934 @node Miscellaneous configuring, Improving output quality, HTML driver class, Configuration
1935 @section Miscellaneous configuration
1936
1937 The following environment variables can be used to further configure
1938 PSPP:
1939
1940 @table @code
1941 @item HOME
1942
1943 Used to determine the user's home directory.  No default value.
1944
1945 @item STAT_INCLUDE_PATH
1946
1947 Path used to find include files in PSPP syntax files.  Defaults vary
1948 across operating systems:
1949
1950 @table @asis
1951 @item UNIX
1952
1953 @itemize @bullet
1954 @item
1955 @file{.}
1956
1957 @item
1958 @file{~/.pspp/include}
1959
1960 @item
1961 @file{/usr/local/lib/pspp/include}
1962
1963 @item
1964 @file{/usr/lib/pspp/include}
1965
1966 @item
1967 @file{/usr/local/share/pspp/include}
1968
1969 @item
1970 @file{/usr/share/pspp/include}
1971 @end itemize
1972
1973 @item MS-DOS
1974
1975 @itemize @bullet
1976 @item
1977 @file{.}
1978
1979 @item
1980 @file{C:\PSPP\INCLUDE}
1981
1982 @item
1983 @file{$PATH}
1984 @end itemize
1985
1986 @item Other OSes
1987 No default path.
1988 @end table
1989
1990 @item STAT_PAGER
1991 @itemx PAGER
1992
1993 When PSPP invokes an external pager, it uses the first of these that
1994 is defined.  There is a default pager only if the person who compiled
1995 PSPP defined one.
1996
1997 @item TERM
1998
1999 The terminal type @code{termcap} or @code{ncurses} will use, if such
2000 support was compiled into PSPP.
2001
2002 @item STAT_OUTPUT_INIT_FILE
2003
2004 The basename used to search for the driver definition file.
2005 @xref{Output devices}.  @xref{File locations}.  Default: @code{devices}.
2006
2007 @item STAT_OUTPUT_PAPERSIZE_FILE
2008
2009 The basename used to search for the papersize file.  @xref{papersize}.
2010 @xref{File locations}.  Default: @code{papersize}.
2011
2012 @item STAT_OUTPUT_INIT_PATH
2013
2014 The path used to search for the driver definition file and the papersize
2015 file.  @xref{File locations}.  Default: the standard configuration path.
2016
2017 @item TMPDIR
2018
2019 The @code{sort} procedure stores its temporary files in this directory.
2020 Default: (UNIX) @file{/tmp}, (MS-DOS) @file{\}, (other OSes) empty string.
2021
2022 @item TEMP
2023 @item TMP
2024
2025 Under MS-DOS only, these variables are consulted after TMPDIR, in this
2026 order.
2027 @end table
2028
2029 @node Improving output quality,  , Miscellaneous configuring, Configuration
2030 @section Improving output quality
2031
2032 When its drivers are set up properly, PSPP can produce output that
2033 looks very good indeed.  The PostScript driver, suitably configured, can
2034 produce presentation-quality output.  Here are a few guidelines for
2035 producing better-looking output, regardless of output driver.  Your
2036 mileage may vary, of course, and everyone has different esthetic
2037 preferences.
2038
2039 @itemize @bullet
2040 @item
2041 Width is important in PSPP output.  Greater output width leads to more
2042 readable output, to a point.  Try the following to increase the output
2043 width:
2044
2045 @itemize @minus
2046 @item
2047 If you're using the ASCII driver with a dot-matrix printer, figure out
2048 what you need to do to put the printer into compressed mode.  Put that
2049 string into the @code{init-string} setting.  Try to get 132 columns; 160
2050 might be better, but you might find that print that tiny is difficult to
2051 read.
2052
2053 @item
2054 With the PostScript driver, try these ideas:
2055
2056 @itemize +
2057 @item
2058 Landscape mode.
2059
2060 @item
2061 Legal-size (8.5" x 14") paper in landscape mode.
2062
2063 @item
2064 Reducing font sizes.  If you're using 12-point fonts, try 10 point; if
2065 you're using 10-point fonts, try 8 point.  Some fonts are more readable
2066 than others at small sizes.
2067 @end itemize
2068 @end itemize
2069
2070 Try to strike a balance between character size and page width.
2071
2072 @item
2073 Use high-quality fonts.  Many public domain fonts are poor in quality.
2074 Recently, URW made some high-quality fonts available under the GPL.
2075 These are probably suitable.
2076
2077 @item
2078 Be sure you're using the proper font metrics.  The font metrics provided
2079 with PSPP may not correspond to the fonts actually being printed.
2080 This can cause bizarre-looking output.
2081
2082 @item
2083 Make sure that you're using good ink/ribbon/toner.  Darker print is
2084 easier to read.
2085
2086 @item
2087 Use plain fonts with serifs, such as Times-Roman or Palatino.  Avoid
2088 choosing italic or bold fonts as document base fonts.
2089 @end itemize
2090
2091 @node Invocation, Language, Configuration, Top
2092 @chapter Invoking PSPP
2093 @cindex invocation
2094 @cindex PSPP, invoking
2095
2096 @cindex command line, options
2097 @cindex options, command-line
2098 @example
2099 pspp [ -B @var{dir} | --config-dir=@var{dir} ] [ -o @var{device} | --device=@var{device} ]
2100        [ -d @var{var}[=@var{value}] | --define=@var{var}[=@var{value}] ] [-u @var{var} | --undef=@var{var} ]
2101        [ -f @var{file} | --out-file=@var{file} ] [ -p | --pipe ] [ -I- | --no-include ]
2102        [ -I @var{dir} | --include=@var{dir} ] [ -i | --interactive ] 
2103        [ -n | --edit | --dry-run | --just-print | --recon ] 
2104        [ -r | --no-statrc ] [ -h | --help ] [ -l | --list ] 
2105        [ -c @var{command} | --command @var{command} ] [ -s | --safer ]
2106        [ --testing-mode ] [ -V | --version ] [ -v | --verbose ] 
2107        [ @var{key}=@var{value} ] @var{file}@enddots{}
2108 @end example
2109
2110 @menu
2111 * Non-option Arguments::        Specifying syntax files and output devices.
2112 * Configuration Options::       Change the configuration for the current run.
2113 * Input and output options::    Controlling input and output files.
2114 * Language control options::    Language variants.
2115 * Informational options::       Helpful information about PSPP.
2116 @end menu
2117
2118 @node Non-option Arguments, Configuration Options, Invocation, Invocation
2119 @section Non-option Arguments
2120
2121 Syntax files and output device substitutions can be specified on
2122 PSPP's command line:
2123
2124 @table @code
2125 @item @var{file}
2126
2127 A file by itself on the command line will be executed as a syntax file.
2128 PSPP terminates after the syntax file runs, unless the @code{-i} or
2129 @code{--interactive} option is given (@pxref{Language control options}).
2130
2131 @item @var{file1} @var{file2}
2132
2133 When two or more filenames are given on the command line, the first
2134 syntax file is executed, then PSPP's dictionary is cleared, then the second
2135 syntax file is executed.
2136
2137 @item @var{file1} + @var{file2}
2138
2139 If syntax files' names are delimited by a plus sign (@samp{+}), then the
2140 dictionary is not cleared between their executions, as if they were
2141 concatenated together into a single file.
2142
2143 @item @var{key}=@var{value}
2144
2145 Defines an output device macro @var{key} to expand to @var{value},
2146 overriding any macro having the same @var{key} defined in the device
2147 configuration file.  @xref{Macro definitions}.
2148
2149 @end table
2150
2151 There is one other way to specify a syntax file, if your operating
2152 system supports it.  If you have a syntax file @file{foobar.stat}, put
2153 the notation
2154
2155 @example
2156 #! /usr/local/bin/pspp
2157 @end example
2158
2159 at the top, and mark the file as executable with @code{chmod +x
2160 foobar.stat}.  (If PSPP is not installed in @file{/usr/local/bin},
2161 then insert its actual installation directory into the syntax file
2162 instead.)  Now you should be able to invoke the syntax file just by
2163 typing its name.  You can include any options on the command line as
2164 usual.  PSPP entirely ignores any lines beginning with @samp{#!}.
2165
2166 @node Configuration Options, Input and output options, Non-option Arguments, Invocation
2167 @section Configuration Options
2168
2169 Configuration options are used to change PSPP's configuration for the
2170 current run.  The configuration options are:
2171
2172 @table @code
2173 @item -B @var{dir}
2174 @itemx --config-dir=@var{dir}
2175
2176 Sets the configuration directory to @var{dir}.  @xref{File locations}.
2177
2178 @item -o @var{device}
2179 @itemx --device=@var{device}
2180
2181 Selects the output device with name @var{device}.  If this option is
2182 given more than once, then all devices mentioned are selected.  This
2183 option disables all devices besides those mentioned on the command line.
2184
2185 @item -d @var{var}[=@var{value}]
2186 @itemx --define=@var{var}[=@var{value}]
2187
2188 Defines an `environment variable' named @var{var} having the optional
2189 value @var{value} specified.  @xref{Variable values}.
2190
2191 @item -u @var{var}
2192 @itemx --undef=@var{var}
2193
2194 Undefines the `environment variable' named @var{var}.  @xref{Variable
2195 values}.
2196 @end table
2197
2198 @node Input and output options, Language control options, Configuration Options, Invocation
2199 @section Input and output options
2200
2201 Input and output options affect how PSPP reads input and writes
2202 output.  These are the input and output options:
2203
2204 @table @code
2205 @item -f @var{file}
2206 @itemx --out-file=@var{file}
2207
2208 This overrides the output file name for devices designated as listing
2209 devices.  If a file named @var{file} already exists, it is overwritten.
2210
2211 @item -p
2212 @itemx --pipe
2213
2214 Allows PSPP to be used as a filter by causing the syntax file to be
2215 read from stdin and output to be written to stdout.  Conflicts with the
2216 @code{-f @var{file}} and @code{--file=@var{file}} options.
2217
2218 @item -I-
2219 @itemx --no-include
2220
2221 Clears all directories from the include path.  This includes all
2222 directories put in the include path by default.  @xref{Miscellaneous
2223 configuring}.
2224
2225 @item -I @var{dir}
2226 @itemx --include=@var{dir}
2227
2228 Appends directory @var{dir} to the path that is searched for include
2229 files in PSPP syntax files.
2230
2231 @item -c @var{command}
2232 @itemx --command=@var{command}
2233
2234 Execute literal command @var{command}.  The command is executed before
2235 startup syntax files, if any.
2236
2237 @item --testing-mode
2238
2239 Invoke heuristics to assist with testing PSPP.  For use by @code{make
2240 check} and similar scripts.
2241 @end table
2242
2243 @node Language control options, Informational options, Input and output options, Invocation
2244 @section Language control options
2245
2246 Language control options control how PSPP syntax files are parsed and
2247 interpreted.  The available language control options are:
2248
2249 @table @code
2250 @item -i
2251 @itemx --interactive
2252
2253 When a syntax file is specified on the command line, PSPP normally
2254 terminates after processing it.  Giving this option will cause PSPP to
2255 bring up a command prompt after processing the syntax file.
2256
2257 In addition, this forces syntax files to be interpreted in interactive
2258 mode, rather than the default batch mode.  @xref{Tokenizing lines}, for
2259 information on the differences between batch mode and interactive mode
2260 command interpretation.
2261
2262 @item -n
2263 @itemx --edit
2264 @itemx --dry-run
2265 @itemx --just-print
2266 @itemx --recon
2267
2268 Only the syntax of any syntax file specified or of commands entered at
2269 the command line is checked.  Transformations are not performed and
2270 procedures are not executed.  Not yet implemented.
2271
2272 @item -r
2273 @itemx --no-statrc
2274
2275 Prevents the execution of the PSPP startup syntax file.  Not yet
2276 implemented, as startup syntax files aren't, either.
2277
2278 @item -s
2279 @itemx --safer
2280
2281 Disables certain unsafe operations.  This includes the @code{ERASE} and
2282 @code{HOST} commands, as well as use of pipes as input and output files.
2283 @end table
2284
2285 @node Informational options,  , Language control options, Invocation
2286 @section Informational options
2287
2288 Informational options cause information about PSPP to be written to
2289 the terminal.  Here are the available options:
2290
2291 @table @code
2292 @item -h
2293 @item --help
2294
2295 Prints a message describing PSPP command-line syntax and the available
2296 device driver classes, then terminates.
2297
2298 @item -l
2299 @item --list
2300
2301 Lists the available device driver classes, then terminates.
2302
2303 @item -V
2304 @item --version
2305
2306 Prints a brief message listing PSPP's version, warranties you don't
2307 have, copying conditions and copyright, and e-mail address for bug
2308 reports, then terminates.
2309
2310 @item -v
2311 @item --verbose
2312
2313 Increments PSPP's verbosity level.  Higher verbosity levels cause
2314 PSPP to display greater amounts of information about what it is
2315 doing.  Often useful for debugging PSPP's configuration.  
2316
2317 This option can be given multiple times to set the verbosity level to
2318 that value.  The default verbosity level is 0, in which no informational
2319 messages will be displayed.
2320
2321 Higher verbosity levels cause messages to be displayed when the
2322 corresponding events take place.
2323
2324 @table @asis
2325 @item 1
2326
2327 Driver and subsystem initializations.
2328
2329 @item 2
2330
2331 Completion of driver initializations.  Beginning of driver closings.
2332
2333 @item 3
2334
2335 Completion of driver closings.
2336
2337 @item 4
2338
2339 Files searched for; success of searches.
2340
2341 @item 5
2342
2343 Individual directories included in file searches.
2344 @end table
2345
2346 Each verbosity level also includes messages from lower verbosity levels.
2347
2348 @end table
2349
2350 @node Language, Expressions, Invocation, Top
2351 @chapter The PSPP language
2352 @cindex language, PSPP
2353 @cindex PSPP, language
2354
2355 @quotation
2356 @strong{Please note:} PSPP is not even close to completion.
2357 Only a few actual statistical procedures are implemented.  PSPP
2358 is a work in progress.
2359 @end quotation
2360
2361 This chapter discusses elements common to many PSPP commands.
2362 Later chapters will describe individual commands in detail.
2363
2364 @menu
2365 * Tokens::                      Characters combine to form tokens.
2366 * Commands::                    Tokens combine to form commands.
2367 * Types of Commands::           Commands come in several flavors.
2368 * Order of Commands::           Commands combine to form syntax files.
2369 * Missing Observations::        Handling missing observations.
2370 * Variables::                   The unit of data storage.
2371 * Files::                       Files used by PSPP.
2372 * BNF::                         How command syntax is described.
2373 @end menu
2374
2375 @node Tokens, Commands, Language, Language
2376 @section Tokens
2377 @cindex language, lexical analysis
2378 @cindex language, tokens
2379 @cindex tokens
2380 @cindex lexical analysis
2381 @cindex lexemes
2382
2383 PSPP divides most syntax file lines into series of short chunks
2384 called @dfn{tokens}, @dfn{lexical elements}, or @dfn{lexemes}.  These
2385 tokens are then grouped to form commands, each of which tells
2386 PSPP to take some action---read in data, write out data, perform
2387 a statistical procedure, etc.  The process of dividing input into tokens
2388 is @dfn{tokenization}, or @dfn{lexical analysis}.  Each type of token is
2389 described below.
2390
2391 @cindex delimiters
2392 @cindex whitespace
2393 Tokens must be separated from each other by @dfn{delimiters}.
2394 Delimiters include whitespace (spaces, tabs, carriage returns, line
2395 feeds, vertical tabs), punctuation (commas, forward slashes, etc.), and
2396 operators (plus, minus, times, divide, etc.)  Note that while whitespace
2397 only separates tokens, other delimiters are tokens in themselves.
2398
2399 @table @strong
2400 @cindex identifiers
2401 @item Identifiers
2402 Identifiers are names that specify variable names, commands, or command
2403 details.
2404
2405 @itemize @bullet
2406 @item
2407 The first character in an identifier must be a letter, @samp{#}, or
2408 @samp{@@}.  Some system identifiers begin with @samp{$}, but
2409 user-defined variables' names may not begin with @samp{$}.
2410
2411 @item
2412 The remaining characters in the identifier must be letters, digits, or
2413 one of the following special characters: 
2414
2415 @example
2416 .  _  $  #  @@
2417 @end example
2418
2419 @item
2420 @cindex variable names
2421 @cindex names, variable
2422 Variable names may be any length, but only the first 8 characters are
2423 significant.
2424
2425 @item
2426 @cindex case-sensitivity
2427 Identifiers are not case-sensitive: @code{foobar}, @code{Foobar},
2428 @code{FooBar}, @code{FOOBAR}, and @code{FoObaR} are different
2429 representations of the same identifier.
2430
2431 @item
2432 @cindex keywords
2433 Identifiers other than variable names may be abbreviated to their first
2434 3 characters if this abbreviation is unambiguous.  These identifiers are
2435 often called @dfn{keywords}.  (Unique abbreviations of more than 3
2436 characters are also accepted: @samp{FRE}, @samp{FREQ}, and
2437 @samp{FREQUENCIES} are equivalent when the last is a keyword.)
2438
2439 @item
2440 Whether an identifier is a keyword depends on the context.
2441
2442 @item
2443 @cindex keywords, reserved
2444 @cindex reserved keywords
2445 Some keywords are reserved.  These keywords may not be used in any
2446 context besides those explicitly described in this manual.  The reserved
2447 keywords are:
2448
2449 @example
2450 ALL  AND  BY  EQ  GE  GT  LE  LT  NE  NOT  OR  TO  WITH
2451 @end example
2452
2453 @item 
2454 Since keywords are identifiers, all the rules for identifiers apply.
2455 Specifically, they must be delimited as are other identifiers:
2456 @code{WITH} is a reserved keyword, but @code{WITHOUT} is a valid
2457 variable name.
2458 @end itemize
2459
2460 @cindex @samp{.}
2461 @cindex period
2462 @cindex variable names, ending with period
2463 @strong{Caution:} It is legal to end a variable name with a period, but
2464 @emph{don't do it!}  The variable name will be misinterpreted when it is
2465 the final token on a line: @code{FOO.} will be divided into two separate
2466 tokens, @samp{FOO} and @samp{.}, the @dfn{terminal dot}.
2467 @xref{Commands, , Forming commands of tokens}.
2468
2469 @item Numbers
2470 @cindex numbers
2471 @cindex integers
2472 @cindex reals
2473 Numbers may be specified as integers or reals.  Integers are internally
2474 converted into reals.  Scientific notation is not supported.  Here are
2475 some examples of valid numbers:
2476
2477 @example
2478 1234  3.14159265359  .707106781185  8945.
2479 @end example
2480
2481 @strong{Caution:} The last example will be interpreted as two tokens,
2482 @samp{8945} and @samp{.}, if it is the last token on a line.
2483
2484 @item Strings
2485 @cindex strings
2486 @cindex @samp{'}
2487 @cindex @samp{"}
2488 @cindex case-sensitivity
2489 Strings are literal sequences of characters enclosed in pairs of single
2490 quotes (@samp{'}) or double quotes (@samp{"}).
2491
2492 @itemize @bullet
2493 @item
2494 Whitespace and case of letters @emph{are} significant inside strings.
2495 @item
2496 Whitespace characters inside a string are not delimiters.
2497 @item
2498 To include single-quote characters in a string, enclose the string in
2499 double quotes.
2500 @item
2501 To include double-quote characters in a string, enclose the string in
2502 single quotes.
2503 @item
2504 It is not possible to put both single- and double-quote characters
2505 inside one string.
2506 @end itemize
2507
2508 @item Hexstrings
2509 @cindex hexstrings
2510 Hexstrings are string variants that use hex digits to specify
2511 characters.
2512
2513 @itemize @bullet
2514 @item
2515 A hexstring may be used anywhere that an ordinary string is allowed.
2516
2517 @item
2518 @cindex @samp{X'}
2519 @cindex @samp{'}
2520 A hexstring begins with @samp{X'} or @samp{x'}, and ends with @samp{'}.
2521
2522 @cindex whitespace
2523 @item
2524 No whitespace is allowed between the initial @samp{X} and @samp{'}.
2525
2526 @item
2527 Double quotes @samp{"} may be used in place of single quotes @samp{'} if
2528 done in both places.
2529
2530 @item
2531 Each pair of hex digits is internally changed into a single character
2532 with the given value.
2533
2534 @item
2535 If there is an odd number of hex digits, the missing last digit is
2536 assumed to be @samp{0}.
2537
2538 @item
2539 @cindex portability
2540 @strong{Please note:} Use of hexstrings is nonportable because the same
2541 numeric values are associated with different glyphs by different
2542 operating systems.  Therefore, their use should be confined to syntax
2543 files that will not be widely distributed.
2544
2545 @item
2546 @cindex characters, reserved
2547 @cindex 0
2548 @cindex whitespace
2549 @strong{Please note also:} The character with value 00 is reserved for
2550 internal use by PSPP.  Its use in strings causes an error and
2551 replacement with a blank space (in ASCII, hex 20, decimal 32).
2552 @end itemize
2553
2554 @item Punctuation
2555 @cindex punctuation
2556 Punctuation separates tokens; punctuators are delimiters.  These are the
2557 punctuation characters:
2558
2559 @example
2560 ,  /  =  (  )
2561 @end example
2562
2563 @item Operators
2564 @cindex operators
2565 Operators describe mathematical operations.  Some operators are delimiters:
2566
2567 @example
2568 (  )  +  -  *  /  **
2569 @end example
2570
2571 Many of the above operators are also punctuators.  Punctuators are
2572 distinguished from operators by context. 
2573
2574 The other operators are all reserved keywords.  None of these are
2575 delimiters:
2576
2577 @example
2578 AND  EQ  GE  GT  LE  LT  NE  OR
2579 @end example
2580
2581 @item Terminal Dot
2582 @cindex terminal dot
2583 @cindex dot, terminal
2584 @cindex period
2585 @cindex @samp{.}
2586 A period (@samp{.}) at the end of a line (except for whitespace) is one
2587 type of a @dfn{terminal dot}, although not every terminal dot is a
2588 period at the end of a line.  @xref{Commands, , Forming commands of
2589 tokens}.  A period is a terminal dot @emph{only}
2590 when it is at the end of a line; otherwise it is part of a
2591 floating-point number.  (A period outside a number in the middle of a
2592 line is an error.)
2593
2594 @quotation
2595 @cindex terminal dot, changing
2596 @cindex dot, terminal, changing
2597 @strong{Please note:} The character used for the @dfn{terminal dot} can
2598 be changed with the SET command.  This is strongly discouraged, and
2599 throughout all the remainder of this manual it will be assumed that the
2600 default setting is in effect.
2601 @end quotation
2602
2603 @end table
2604
2605 @node Commands, Types of Commands, Tokens, Language
2606 @section Forming commands of tokens
2607
2608 @cindex PSPP, command structure
2609 @cindex language, command structure
2610 @cindex commands, structure
2611
2612 Most PSPP commands share a common structure, diagrammed below:
2613
2614 @example
2615 @var{cmd}@dots{} [@var{sbc}[=][@var{spec} [[,]@var{spec}]@dots{}]] [[/[=][@var{spec} [[,]@var{spec}]@dots{}]]@dots{}].
2616 @end example
2617
2618 @cindex @samp{[  ]}
2619 In the above, rather daunting, expression, pairs of square brackets
2620 (@samp{[ ]}) indicate optional elements, and names such as @var{cmd}
2621 indicate parts of the syntax that vary from command to command.
2622 Ellipses (@samp{...}) indicate that the preceding part may be repeated
2623 an arbitrary number of times.  Let's pick apart what it says above:
2624
2625 @itemize @bullet
2626 @cindex commands, names
2627 @item
2628 A command begins with a command name of one or more keywords, such as
2629 @code{FREQUENCIES}, @code{DATA LIST}, or @code{N OF CASES}.  @var{cmd}
2630 may be abbreviated to its first word if that is unambiguous; each word
2631 in @var{cmd} may be abbreviated to a unique prefix of three or more
2632 characters as described above.
2633
2634 @cindex subcommands
2635 @item
2636 The command name may be followed by one or more @dfn{subcommands}:
2637
2638 @itemize @minus
2639 @item
2640 Each subcommand begins with a unique keyword, indicated by @var{sbc}
2641 above.  This is analogous to the command name.
2642
2643 @item
2644 The subcommand name is optionally followed by an equals sign (@samp{=}).
2645
2646 @item
2647 Some subcommands accept a series of one or more specifications
2648 (@var{spec}), optionally separated by commas.
2649
2650 @item
2651 Each subcommand must be separated from the next (if any) by a forward
2652 slash (@samp{/}).
2653 @end itemize
2654
2655 @cindex dot, terminal
2656 @cindex terminal dot
2657 @item
2658 Each command must be terminated with a @dfn{terminal dot}.  
2659 The terminal dot may be given one of three ways:
2660
2661 @itemize @minus
2662 @item
2663 (most commonly) A period character at the very end of a line, as
2664 described above.
2665
2666 @item
2667 (only if NULLINE is on: @xref{SET, , Setting user preferences}, for more
2668 details.)  A completely blank line.
2669
2670 @item
2671 (in batch mode only) Any line that is not indented from the left side of
2672 the page causes a terminal dot to be inserted before that line.
2673 Therefore, each command begins with a line that is flush left, followed
2674 by zero or more lines that are indented one or more characters from the
2675 left margin.
2676
2677 In batch mode, PSPP will ignore a plus sign, minus sign, or period
2678 (@samp{+}, @samp{@minus{}}, or @samp{.}) as the first character in a
2679 line.  Any of these characters as the first character on a line will
2680 begin a new command.  This allows for visual indentation of a command
2681 without that command being considered part of the previous command.
2682
2683 PSPP is in batch mode when it is reading input from a file, rather
2684 than from an interactive user.  Note that the other forms of the
2685 terminal dot may also be used in batch mode.
2686
2687 Sometimes, one encounters syntax files that are intended to be
2688 interpreted in interactive mode rather than batch mode (for instance,
2689 this can happen if a session log file is used directly as a syntax
2690 file).  When this occurs, use the @samp{-i} command line option to force
2691 interpretation in interactive mode (@pxref{Language control options}).
2692 @end itemize
2693 @end itemize
2694
2695 PSPP ignores empty commands when they are generated by the above
2696 rules.  Note that, as a consequence of these rules, each command must
2697 begin on a new line.
2698
2699 @node Types of Commands, Order of Commands, Commands, Language
2700 @section Types of Commands
2701
2702 Commands in PSPP are divided roughly into six categories:
2703
2704 @table @strong
2705 @item Utility commands
2706 Set or display various global options that affect PSPP operations.
2707 May appear anywhere in a syntax file.  @xref{Utilities, , Utility
2708 commands}.
2709
2710 @item File definition commands
2711 Give instructions for reading data from text files or from special
2712 binary ``system files''.  Most of these commands discard any previous
2713 data or variables in order to replace it with the new data and
2714 variables.  At least one must appear before the first command in any of
2715 the categories below.  @xref{Data Input and Output}.
2716
2717 @item Input program commands
2718 Though rarely used, these provide powerful tools for reading data files
2719 in arbitrary textual or binary formats.  @xref{INPUT PROGRAM}.
2720
2721 @item Transformations
2722 Perform operations on data and write data to output files.  Transformations
2723 are not carried out until a procedure is executed.  
2724
2725 @item Restricted transformations
2726 Same as transformations for most purposes.  @xref{Order of Commands}, for a
2727 detailed description of the differences.
2728
2729 @item Procedures
2730 Analyze data, writing results of analyses to the listing file.  Cause
2731 transformations specified earlier in the file to be performed.  In a
2732 more general sense, a @dfn{procedure} is any command that causes the
2733 active file (the data) to be read.
2734 @end table
2735
2736 @node Order of Commands, Missing Observations, Types of Commands, Language
2737 @section Order of Commands
2738 @cindex commands, ordering
2739 @cindex order of commands
2740
2741 PSPP does not place many restrictions on ordering of commands.
2742 The main restriction is that variables must be defined with one of the
2743 file-definition commands before they are otherwise referred to.
2744
2745 Of course, there are specific rules, for those who are interested.
2746 PSPP possesses five internal states, called initial, INPUT
2747 PROGRAM, FILE TYPE, transformation, and procedure states.  (Please note
2748 the distinction between the INPUT PROGRAM and FILE TYPE @emph{commands}
2749 and the INPUT PROGRAM and FILE TYPE @emph{states}.)
2750
2751 PSPP starts up in the initial state.  Each successful completion
2752 of a command may cause a state transition.  Each type of command has its
2753 own rules for state transitions:
2754
2755 @table @strong
2756 @item Utility commands
2757 @itemize @bullet
2758 @item
2759 Legal in all states, except Pennsylvania.
2760 @item
2761 Do not cause state transitions.  Exception: when the N OF CASES command
2762 is executed in the procedure state, it causes a transition to the
2763 transformation state.
2764 @end itemize
2765
2766 @item DATA LIST
2767 @itemize @bullet
2768 @item
2769 Legal in all states.
2770 @item
2771 When executed in the initial or procedure state, causes a transition to
2772 the transformation state.  
2773 @item
2774 Clears the active file if executed in the procedure or transformation
2775 state.
2776 @end itemize
2777
2778 @item INPUT PROGRAM
2779 @itemize @bullet
2780 @item
2781 Invalid in INPUT PROGRAM and FILE TYPE states.
2782 @item
2783 Causes a transition to the INPUT PROGRAM state.  
2784 @item
2785 Clears the active file.
2786 @end itemize
2787
2788 @item FILE TYPE
2789 @itemize @bullet
2790 @item
2791 Invalid in INPUT PROGRAM and FILE TYPE states.
2792 @item
2793 Causes a transition to the FILE TYPE state.
2794 @item
2795 Clears the active file.
2796 @end itemize
2797
2798 @item Other file definition commands
2799 @itemize @bullet
2800 @item
2801 Invalid in INPUT PROGRAM and FILE TYPE states.
2802 @item
2803 Cause a transition to the transformation state.
2804 @item
2805 Clear the active file, except for ADD FILES, MATCH FILES, and UPDATE.
2806 @end itemize
2807
2808 @item Transformations
2809 @itemize @bullet
2810 @item
2811 Invalid in initial and FILE TYPE states.
2812 @item
2813 Cause a transition to the transformation state.
2814 @end itemize
2815
2816 @item Restricted transformations
2817 @itemize @bullet
2818 @item
2819 Invalid in initial, INPUT PROGRAM, and FILE TYPE states.
2820 @item
2821 Cause a transition to the transformation state.
2822 @end itemize
2823
2824 @item Procedures
2825 @itemize @bullet
2826 @item
2827 Invalid in initial, INPUT PROGRAM, and FILE TYPE states.
2828 @item
2829 Cause a transition to the procedure state.
2830 @end itemize
2831 @end table
2832
2833 @node Missing Observations, Variables, Order of Commands, Language
2834 @section Handling missing observations
2835 @cindex missing values
2836 @cindex values, missing
2837
2838 PSPP includes special support for unknown numeric data values.
2839 Missing observations are assigned a special value, called the
2840 @dfn{system-missing value}.  This ``value'' actually indicates the
2841 absence of value; it means that the actual value is unknown.  Procedures
2842 automatically exclude from analyses those observations or cases that
2843 have missing values.  Whether single observations or entire cases are
2844 excluded depends on the procedure.
2845
2846 The system-missing value exists only for numeric variables.  String
2847 variables always have a defined value, even if it is only a string of
2848 spaces.
2849
2850 Variables, whether numeric or string, can have designated
2851 @dfn{user-missing values}.  Every user-missing value is an actual value
2852 for that variable.  However, most of the time user-missing values are
2853 treated in the same way as the system-missing value.  String variables
2854 that are wider than a certain width, usually 8 characters (depending on
2855 computer architecture), cannot have user-missing values.
2856
2857 For more information on missing values, see the following sections:
2858 @ref{Variables}, @ref{MISSING VALUES}, @ref{Expressions}.  See also the
2859 documentation on individual procedures for information on how they
2860 handle missing values.
2861
2862 @node Variables, Files, Missing Observations, Language
2863 @section Variables
2864 @cindex variables
2865
2866 Variables are the basic unit of data storage in PSPP.  All the
2867 variables in a file taken together, apart from any associated data, are
2868 said to form a @dfn{dictionary}.  Each case contain a value for each
2869 variable.  Some details of variables are described in the sections
2870 below.
2871
2872 @menu
2873 * Attributes::                  Attributes of variables.
2874 * System Variables::            Variables automatically defined by PSPP.
2875 * Sets of Variables::           Lists of variable names.
2876 * Input/Output Formats::        Input and output formats.
2877 * Scratch Variables::           Variables deleted by procedures.
2878 @end menu
2879
2880 @node Attributes, System Variables, Variables, Variables
2881 @subsection Attributes of Variables
2882 @cindex variables, attributes of
2883 @cindex attributes of variables
2884 Each variable has a number of attributes, including:
2885
2886 @table @strong
2887 @item Name
2888 This is an identifier.  Each variable must have a different name.
2889 @xref{Tokens}.
2890
2891 @cindex variables, type
2892 @cindex type of variables
2893 @item Type
2894 Numeric or string.
2895
2896 @cindex variables, width
2897 @cindex width of variables
2898 @item Width
2899 (string variables only) String variables with a width of 8 characters or
2900 fewer are called @dfn{short string variables}.  Short string variables
2901 can be used in many procedures where @dfn{long string variables} (those
2902 with widths greater than 8) are not allowed.
2903
2904 @quotation
2905 @strong{Please note:} Certain systems may consider strings longer than 8
2906 characters to be short strings.  Eight characters represents a minimum
2907 figure for the maximum length of a short string.
2908 @end quotation
2909
2910 @item Position
2911 Variables in the dictionary are arranged in a specific order.  The
2912 DISPLAY command can be used to show this order: see @ref{DISPLAY}.
2913
2914 @item Orientation
2915 Dexter or sinister.  @xref{LEAVE}.
2916
2917 @cindex missing values
2918 @cindex values, missing
2919 @item Missing values
2920 Optionally, up to three values, or a range of values, or a specific
2921 value plus a range, can be specified as @dfn{user-missing values}.
2922 There is also a @dfn{system-missing value} that is assigned to an
2923 observation when there is no other obvious value for that observation.
2924 Observations with missing values are automatically excluded from
2925 analyses.  User-missing values are actual data values, while the
2926 system-missing value is not a value at all.  @xref{Missing Observations}.
2927
2928 @cindex variable labels
2929 @cindex labels, variable
2930 @item Variable label
2931 A string that describes the variable.  @xref{VARIABLE LABELS}.
2932
2933 @cindex value labels
2934 @cindex labels, value
2935 @item Value label
2936 Optionally, these associate each possible value of the variable with a
2937 string.  @xref{VALUE LABELS}.
2938
2939 @cindex print format
2940 @item Print format
2941 Display width, format, and (for numeric variables) number of decimal
2942 places.  This attribute does not affect how data are stored, just how
2943 they are displayed.  Example: a width of 8, with 2 decimal places.
2944 @xref{PRINT FORMATS}.
2945
2946 @cindex write format
2947 @item Write format
2948 Similar to print format, but used by certain commands that are
2949 designed to write to binary files.  @xref{WRITE FORMATS}.
2950 @end table
2951
2952 @node System Variables, Sets of Variables, Attributes, Variables
2953 @subsection Variables Automatically Defined by PSPP
2954 @cindex system variables
2955 @cindex variables, system
2956
2957 There are seven system variables.  These are not like ordinary
2958 variables, as they are not stored in each case.  They can only be used
2959 in expressions.  These system variables, whose values and output formats
2960 cannot be modified, are described below.
2961
2962 @table @code
2963 @cindex @code{$CASENUM}
2964 @item $CASENUM
2965 Case number of the case at the moment.  This changes as cases are
2966 shuffled around.
2967
2968 @cindex @code{$DATE}
2969 @item $DATE
2970 Date the PSPP process was started, in format A9, following the
2971 pattern @code{DD MMM YY}.
2972
2973 @cindex @code{$JDATE}
2974 @item $JDATE
2975 Number of days between 15 Oct 1582 and the time the PSPP process
2976 was started.
2977
2978 @cindex @code{$LENGTH}
2979 @item $LENGTH
2980 Page length, in lines, in format F11.
2981
2982 @cindex @code{$SYSMIS}
2983 @item $SYSMIS
2984 System missing value, in format F1.
2985
2986 @cindex @code{$TIME}
2987 @item $TIME
2988 Number of seconds between midnight 14 Oct 1582 and the time the active file
2989 was read, in format F20.
2990
2991 @cindex @code{$WIDTH}
2992 @item $WIDTH
2993 Page width, in characters, in format F3.
2994 @end table
2995
2996 @node Sets of Variables, Input/Output Formats, System Variables, Variables
2997 @subsection Lists of variable names
2998 @cindex TO convention
2999 @cindex convention, TO
3000
3001 There are several ways to specify a set of variables:
3002
3003 @enumerate
3004 @item
3005 (Most commonly.)  List the variable names one after another, optionally
3006 separating them by commas.
3007
3008 @cindex @code{TO}
3009 @item
3010 (This method cannot be used on commands that define the dictionary, such
3011 as @code{DATA LIST}.)  The syntax is the names of two existed variables,
3012 separated by the reserved keyword @code{TO}.  The meaning is to include
3013 every variable in the dictionary between and including the variables
3014 specified.  For instance, if the dictionary contains six variables with
3015 the names @code{ID}, @code{X1}, @code{X2}, @code{GOAL}, @code{MET}, and
3016 @code{NEXTGOAL}, in that order, then @code{X2 TO MET} would include
3017 variables @code{X2}, @code{GOAL}, and @code{MET}.
3018
3019 @item
3020 (This method can be used only on commands that define the dictionary,
3021 such as @code{DATA LIST}.)  It is used to define sequences of variables
3022 that end in consecutive integers.  The syntax is two identifiers that
3023 end in numbers.  This method is best illustrated with examples:
3024
3025 @itemize @bullet
3026 @item
3027 The syntax @code{X1 TO X5} defines 5 variables:
3028
3029 @itemize @minus
3030 @item
3031 X1
3032 @item
3033 X2
3034 @item
3035 X3
3036 @item
3037 X4
3038 @item
3039 X5
3040 @end itemize
3041
3042 @item
3043 The syntax @code{ITEM0008 TO ITEM0013} defines 6 variables:
3044
3045 @itemize @minus
3046 @item
3047 ITEM0008
3048 @item
3049 ITEM0009
3050 @item
3051 ITEM0010
3052 @item
3053 ITEM0011
3054 @item
3055 ITEM0012
3056 @item
3057 ITEM0013
3058 @end itemize
3059
3060 @item
3061 Each of the syntaxes @code{QUES001 TO QUES9} and @code{QUES6 TO QUES3}
3062 are invalid, although for different reasons, which should be evident.
3063 @end itemize
3064
3065 Note that after a set of variables has been defined on @code{DATA LIST}
3066 or another command with this method, the same set can be referenced on
3067 later commands using the same syntax.
3068
3069 @item
3070 The above methods can be combined, either one after another or delimited
3071 by commas.  For instance, the combined syntax @code{A Q5 TO Q8 X TO Z}
3072 is legal as long as each part @code{A}, @code{Q5 TO Q8}, @code{X TO Z}
3073 is individually legal.
3074 @end enumerate
3075
3076 @node Input/Output Formats, Scratch Variables, Sets of Variables, Variables
3077 @subsection Input and Output Formats
3078
3079 Data that PSPP inputs and outputs must have one of a number of formats.
3080 These formats are described, in general, by a format specification of
3081 the form @code{NAMEw.d}, where @var{name} is the
3082 format name and @var{w} is a field width.  @var{d} is the optional
3083 desired number of decimal places, if appropriate.  If @var{d} is not
3084 included then it is assumed to be 0.  Some formats do not allow @var{d}
3085 to be specified.
3086
3087 When an input format is specified on DATA LIST or another command, then
3088 it is converted to an output format for the purposes of PRINT and other
3089 data output commands.  For most purposes, input and output formats are
3090 the same; the salient differences are described below.
3091
3092 Below are listed the input and output formats supported by PSPP.  If an
3093 input format is mapped to a different output format by default, then
3094 that mapping is indicated with @result{}.  Each format has the listed
3095 bounds on input width (iw) and output width (ow).
3096
3097 The standard numeric input and output formats are given in the following
3098 table:
3099
3100 @table @asis
3101 @item Fw.d: 1 <= iw,ow <= 40
3102 Standard decimal format with @var{d} decimal places.  If the number is
3103 too large to fit within the field width, it is expressed in scientific
3104 notation (@code{1.2+34}) if w >= 6, with always at least two digits in
3105 the exponent.  When used as an input format, scientific notation is
3106 allowed but an E or an F must be used to introduce the exponent.
3107
3108 The default output format is the same as the input format, except if
3109 @var{d} > 1.  In that case the output @var{w} is always made to be at
3110 least 2 + @var{d}.
3111
3112 @item Ew.d: 1 <= iw <= 40; 6 <= ow <= 40
3113 For input this is equivalent to F format except that no E or F is
3114 require to introduce the exponent.  For output, produces scientific
3115 notation in the form @code{1.2+34}.  There are always at least two
3116 digits given in the exponent.
3117
3118 The default output @var{w} is the largest of the input @var{w}, the
3119 input @var{d} + 7, and 10.  The default output @var{d} is the input
3120 @var{d}, but at least 3.
3121
3122 @item COMMAw.d: 1 <= iw,ow <= 40
3123 Equivalent to F format, except that groups of three digits are
3124 comma-separated on output.  If the number is too large to express in the
3125 field width, then first commas are eliminated, then if there is still
3126 not enough space the number is expressed in scientific notation given
3127 that w >= 6.  Commas are allowed and ignored when this is used as an
3128 input format.  
3129
3130 @item DOTw.d: 1 <= iw,ow <= 40
3131 Equivalent to COMMA format except that the roles of comma and decimal
3132 point are interchanged.  However: If SET /DECIMAL=DOT is in effect, then
3133 COMMA uses @samp{,} for a decimal point and DOT uses @samp{.} for a
3134 decimal point.
3135
3136 @item DOLLARw.d: 1 <= iw <= 40; 2 <= ow <= 40
3137 Equivalent to COMMA format, except that the number is prefixed by a
3138 dollar sign (@samp{$}) if there is room.  On input the value is allowed
3139 to be prefixed by a dollar sign, which is ignored.
3140
3141 The default output @var{w} is the input @var{w}, but at least 2.
3142
3143 @item PCTw.d: 2 <= iw,ow <= 40
3144 Equivalent to F format, except that the number is suffixed by a percent
3145 sign (@samp{%}) if there is room.  On input the value is allowed to be
3146 suffixed by a percent sign, which is ignored.
3147
3148 The default output @var{w} is the input @var{w}, but at least 2.
3149
3150 @item Nw.d: 1 <= iw,ow <= 40
3151 Only digits are allowed within the field width.  The decimal point is
3152 assumed to be @var{d} digits from the right margin.
3153
3154 The default output format is F with the same @var{w} and @var{d}, except
3155 if @var{d} > 1.  In that case the output @var{w} is always made to be at
3156 least 2 + @var{d}.
3157
3158 @item Zw.d @result{} F: 1 <= iw,ow <= 40
3159 Zoned decimal input.  If you need to use this then you know how.
3160
3161 @item IBw.d @result{} F: 1 <= iw,ow <= 8
3162 Integer binary format.  The field is interpreted as a fixed-point
3163 positive or negative binary number in two's-complement notation.  The
3164 location of the decimal point is implied.  Endianness is the same as the
3165 host machine.
3166
3167 The default output format is F8.2 if @var{d} is 0.  Otherwise it is F,
3168 with output @var{w} as 9 + input @var{d} and output @var{d} as input
3169 @var{d}.
3170
3171 @item PIB @result{} F: 1 <= iw,ow <= 8
3172 Positive integer binary format.  The field is interpreted as a
3173 fixed-point positive binary number.  The location of the decimal point
3174 is implied.  Endianness is teh same as the host machine.
3175
3176 The default output format follows the rules for IB format.
3177
3178 @item Pw.d @result{} F: 1 <= iw,ow <= 16
3179 Binary coded decimal format.  Each byte from left to right, except the
3180 rightmost, represents two digits.  The upper nibble of each byte is more
3181 significant.  The upper nibble of the final byte is the least
3182 significant digit.  The lower nibble of the final byte is the sign; a
3183 value of D represents a negative sign and all other values are
3184 considered positive.  The decimal point is implied.
3185
3186 The default output format follows the rules for IB format.
3187
3188 @item PKw.d @result{} F: 1 <= iw,ow <= 16
3189 Positive binary code decimal format.  Same as P but the last byte is the
3190 same as the others.
3191
3192 The default output format follows the rules for IB format.
3193
3194 @item RBw @result{} F: 2 <= iw,ow <= 8
3195
3196 Binary C architecture-dependent ``double'' format.  For a standard
3197 IEEE754 implementation @var{w} should be 8.
3198
3199 The default output format follows the rules for IB format.
3200
3201 @item PIBHEXw.d @result{} F: 2 <= iw,ow <= 16
3202 PIB format encoded as textual hex digit pairs.  @var{w} must be even.
3203
3204 The input width is mapped to a default output width as follows:
3205 2@result{}4, 4@result{}6, 6@result{}9, 8@result{}11, 10@result{}14,
3206 12@result{}16, 14@result{}18, 16@result{}21.  No allowances are made for
3207 decimal places.
3208
3209 @item RBHEXw @result{} F: 4 <= iw,ow <= 16
3210
3211 RB format encoded as textual hex digits pairs.  @var{w} must be even.
3212
3213 The default output format is F8.2.
3214
3215 @item CCAw.d: 1 <= ow <= 40
3216 @itemx CCBw.d: 1 <= ow <= 40
3217 @itemx CCCw.d: 1 <= ow <= 40
3218 @itemx CCDw.d: 1 <= ow <= 40
3219 @itemx CCEw.d: 1 <= ow <= 40
3220
3221 User-defined custom currency formats.  May not be used as an input
3222 format.  @xref{SET}, for more details.
3223 @end table
3224
3225 The date and time numeric input and output formats accept a number of
3226 possible formats.  Before describing the formats themselves, some
3227 definitions of the elements that make up their formats will be helpful:
3228
3229 @table @dfn
3230 @item leader
3231 All formats accept an optional whitespace leader.
3232
3233 @item day
3234 An integer between 1 and 31 representing the day of month.
3235
3236 @item day-count
3237 An integer representing a number of days.
3238
3239 @item date-delimiter
3240 One or more characters of whitespace or the following characters:
3241 @code{- / . ,}
3242
3243 @item month
3244 A month name in one of the following forms:
3245 @itemize @bullet
3246 @item
3247 An integer between 1 and 12.
3248 @item
3249 Roman numerals representing an integer between 1 and 12.
3250 @item
3251 At least the first three characters of an English month name (January,
3252 February, @dots{}).
3253 @end itemize
3254
3255 @item year
3256 An integer year number between 1582 and 19999, or between 1 and 199.
3257 Years between 1 and 199 will have 1900 added.
3258
3259 @item julian
3260 A single number with a year number in the first 2, 3, or 4 digits (as
3261 above) and the day number within the year in the last 3 digits.
3262
3263 @item quarter
3264 An integer between 1 and 4 representing a quarter.
3265
3266 @item q-delimiter
3267 The letter @samp{Q} or @samp{q}.
3268
3269 @item week
3270 An integer between 1 and 53 representing a week within a year.
3271
3272 @item wk-delimiter
3273 The letters @samp{wk} in any case.
3274
3275 @item time-delimiter
3276 At least one characters of whitespace or @samp{:} or @samp{.}.
3277
3278 @item hour
3279 An integer greater than 0 representing an hour.
3280
3281 @item minute
3282 An integer between 0 and 59 representing a minute within an hour.
3283
3284 @item opt-second
3285 Optionally, a time-delimiter followed by a real number representing a
3286 number of seconds.
3287
3288 @item hour24
3289 An integer between 0 and 23 representing an hour within a day.
3290
3291 @item weekday
3292 At least the first two characters of an English day word.
3293
3294 @item spaces
3295 Any amount or no amount of whitespace.
3296
3297 @item sign
3298 An optional positive or negative sign.
3299
3300 @item trailer
3301 All formats accept an optional whitespace trailer.
3302 @end table
3303
3304 The date input formats are strung together from the above pieces.  On
3305 output, the date formats are always printed in a single canonical
3306 manner, based on field width.  The date input and output formats are
3307 described below:
3308
3309 @table @asis
3310 @item DATEw: 9 <= iw,ow <= 40
3311 Date format. Input format: leader + day + date-delimiter +
3312 month + date-delimiter + year + trailer.  Output format: DD-MMM-YY for
3313 @var{w} < 11, DD-MMM-YYYY otherwise.
3314
3315 @item EDATEw: 8 <= iw,ow <= 40
3316 European date format.  Input format same as DATE.  Output format:
3317 DD.MM.YY for @var{w} < 10, DD.MM.YYYY otherwise.
3318
3319 @item SDATEw: 8 <= iw,ow <= 40
3320 Standard date format. Input format: leader + year + date-delimiter +
3321 month + date-delimiter + day + trailer.  Output format: YY/MM/DD for
3322 @var{w} < 10, YYYY/MM/DD otherwise.
3323
3324 @item ADATEw: 8 <= iw,ow <= 40
3325 American date format.  Input format: leader + month + date-delimiter +
3326 day + date-delimiter + year + trailer.  Output format: MM/DD/YY for
3327 @var{w} < 10, MM/DD/YYYY otherwise.
3328
3329 @item JDATEw: 5 <= iw,ow <= 40
3330 Julian date format.  Input format: leader + julian + trailer.  Output
3331 format: YYDDD for @var{w} < 7, YYYYDDD otherwise.
3332
3333 @item QYRw: 4 <= iw <= 40, 6 <= ow <= 40
3334 Quarter/year format.  Input format: leader + quarter + q-delimiter +
3335 year + trailer.  Output format: @samp{Q Q YY}, where the first
3336 @samp{Q} is one of the digits 1, 2, 3, 4, if @var{w} < 8, @code{Q Q
3337 YYYY} otherwise.
3338
3339 @item MOYRw: 6 <= iw,ow <= 40
3340 Month/year format.  Input format: leader + month + date-delimiter + year
3341 + trailer.  Output format: @samp{MMM YY} for @var{w} < 8, @samp{MMM
3342 YYYY} otherwise.
3343
3344 @item WKYRw: 6 <= iw <= 40, 8 <= ow <= 40
3345 Week/year format.  Input format: leader + week + wk-delimiter + year +
3346 trailer.  Output format: @samp{WW WK YY} for @var{w} < 10, @samp{WW WK
3347 YYYY} otherwise.
3348
3349 @item DATETIMEw.d: 17 <= iw,ow <= 40
3350 Date and time format.  Input format: leader + day + date-delimiter +
3351 month + date-delimiter + yaer + time-delimiter + hour24 + time-delimiter
3352 + minute + opt-second.  Output format: @samp{DD-MMM-YYYY HH:MM}.  If
3353 @var{w} > 19 then seconds @samp{:SS} is added.  If @var{w} > 22 and
3354 @var{d} > 0 then fractional seconds @samp{.SS} are added.
3355
3356 @item TIMEw.d: 5 <= iw,ow <= 40
3357 Time format.  Input format: leader + sign + spaces + hour +
3358 time-delimiter + minute + opt-second.  Output format: @samp{HH:MM}.
3359 Seconds and fractional seconds are available with @var{w} of at least 8
3360 and 10, respectively.
3361
3362 @item DTIMEw.d: 1 <= iw <= 40, 8 <= ow <= 40
3363 Time format with day count.  Input format: leader + sign + spaces +
3364 day-count + time-delimiter + hour + time-delimiter + minute +
3365 opt-second.  Output format: @samp{DD HH:MM}.  Seconds and fractional
3366 seconds are available with @var{w} of at least 8 and 10, respectively.
3367
3368 @item WKDAYw: 2 <= iw,ow <= 40
3369 A weekday as a number between 1 and 7, where 1 is Sunday.  Input format:
3370 leader + weekday + trailer.  Output format: as many characters, in all
3371 capital letters, of the English name of the weekday as will fit in the
3372 field width.
3373
3374 @item MONTHw: 3 <= iw,ow <= 40
3375 A month as a number between 1 and 12, where 1 is January.  Input format:
3376 leader + month + trailer.  Output format: as many character, in all
3377 capital letters, of the English name of the month as will fit in the
3378 field width.
3379 @end table
3380
3381 There are only two formats that may be used with string variables:
3382
3383 @table @asis
3384 @item Aw: 1 <= iw <= 255, 1 <= ow <= 254
3385 The entire field is treated as a string value.
3386
3387 @item AHEXw @result{} A: 2 <= iw <= 254; 2 <= ow <= 510
3388 The field is composed of characters in a string encoded as textual hex
3389 digit pairs.
3390
3391 The default output @var{w} is half the input @var{w}.
3392 @end table
3393
3394 @node Scratch Variables,  , Input/Output Formats, Variables
3395 @subsection Scratch Variables
3396
3397 Most of the time, variables don't retain their values between cases.
3398 Instead, either they're being read from a data file or the active file,
3399 in which case they assume the value read, or, if created with COMPUTE or
3400 another transformation, they're initialized to the system-missing value
3401 or to blanks, depending on type.
3402
3403 However, sometimes it's useful to have a variable that keeps its value
3404 between cases.  You can do this with LEAVE (@pxref{LEAVE}), or you can
3405 use a @dfn{scratch variable}.  Scratch variables are variables whose
3406 names begin with an octothorpe (@samp{#}).  
3407
3408 Scratch variables have the same properties as variables left with LEAVE:
3409 they retain their values between cases, and for the first case they are
3410 initialized to 0 or blanks.  They have the additional property that they
3411 are deleted before the execution of any procedure.  For this reason,
3412 scratch variables can't be used for analysis.  To obtain the same
3413 effect, use COMPUTE (@pxref{COMPUTE}) to copy the scratch variable's
3414 value into an ordinary variable, then analysis that variable.
3415
3416 @node Files, BNF, Variables, Language
3417 @section Files Used by PSPP
3418
3419 PSPP makes use of many files each time it runs.  Some of these it
3420 reads, some it writes, some it creates.  Here is a table listing the
3421 most important of these files:
3422
3423 @table @strong
3424 @cindex file, command
3425 @cindex file, syntax file
3426 @cindex command file
3427 @cindex syntax file
3428 @item command file
3429 @itemx syntax file
3430 These names (synonyms) refer to the file that contains instructions to
3431 PSPP that tell it what to do.  The syntax file's name is specified on
3432 the PSPP command line.  Syntax files can also be pulled in with the
3433 @code{INCLUDE} command.
3434
3435 @cindex file, data
3436 @cindex data file
3437 @item data file
3438 Data files contain raw data in ASCII format suitable for being read in
3439 by the @code{DATA LIST} command.  Data can be embedded in the syntax
3440 file with @code{BEGIN DATA} and @code{END DATA} commands: this makes the
3441 syntax file a data file too.
3442
3443 @cindex file, output
3444 @cindex output file
3445 @item listing file
3446 One or more output files are created by PSPP each time it is
3447 run.  The output files receive the tables and charts produced by
3448 statistical procedures.  The output files may be in any number of formats,
3449 depending on how PSPP is configured.
3450
3451 @cindex active file
3452 @cindex file, active
3453 @item active file
3454 The active file is the ``file'' on which all PSPP procedures
3455 are performed.  The active file contains variable definitions and
3456 cases.  The active file is not necessarily a disk file: it is stored
3457 in memory if there is room.
3458 @end table
3459
3460 @node BNF,  , Files, Language
3461 @section Backus-Naur Form
3462 @cindex BNF
3463 @cindex Backus-Naur Form
3464 @cindex command syntax, description of
3465 @cindex description of command syntax
3466
3467 The syntax of some parts of the PSPP language is presented in this
3468 manual using the formalism known as @dfn{Backus-Naur Form}, or BNF. The
3469 following table describes BNF:
3470
3471 @itemize @bullet
3472 @cindex keywords
3473 @cindex terminals
3474 @item
3475 Words in all-uppercase are PSPP keyword tokens.  In BNF, these are
3476 often called @dfn{terminals}.  There are some special terminals, which
3477 are actually written in lowercase for clarity:
3478
3479 @table @asis
3480 @cindex @code{number}
3481 @item @code{number}
3482 A real number.
3483
3484 @cindex @code{integer}
3485 @item @code{integer}
3486 An integer number.
3487
3488 @cindex @code{string}
3489 @item @code{string}
3490 A string.
3491
3492 @cindex @code{var-name}
3493 @item @code{var-name}
3494 A single variable name.
3495
3496 @cindex operators
3497 @cindex punctuators
3498 @item @code{=}, @code{/}, @code{+}, @code{-}, etc.
3499 Operators and punctuators.
3500
3501 @cindex @code{.}
3502 @cindex terminal dot
3503 @cindex dot, terminal
3504 @item @code{.}
3505 The terminal dot.  This is not necessarily an actual dot in the syntax
3506 file: @xref{Commands}, for more details.
3507 @end table
3508
3509 @item
3510 @cindex productions
3511 @cindex nonterminals
3512 Other words in all lowercase refer to BNF definitions, called
3513 @dfn{productions}.  These productions are also known as
3514 @dfn{nonterminals}.  Some nonterminals are very common, so they are
3515 defined here in English for clarity:
3516
3517 @table @code
3518 @cindex @code{var-list}
3519 @item var-list
3520 A list of one or more variable names or the keyword @code{ALL}.
3521
3522 @cindex @code{expression}
3523 @item expression
3524 An expression.  @xref{Expressions}, for details.
3525 @end table
3526
3527 @item
3528 @cindex @code{::=}
3529 @cindex ``is defined as''
3530 @cindex productions
3531 @samp{::=} means ``is defined as''.  The left side of @samp{::=} gives
3532 the name of the nonterminal being defined.  The right side of @samp{::=}
3533 gives the definition of that nonterminal.  If the right side is empty,
3534 then one possible expansion of that nonterminal is nothing.  A BNF
3535 definition is called a @dfn{production}.
3536
3537 @item
3538 @cindex terminals and nonterminals, differences
3539 So, the key difference between a terminal and a nonterminal is that a
3540 terminal cannot be broken into smaller parts---in fact, every terminal
3541 is a single token (@pxref{Tokens}).  On the other hand, nonterminals are
3542 composed of a (possibly empty) sequence of terminals and nonterminals.
3543 Thus, terminals indicate the deepest level of syntax description.  (In
3544 parsing theory, terminals are the leaves of the parse tree; nonterminals
3545 form the branches.)
3546
3547 @item
3548 @cindex start symbol
3549 @cindex symbol, start
3550 The first nonterminal defined in a set of productions is called the
3551 @dfn{start symbol}.  The start symbol defines the entire syntax for
3552 that command.
3553 @end itemize
3554
3555 @node Expressions, Data Input and Output, Language, Top
3556 @chapter Mathematical Expressions
3557 @cindex expressions, mathematical
3558 @cindex mathematical expressions
3559
3560 Some PSPP commands use expressions, which share a common syntax
3561 among all PSPP commands.  Expressions are made up of
3562 @dfn{operands}, which can be numbers, strings, or variable names,
3563 separated by @dfn{operators}.  There are five types of operators:
3564 grouping, arithmetic, logical, relational, and functions.
3565
3566 Every operator takes one or more @dfn{arguments} as input and produces
3567 or @dfn{returns} exactly one result as output.  Both strings and numeric
3568 values can be used as arguments and are produced as results, but each
3569 operator accepts only specific combinations of numeric and string values
3570 as arguments.  With few exceptions, operator arguments may be
3571 full-fledged expressions in themselves.
3572
3573 @menu
3574 * Booleans::                       Boolean values.
3575 * Missing Values in Expressions::  Using missing values in expressions.
3576 * Grouping Operators::             ( )
3577 * Arithmetic Operators::           + - * / **
3578 * Logical Operators::              AND NOT OR
3579 * Relational Operators::           EQ GE GT LE LT NE
3580 * Functions::                      More-sophisticated operators.
3581 * Order of Operations::            Operator precedence.
3582 @end menu
3583
3584 @node Booleans, Missing Values in Expressions, Expressions, Expressions
3585 @section Boolean values
3586 @cindex Boolean
3587 @cindex values, Boolean
3588
3589 There is a third type for arguments and results, the @dfn{Boolean} type,
3590 which is used to represent true/false conditions.  Booleans have only
3591 three possible values: 0 (false), 1 (true), and system-missing.
3592 System-missing is neither true or false.
3593
3594 @itemize @bullet
3595 @item
3596 A numeric expression that has value 0, 1, or system-missing may be used
3597 in place of a Boolean.  Thus, the expression @code{0 AND 1} is valid
3598 (although it is always true).
3599
3600 @item
3601 A numeric expression with any other value will cause an error if it is
3602 used as a Boolean.  So, @code{2 OR 3} is invalid.
3603
3604 @item
3605 A Boolean expression may not be used in place of a numeric expression.
3606 Thus, @code{(1>2) + (3<4)} is invalid.
3607
3608 @item
3609 Strings and Booleans are not compatible, and neither may be used in
3610 place of the other.
3611 @end itemize
3612
3613 @node Missing Values in Expressions, Grouping Operators, Booleans, Expressions
3614 @section Missing Values in Expressions
3615
3616 String missing values are not treated specially in expressions.  Most
3617 numeric operators return system-missing when given system-missing
3618 arguments.  Exceptions are listed under particular operator
3619 descriptions.
3620
3621 User-missing values for numeric variables are always transformed into
3622 the system-missing value, except inside the arguments to the
3623 @code{VALUE}, @code{SYSMIS}, and @code{MISSING} functions.
3624
3625 The missing-value functions can be used to precisely control how missing
3626 values are treated in expressions.  @xref{Missing Value Functions}, for
3627 more details.
3628
3629 @node Grouping Operators, Arithmetic Operators, Missing Values in Expressions, Expressions
3630 @section Grouping Operators
3631 @cindex parentheses
3632 @cindex @samp{(  )}
3633 @cindex grouping operators
3634 @cindex operators, grouping
3635
3636 Parentheses (@samp{()}) are the grouping operators.  Surround an
3637 expression with parentheses to force early evaluation.
3638
3639 Parentheses also surround the arguments to functions, but in that
3640 situation they act as punctuators, not as operators.
3641
3642 @node Arithmetic Operators, Logical Operators, Grouping Operators, Expressions
3643 @section Arithmetic Operators
3644 @cindex operators, arithmetic
3645 @cindex arithmetic operators
3646
3647 The arithmetic operators take numeric arguments and produce numeric
3648 results.
3649
3650 @table @code
3651 @cindex @samp{+}
3652 @cindex addition
3653 @item @var{a} + @var{b}
3654 Adds @var{a} and @var{b}, returning the sum.
3655
3656 @cindex @samp{-}
3657 @cindex subtraction
3658 @item @var{a} - @var{b}
3659 Subtracts @var{b} from @var{a}, returning the difference.
3660
3661 @cindex @samp{*}
3662 @cindex multiplication
3663 @item @var{a} * @var{b}
3664 Multiplies @var{a} and @var{b}, returning the product.
3665
3666 @cindex @samp{/}
3667 @cindex division
3668 @item @var{a} / @var{b}
3669 Divides @var{a} by @var{b}, returning the quotient.  If @var{b} is
3670 zero, the result is system-missing.
3671
3672 @cindex @samp{**}
3673 @cindex exponentiation
3674 @item @var{a} ** @var{b}
3675 Returns the result of raising @var{a} to the power @var{b}.  If
3676 @var{a} is negative and @var{b} is not an integer, the result is
3677 system-missing.  The result of @code{0**0} is system-missing as well.
3678
3679 @cindex @samp{-}
3680 @cindex negation
3681 @item - @var{a}
3682 Reverses the sign of @var{a}.  
3683 @end table
3684
3685 @node Logical Operators, Relational Operators, Arithmetic Operators, Expressions
3686 @section Logical Operators
3687 @cindex logical operators
3688 @cindex operators, logical
3689
3690 @cindex true
3691 @cindex false
3692 @cindex Boolean
3693 @cindex values, system-missing
3694 @cindex system-missing
3695 The logical operators take logical arguments and produce logical
3696 results, meaning ``true or false''.  PSPP logical operators are
3697 not true Boolean operators because they may also result in a
3698 system-missing value.
3699
3700 @table @code
3701 @cindex @code{AND}
3702 @cindex @samp{&}
3703 @cindex intersection, logical
3704 @cindex logical intersection
3705 @item @var{a} AND @var{b}
3706 @itemx @var{a} & @var{b}
3707 True if both @var{a} and @var{b} are true.  However, if one argument is
3708 false and the other is missing, the result is false, not missing.  If
3709 both arguments are missing, the result is missing.
3710
3711 @cindex @code{OR}
3712 @cindex @samp{|}
3713 @cindex union, logical
3714 @cindex logical union
3715 @item @var{a} OR @var{b}
3716 @itemx @var{a} | @var{b}
3717 True if at least one of @var{a} and @var{b} is true.  If one argument is
3718 true and the other is missing, the result is true, not missing.  If both
3719 arguments are missing, the result is missing.
3720
3721 @cindex @code{NOT}
3722 @cindex @samp{~}
3723 @cindex inversion, logical
3724 @cindex logical inversion
3725 @item NOT @var{a}
3726 @itemx ~ @var{a}
3727 True if @var{a} is false.
3728 @end table
3729
3730 @node Relational Operators, Functions, Logical Operators, Expressions
3731 @section Relational Operators
3732
3733 The relational operators take numeric or string arguments and produce Boolean
3734 results.
3735
3736 Note that, with numeric arguments, PSPP does not make exact
3737 relational tests.  Instead, two numbers are considered to be equal even
3738 if they differ by a small amount.  This amount, @dfn{epsilon}, is
3739 dependent on the PSPP configuration and determined at compile
3740 time.  (The default value is 0.000000001, or 
3741 @ifinfo
3742 @code{10**(-9)}.)
3743 @end ifinfo
3744 @tex
3745 $10 ^ -9$.)
3746 @end tex
3747 Use of epsilon allows for round-off errors.  Use of epsilon is also
3748 idiotic, but the author is not a numeric analyst.
3749
3750 Strings cannot be compared to numbers.  When strings of different
3751 lengths are compared, the shorter string is right-padded with spaces
3752 to match the length of the longer string.
3753
3754 The results of string comparisons, other than tests for equality or
3755 inequality, are dependent on the character set in use.  String
3756 comparisons are case-sensitive.
3757
3758 @table @code
3759 @cindex equality, testing
3760 @cindex testing for equality
3761 @cindex @code{EQ}
3762 @cindex @samp{=}
3763 @item @var{a} EQ @var{b}
3764 @itemx @var{a} = @var{b}
3765 True if @var{a} is equal to @var{b}.
3766
3767 @cindex less than or equal to
3768 @cindex @code{LE}
3769 @cindex @code{<=}
3770 @item @var{a} LE @var{b}
3771 @itemx @var{a} <= @var{b}
3772 True if @var{a} is less than or equal to @var{b}.
3773
3774 @cindex less than
3775 @cindex @code{LT}
3776 @cindex @code{<}
3777 @item @var{a} LT @var{b}
3778 @itemx @var{a} < @var{b}
3779 True if @var{a} is less than @var{b}.
3780
3781 @cindex greater than or equal to
3782 @cindex @code{GE}
3783 @cindex @code{>=}
3784 @item @var{a} GE @var{b}
3785 @itemx @var{a} >= @var{b}
3786 True if @var{a} is greater than or equal to @var{b}.
3787
3788 @cindex greater than
3789 @cindex @code{GT}
3790 @cindex @samp{>}
3791 @item @var{a} GT @var{b}
3792 @itemx @var{a} > @var{b}
3793 True if @var{a} is greater than @var{b}.
3794
3795 @cindex inequality, testing
3796 @cindex testing for inequality
3797 @cindex @code{NE}
3798 @cindex @code{~=}
3799 @cindex @code{<>}
3800 @item @var{a} NE @var{b}
3801 @itemx @var{a} ~= @var{b}
3802 @itemx @var{a} <> @var{b}
3803 True is @var{a} is not equal to @var{b}.
3804 @end table
3805
3806 @node Functions, Order of Operations, Relational Operators, Expressions
3807 @section Functions
3808 @cindex functions
3809
3810 @cindex mathematics
3811 @cindex operators
3812 @cindex parentheses
3813 @cindex @code{(}
3814 @cindex @code{)}
3815 @cindex names, of functions
3816 PSPP functions provide mathematical abilities above and beyond
3817 those possible using simple operators.  Functions have a common
3818 syntax: each is composed of a function name followed by a left
3819 parenthesis, one or more arguments, and a right parenthesis.  Function
3820 names are @strong{not} reserved; their names are specially treated
3821 only when followed by a left parenthesis: @code{EXP(10)} refers to the
3822 constant value @code{e} raised to the 10th power, but @code{EXP} by
3823 itself refers to the value of variable EXP.
3824
3825 The sections below describe each function in detail.
3826
3827 @menu
3828 * Advanced Mathematics::        EXP LG10 LN SQRT
3829 * Miscellaneous Mathematics::   ABS MOD MOD10 RND TRUNC
3830 * Trigonometry::                ACOS ARCOS ARSIN ARTAN ASIN ATAN COS SIN TAN
3831 * Missing Value Functions::     MISSING NMISS NVALID SYSMIS VALUE
3832 * Pseudo-Random Numbers::       NORMAL UNIFORM
3833 * Set Membership::              ANY RANGE
3834 * Statistical Functions::       CFVAR MAX MEAN MIN SD SUM VARIANCE
3835 * String Functions::            CONCAT INDEX LENGTH LOWER LPAD LTRIM NUMBER 
3836                                 RINDEX RPAD RTRIM STRING SUBSTR UPCASE
3837 * Time & Date::                 CTIME.xxx DATE.xxx TIME.xxx XDATE.xxx
3838 * Miscellaneous Functions::     LAG YRMODA
3839 * Functions Not Implemented::   CDF.xxx CDFNORM IDF.xxx NCDF.xxx PROBIT RV.xxx
3840 @end menu
3841
3842 @node Advanced Mathematics, Miscellaneous Mathematics, Functions, Functions
3843 @subsection Advanced Mathematical Functions
3844 @cindex mathematics, advanced
3845
3846 Advanced mathematical functions take numeric arguments and produce
3847 numeric results.
3848
3849 @deftypefn {Function} {} EXP (@var{exponent})
3850 Returns @i{e} (approximately 2.71828) raised to power @var{exponent}.
3851 @end deftypefn
3852
3853 @cindex logarithms
3854 @deftypefn {Function} {} LG10 (@var{number})
3855 Takes the base-10 logarithm of @var{number}.  If @var{number} is
3856 not positive, the result is system-missing.
3857 @end deftypefn
3858
3859 @deftypefn {Function} {} LN (@var{number})
3860 Takes the base-@samp{e} logarithm of @var{number}.  If @var{number} is
3861 not positive, the result is system-missing.
3862 @end deftypefn
3863
3864 @cindex square roots
3865 @deftypefn {Function} {} SQRT (@var{number})
3866 Takes the square root of @var{number}.  If @var{number} is negative,
3867 the result is system-missing.
3868 @end deftypefn
3869
3870 @node Miscellaneous Mathematics, Trigonometry, Advanced Mathematics, Functions
3871 @subsection Miscellaneous Mathematical Functions
3872 @cindex mathematics, miscellaneous
3873
3874 Miscellaneous mathematical functions take numeric arguments and produce
3875 numeric results.
3876
3877 @cindex absolute value
3878 @deftypefn {Function} {} ABS (@var{number})
3879 Results in the absolute value of @var{number}.
3880 @end deftypefn
3881
3882 @cindex modulus
3883 @deftypefn {Function} {} MOD (@var{numerator}, @var{denominator})
3884 Returns the remainder (modulus) of @var{numerator} divided by
3885 @var{denominator}.  If @var{denominator} is 0, the result is
3886 system-missing.  However, if @var{numerator} is 0 and
3887 @var{denominator} is system-missing, the result is 0.
3888 @end deftypefn
3889
3890 @cindex modulus, by 10
3891 @deftypefn {Function} {} MOD10 (@var{number})
3892 Returns the remainder when @var{number} is divided by 10.  If
3893 @var{number} is negative, MOD10(@var{number}) is negative or zero.
3894 @end deftypefn
3895
3896 @cindex rounding
3897 @deftypefn {Function} {} RND (@var{number})
3898 Takes the absolute value of @var{number} and rounds it to an integer.
3899 Then, if @var{number} was negative originally, negates the result.
3900 @end deftypefn
3901
3902 @cindex truncation
3903 @deftypefn {Function} {} TRUNC (@var{number})
3904 Discards the fractional part of @var{number}; that is, rounds
3905 @var{number} towards zero.
3906 @end deftypefn
3907
3908 @node Trigonometry, Missing Value Functions, Miscellaneous Mathematics, Functions
3909 @subsection Trigonometric Functions
3910 @cindex trigonometry
3911
3912 Trigonometric functions take numeric arguments and produce numeric
3913 results.
3914
3915 @cindex arccosine
3916 @cindex inverse cosine
3917 @deftypefn {Function} {} ACOS (@var{number})
3918 @deftypefnx {Function} {} ARCOS (@var{number})
3919 Takes the arccosine, in radians, of @var{number}.  Results in
3920 system-missing if @var{number} is not between -1 and 1.  Portability:
3921 none.
3922 @end deftypefn
3923
3924 @cindex arcsine
3925 @cindex inverse sine
3926 @deftypefn {Function} {} ARSIN (@var{number})
3927 Takes the arcsine, in radians, of @var{number}.  Results in
3928 system-missing if @var{number} is not between -1 and 1 inclusive.
3929 @end deftypefn
3930
3931 @cindex arctangent
3932 @cindex inverse tangent
3933 @deftypefn {Function} {} ARTAN (@var{number})
3934 Takes the arctangent, in radians, of @var{number}.
3935 @end deftypefn
3936
3937 @cindex arcsine
3938 @cindex inverse sine
3939 @deftypefn {Function} {} ASIN (@var{number})
3940 Takes the arcsine, in radians, of @var{number}.  Results in
3941 system-missing if @var{number} is not between -1 and 1 inclusive.
3942 Portability: none.
3943 @end deftypefn
3944
3945 @cindex arctangent
3946 @cindex inverse tangent
3947 @deftypefn {Function} {} ATAN (@var{number})
3948 Takes the arctangent, in radians, of @var{number}.
3949 @end deftypefn
3950
3951 @quotation
3952 @strong{Please note:} Use of the AR* group of inverse trigonometric
3953 functions is recommended over the A* group because they are more
3954 portable.
3955 @end quotation
3956
3957 @cindex cosine
3958 @deftypefn {Function} {} COS (@var{radians})
3959 Takes the cosine of @var{radians}.
3960 @end deftypefn
3961
3962 @cindex sine
3963 @deftypefn {Function} {} SIN (@var{angle})
3964 Takes the sine of @var{radians}.
3965 @end deftypefn
3966
3967 @cindex tangent
3968 @deftypefn {Function} {} TAN (@var{angle})
3969 Takes the tangent of @var{radians}.  Results in system-missing at values
3970 of @var{angle} that are too close to odd multiples of pi/2.
3971 Portability: none.
3972 @end deftypefn
3973
3974 @node Missing Value Functions, Pseudo-Random Numbers, Trigonometry, Functions
3975 @subsection Missing-Value Functions
3976 @cindex missing values
3977 @cindex values, missing
3978 @cindex functions, missing-value
3979
3980 Missing-value functions take various types as arguments, returning
3981 various types of results.
3982
3983 @deftypefn {Function} {} MISSING (@var{variable or expression})
3984 @var{num} may be a single variable name or an expression.  If it is a
3985 variable name, results in 1 if the variable has a user-missing or
3986 system-missing value for the current case, 0 otherwise.  If it is an
3987 expression, results in 1 if the expression has the system-missing value,
3988 0 otherwise.
3989
3990 @quotation
3991 @strong{Please note:} If the argument is a string expression other than
3992 a variable name, MISSING is guaranteed to return 0, because strings do
3993 not have a system-missing value.  Also, when using a numeric expression
3994 argument, remember that user-missing values are converted to the
3995 system-missing value in most contexts.  Thus, the expressions
3996 @code{MISSING(VAR1 @var{op} VAR2)} and @code{MISSING(VAR1) OR
3997 MISSING(VAR2)} are often equivalent, depending on the specific operator
3998 @var{op} used.
3999 @end quotation
4000 @end deftypefn
4001
4002 @deftypefn {Function} {} NMISS (@var{expr} [, @var{expr}]@dots{})
4003 Each argument must be a numeric expression.  Returns the number of
4004 user- or system-missing values in the list.  As a special extension,
4005 the syntax @code{@var{var1} TO @var{var2}} may be used to refer to a
4006 range of variables; see @ref{Sets of Variables}, for more details.
4007 @end deftypefn
4008
4009 @deftypefn {Function} {} NVALID (@var{expr} [, @var{expr}]@dots{})
4010 Each argument must be a numeric expression.  Returns the number of
4011 values in the list that are not user- or system-missing.  As a special extension,
4012 the syntax @code{@var{var1} TO @var{var2}} may be used to refer to a
4013 range of variables; see @ref{Sets of Variables}, for more details.
4014 @end deftypefn
4015
4016 @deftypefn {Function} {} SYSMIS (@var{variable or expression})
4017 When given the name of a numeric variable, returns 1 if the value of
4018 that variable is system-missing.  Otherwise, if the value is not
4019 missing or if it is user-missing, returns 0.  If given the name of a
4020 string variable, always returns 1.  If given an expression other than
4021 a single variable name, results in 1 if the value is system- or
4022 user-missing, 0 otherwise.
4023 @end deftypefn
4024
4025 @deftypefn {Function} {} VALUE (@var{variable})
4026 Prevents the user-missing values of @var{variable} from being
4027 transformed into system-missing values: If @var{variable} is not
4028 system- or user-missing, results in the value of @var{variable}.  If
4029 @var{variable} is user-missing, results in the value of @var{variable}
4030 anyway.  If @var{variable} is system-missing, results in system-missing.
4031 @end deftypefn
4032
4033 @node Pseudo-Random Numbers, Set Membership, Missing Value Functions, Functions
4034 @subsection Pseudo-Random Number Generation Functions
4035 @cindex random numbers
4036 @cindex pseudo-random numbers (see random numbers)
4037
4038 Pseudo-random number generation functions take numeric arguments and
4039 produce numeric results.
4040
4041 @cindex Knuth
4042 The system's C library random generator is used as a basis for
4043 generating random numbers, since random number generation is a
4044 system-dependent task.  However, Knuth's Algorithm B is used to
4045 shuffle the resultant values, which is enough to make even a stream of
4046 consecutive integers random enough for most applications.
4047
4048 (If you're worried about the quality of the random number generator,
4049 well, you're using a statistical processing package---analyze it!)
4050
4051 @cindex random numbers, normally-distributed
4052 @deftypefn {Function} {} NORMAL (@var{number})
4053 Results in a random number.  Results from @code{NORMAL} are normally
4054 distributed with a mean of 0 and a standard deviation of @var{number}.
4055 @end deftypefn
4056
4057 @cindex random numbers, uniformly-distributed
4058 @deftypefn {Function} {} UNIFORM (@var{number})
4059 Results in a random number between 0 and @var{number}.  Results from
4060 @code{UNIFORM} are evenly distributed across its entire range.  There
4061 may be a maximum on the largest random number ever generated---this is
4062 often 2**31-1 (2,147,483,647), but it may be orders of magnitude
4063 higher or lower.
4064 @end deftypefn
4065
4066 @node Set Membership, Statistical Functions, Pseudo-Random Numbers, Functions
4067 @subsection Set-Membership Functions
4068 @cindex set membership
4069 @cindex membership, of set
4070
4071 Set membership functions determine whether a value is a member of a set.
4072 They take a set of numeric arguments or a set of string arguments, and
4073 produce Boolean results.
4074
4075 String comparisons are performed according to the rules given in
4076 @ref{Relational Operators}.
4077
4078 @deftypefn {Function} {} ANY (@var{value}, @var{set} [, @var{set}]@dots{})
4079 Results in true if @var{value} is equal to any of the @var{set}
4080 values.  Otherwise, results in false.  If @var{value} is
4081 system-missing, returns system-missing.  System-missing values in
4082 @var{set} do not cause ANY to return system-missing.
4083 @end deftypefn
4084
4085 @deftypefn {Function} {} RANGE (@var{value}, @var{low}, @var{high} [, @var{low}, @var{high}]@dots{})
4086 Results in true if @var{value} is in any of the intervals bounded by
4087 @var{low} and @var{high} inclusive.  Otherwise, results in false.
4088 Each @var{low} must be less than or equal to its corresponding
4089 @var{high} value.  @var{low} and @var{high} must be given in pairs.
4090 If @var{value} is system-missing, returns system-missing.
4091 System-missing values in @var{set} do not cause RANGE to return
4092 system-missing.
4093 @end deftypefn
4094
4095 @node Statistical Functions, String Functions, Set Membership, Functions
4096 @subsection Statistical Functions
4097 @cindex functions, statistical
4098 @cindex statistics
4099
4100 Statistical functions compute descriptive statistics on a list of
4101 values.  Some statistics can be computed on numeric or string values;
4102 other can only be computed on numeric values.  They result in the same
4103 type as their arguments.
4104
4105 @cindex arguments, minimum valid
4106 @cindex minimum valid number of arguments
4107 With statistical functions it is possible to specify a minimum number of
4108 non-missing arguments for the function to be evaluated.  To do so,
4109 append a dot and the number to the function name.  For instance, to
4110 specify a minimum of three valid arguments to the MEAN function, use the
4111 name @code{MEAN.3}.
4112
4113 @cindex coefficient of variation
4114 @cindex variation, coefficient of
4115 @deftypefn {Function} {} CFVAR (@var{number}, @var{number}[, @dots{}])
4116 Results in the coefficient of variation of the values of @var{number}.
4117 This function requires at least two valid arguments to give a
4118 non-missing result.  (The coefficient of variation is the standard
4119 deviation divided by the mean.)
4120 @end deftypefn
4121
4122 @cindex maximum
4123 @deftypefn {Function} {} MAX (@var{value}, @var{value}[, @dots{}])
4124 Results in the value of the greatest @var{value}.  The @var{value}s may
4125 be numeric or string.  Although at least two arguments must be given,
4126 only one need be valid for MAX to give a non-missing result.
4127 @end deftypefn
4128
4129 @cindex mean
4130 @deftypefn {Function} {} MEAN (@var{number}, @var{number}[, @dots{}])
4131 Results in the mean of the values of @var{number}.  Although at least
4132 two arguments must be given, only one need be valid for MEAN to give a
4133 non-missing result.
4134 @end deftypefn
4135
4136 @cindex minimum
4137 @deftypefn {Function} {} MIN (@var{number}, @var{number}[, @dots{}])
4138 Results in the value of the least @var{value}.  The @var{value}s may
4139 be numeric or string.  Although at least two arguments must be given,
4140 only one need be valid for MAX to give a non-missing result.
4141 @end deftypefn
4142
4143 @cindex standard deviation
4144 @cindex deviation, standard
4145 @deftypefn {Function} {} SD (@var{number}, @var{number}[, @dots{}])
4146 Results in the standard deviation of the values of @var{number}.
4147 This function requires at least two valid arguments to give a
4148 non-missing result.
4149 @end deftypefn
4150
4151 @cindex sum
4152 @deftypefn {Function} {} SUM (@var{number}, @var{number}[, @dots{}])
4153 Results in the sum of the values of @var{number}.  Although at least two
4154 arguments must be given, only one need by valid for SUM to give a
4155 non-missing result.
4156 @end deftypefn
4157
4158 @cindex variance
4159 @deftypefn {Function} {} VAR (@var{number}, @var{number}[, @dots{}])
4160 Results in the variance of the values of @var{number}.  This function
4161 requires at least two valid arguments to give a non-missing result.
4162 @end deftypefn
4163
4164 @deftypefn {Function} {} VARIANCE (@var{number}, @var{number}[, @dots{}])
4165 Results in the variance of the values of @var{number}.  This function
4166 requires at least two valid arguments to give a non-missing result.
4167 (Use VAR in preference to VARIANCE for reasons of portability.)
4168 @end deftypefn
4169
4170 @node String Functions, Time & Date, Statistical Functions, Functions
4171 @subsection String Functions
4172 @cindex functions, string
4173 @cindex string functions
4174
4175 String functions take various arguments and return various results.
4176
4177 @cindex concatenation
4178 @cindex strings, concatenation of
4179 @deftypefn {Function} {} CONCAT (@var{string}, @var{string}[, @dots{}])
4180 Returns a string consisting of each @var{string} in sequence.
4181 @code{CONCAT("abc", "def", "ghi")} has a value of @code{"abcdefghi"}.
4182 The resultant string is truncated to a maximum of 255 characters.
4183 @end deftypefn
4184
4185 @cindex searching strings
4186 @deftypefn {Function} {} INDEX (@var{haystack}, @var{needle})
4187 Returns a positive integer indicating the position of the first
4188 occurrence @var{needle} in @var{haystack}.  Returns 0 if @var{haystack}
4189 does not contain @var{needle}.  Returns system-missing if @var{needle}
4190 is an empty string.
4191 @end deftypefn
4192
4193 @deftypefn {Function} {} INDEX (@var{haystack}, @var{needle}, @var{divisor})
4194 Divides @var{needle} into parts, each with length @var{divisor}.
4195 Searches @var{haystack} for the first occurrence of each part, and
4196 returns the smallest value.  Returns 0 if @var{haystack} does not
4197 contain any part in @var{needle}.  It is an error if @var{divisor}
4198 cannot be evenly divided into the length of @var{needle}.  Returns
4199 system-missing if @var{needle} is an empty string.
4200 @end deftypefn
4201
4202 @cindex strings, finding length of
4203 @deftypefn {Function} {} LENGTH (@var{string})
4204 Returns the number of characters in @var{string}.
4205 @end deftypefn
4206
4207 @cindex strings, case of
4208 @deftypefn {Function} {} LOWER (@var{string})
4209 Returns a string identical to @var{string} except that all uppercase
4210 letters are changed to lowercase letters.  The definitions of
4211 ``uppercase'' and ``lowercase'' are system-dependent.
4212 @end deftypefn
4213
4214 @cindex strings, padding
4215 @deftypefn {Function} {} LPAD (@var{string}, @var{length})
4216 If @var{string} is at least @var{length} characters in length, returns
4217 @var{string} unchanged.  Otherwise, returns @var{string} padded with
4218 spaces on the left side to length @var{length}.  Returns an empty string
4219 if @var{length} is system-missing, negative, or greater than 255.
4220 @end deftypefn
4221
4222 @deftypefn {Function} {} LPAD (@var{string}, @var{length}, @var{padding})
4223 If @var{string} is at least @var{length} characters in length, returns
4224 @var{string} unchanged.  Otherwise, returns @var{string} padded with
4225 @var{padding} on the left side to length @var{length}.  Returns an empty
4226 string if @var{length} is system-missing, negative, or greater than 255, or
4227 if @var{padding} does not contain exactly one character.
4228 @end deftypefn
4229
4230 @cindex strings, trimming
4231 @cindex whitespace, trimming
4232 @deftypefn {Function} {} LTRIM (@var{string})
4233 Returns @var{string}, after removing leading spaces.  Other whitespace,
4234 such as tabs, carriage returns, line feeds, and vertical tabs, is not
4235 removed.
4236 @end deftypefn
4237
4238 @deftypefn {Function} {} LTRIM (@var{string}, @var{padding})
4239 Returns @var{string}, after removing leading @var{padding} characters.
4240 If @var{padding} does not contain exactly one character, returns an
4241 empty string.
4242 @end deftypefn
4243
4244 @cindex numbers, converting from strings
4245 @cindex strings, converting to numbers
4246 @deftypefn {Function} {} NUMBER (@var{string})
4247 Returns the number produced when @var{string} is interpreted according
4248 to format F@var{x}.0, where @var{x} is the number of characters in
4249 @var{string}.  If @var{string} does not form a proper number,
4250 system-missing is returned without an error message.  Portability: none.
4251 @end deftypefn
4252
4253 @deftypefn {Function} {} NUMBER (@var{string}, @var{format})
4254 Returns the number produced when @var{string} is interpreted according
4255 to format specifier @var{format}.  Only the number of characters in
4256 @var{string} specified by @var{format} are examined.  For example,
4257 @code{NUMBER("123", F3.0)} and @code{NUMBER("1234", F3.0)} both have
4258 value 123.  If @var{string} does not form a proper number,
4259 system-missing is returned without an error message.
4260 @end deftypefn
4261
4262 @cindex strings, searching backwards
4263 @deftypefn {Function} {} RINDEX (@var{string}, @var{format})
4264 Returns a positive integer indicating the position of the last
4265 occurrence of @var{needle} in @var{haystack}.  Returns 0 if
4266 @var{haystack} does not contain @var{needle}.  Returns system-missing if
4267 @var{needle} is an empty string.
4268 @end deftypefn
4269
4270 @deftypefn {Function} {} RINDEX (@var{haystack}, @var{needle}, @var{divisor})
4271 Divides @var{needle} into parts, each with length @var{divisor}.
4272 Searches @var{haystack} for the last occurrence of each part, and
4273 returns the largest value.  Returns 0 if @var{haystack} does not contain
4274 any part in @var{needle}.  It is an error if @var{divisor} cannot be
4275 evenly divided into the length of @var{needle}.  Returns system-missing
4276 if @var{needle} is an empty string.
4277 @end deftypefn
4278
4279 @cindex padding strings
4280 @cindex strings, padding
4281 @deftypefn {Function} {} RPAD (@var{string}, @var{length})
4282 If @var{string} is at least @var{length} characters in length, returns
4283 @var{string} unchanged.  Otherwise, returns @var{string} padded with
4284 spaces on the right to length @var{length}.  Returns an empty string if
4285 @var{length} is system-missing, negative, or greater than 255.
4286 @end deftypefn
4287
4288 @deftypefn {Function} {} RPAD (@var{string}, @var{length}, @var{padding})
4289 If @var{string} is at least @var{length} characters in length, returns
4290 @var{string} unchanged.  Otherwise, returns @var{string} padded with
4291 @var{padding} on the right to length @var{length}.  Returns an empty
4292 string if @var{length} is system-missing, negative, or greater than 255,
4293 or if @var{padding} does not contain exactly one character.
4294 @end deftypefn
4295
4296 @cindex strings, trimming
4297 @cindex whitespace, trimming
4298 @deftypefn {Function} {} RTRIM (@var{string})
4299 Returns @var{string}, after removing trailing spaces.  Other types of
4300 whitespace are not removed.
4301 @end deftypefn
4302
4303 @deftypefn {Function} {} RTRIM (@var{string}, @var{padding})
4304 Returns @var{string}, after removing trailing @var{padding} characters.
4305 If @var{padding} does not contain exactly one character, returns an
4306 empty string.
4307 @end deftypefn
4308
4309 @cindex strings, converting from numbers
4310 @cindex numbers, converting to strings
4311 @deftypefn {Function} {} STRING (@var{number}, @var{format})
4312 Returns a string corresponding to @var{number} in the format given by
4313 format specifier @var{format}.  For example, @code{STRING(123.56, F5.1)}
4314 has the value @code{"123.6"}.
4315 @end deftypefn
4316
4317 @cindex substrings
4318 @cindex strings, taking substrings of
4319 @deftypefn {Function} {} SUBSTR (@var{string}, @var{start})
4320 Returns a string consisting of the value of @var{string} from position
4321 @var{start} onward.  Returns an empty string if @var{start} is system-missing
4322 or has a value less than 1 or greater than the number of characters in
4323 @var{string}.
4324 @end deftypefn
4325
4326 @deftypefn {Function} {} SUBSTR (@var{string}, @var{start}, @var{count})
4327 Returns a string consisting of the first @var{count} characters from
4328 @var{string} beginning at position @var{start}.  Returns an empty string
4329 if @var{start} or @var{count} is system-missing, if @var{start} is less
4330 than 1 or greater than the number of characters in @var{string}, or if
4331 @var{count} is less than 1.  Returns a string shorter than @var{count}
4332 characters if @var{start} + @var{count} - 1 is greater than the number
4333 of characters in @var{string}.  Examples: @code{SUBSTR("abcdefg", 3, 2)}
4334 has value @code{"cd"}; @code{SUBSTR("Ben Pfaff", 5, 10)} has the value
4335 @code{"Pfaff"}.
4336 @end deftypefn
4337
4338 @cindex case conversion
4339 @cindex strings, case of
4340 @deftypefn {Function} {} UPCASE (@var{string})
4341 Returns @var{string}, changing lowercase letters to uppercase letters.
4342 @end deftypefn
4343
4344 @node Time & Date, Miscellaneous Functions, String Functions, Functions
4345 @subsection Time & Date Functions
4346 @cindex functions, time & date
4347 @cindex times
4348 @cindex dates
4349
4350 @cindex dates, legal range of
4351 The legal range of dates for use in PSPP is 15 Oct 1582
4352 through 31 Dec 19999.
4353
4354 @cindex arguments, invalid
4355 @cindex invalid arguments
4356 @quotation
4357 @strong{Please note:} Most time & date extraction functions will accept
4358 invalid arguments:
4359
4360 @itemize @bullet
4361 @item
4362 Negative numbers in PSPP time format.
4363 @item
4364 Numbers less than 86,400 in PSPP date format.
4365 @end itemize
4366
4367 However, sensible results are not guaranteed for these invalid values.
4368 The given equivalents for these functions are definitely not guaranteed
4369 for invalid values.
4370 @end quotation
4371
4372 @quotation
4373 @strong{Please note also:} The time & date construction
4374 functions @strong{do} produce reasonable and useful results for
4375 out-of-range values; these are not considered invalid.
4376 @end quotation
4377
4378 @menu
4379 * Time & Date Concepts::        How times & dates are defined and represented
4380 * Time Construction::           TIME.@{DAYS HMS@}
4381 * Time Extraction::             CTIME.@{DAYS HOURS MINUTES SECONDS@}
4382 * Date Construction::           DATE.@{DMY MDY MOYR QYR WKYR YRDAY@}
4383 * Date Extraction::             XDATE.@{DATE HOUR JDAY MDAY MINUTE MONTH
4384                                        QUARTER SECOND TDAY TIME WEEK
4385                                        WKDAY YEAR@}
4386 @end menu
4387
4388 @node Time & Date Concepts, Time Construction, Time & Date, Time & Date
4389 @subsubsection How times & dates are defined and represented
4390
4391 @cindex time, concepts
4392 @cindex time, intervals
4393 Times and dates are handled by PSPP as single numbers.  A
4394 @dfn{time} is an interval.  PSPP measures times in seconds.
4395 Thus, the following intervals correspond with the numeric values given:
4396                 
4397 @example
4398           10 minutes                        600
4399           1 hour                          3,600
4400           1 day, 3 hours, 10 seconds     97,210
4401           40 days                     3,456,000
4402           10010 d, 14 min, 24 s     864,864,864
4403 @end example
4404
4405 @cindex dates, concepts
4406 @cindex time, instants of
4407 A @dfn{date}, on the other hand, is a particular instant in the past or
4408 the future.  PSPP represents a date as a number of seconds after the
4409 midnight that separated 8 Oct 1582 and 9 Oct 1582.  (Please note that 15
4410 Oct 1582 immediately followed 9 Oct 1582.)  Thus, the midnights before
4411 the dates given below correspond with the numeric PSPP dates given:
4412
4413 @example
4414               15 Oct 1582                86,400
4415                4 Jul 1776         6,113,318,400
4416                1 Jan 1900        10,010,390,400
4417                1 Oct 1978        12,495,427,200
4418               24 Aug 1995        13,028,601,600
4419 @end example
4420
4421 @cindex time, mathematical properties of
4422 @cindex mathematics, applied to times & dates
4423 @cindex dates, mathematical properties of
4424 @noindent
4425 Please note: 
4426
4427 @itemize @bullet
4428 @item
4429 A time may be added to, or subtracted from, a date, resulting in a date.
4430
4431 @item
4432 The difference of two dates may be taken, resulting in a time.  
4433
4434 @item 
4435 Two times may be added to, or subtracted from, each other, resulting in
4436 a time.
4437 @end itemize
4438
4439 (Adding two dates does not produce a useful result.)
4440
4441 Since times and dates are merely numbers, the ordinary addition and
4442 subtraction operators are employed for these purposes.
4443
4444 @quotation
4445 @strong{Please note:} Many dates and times have extremely large
4446 values---just look at the values above.  Thus, it is not a good idea to
4447 take powers of these values; also, the accuracy of some procedures may
4448 be affected.  If necessary, convert times or dates in seconds to some
4449 other unit, like days or years, before performing analysis.
4450 @end quotation
4451
4452 @node Time Construction, Time Extraction, Time & Date Concepts, Time & Date
4453 @subsubsection Functions that Produce Times
4454 @cindex times, constructing
4455 @cindex constructing times
4456
4457 These functions take numeric arguments and produce numeric results in
4458 PSPP time format.
4459
4460 @cindex days
4461 @cindex time, in days
4462 @deftypefn {Function} {} TIME.DAYS (@var{ndays})
4463 Results in a time value corresponding to @var{ndays} days.
4464 (@code{TIME.DAYS(@var{x})} is equivalent to @code{@var{x} * 60 * 60 *
4465 24}.)
4466 @end deftypefn
4467
4468 @cindex hours-minutes-seconds
4469 @cindex time, in hours-minutes-seconds
4470 @deftypefn {Function} {} TIME.HMS (@var{nhours}, @var{nmins}, @var{nsecs})
4471 Results in a time value corresponding to @var{nhours} hours, @var{nmins}
4472 minutes, and @var{nsecs} seconds.  (@code{TIME.HMS(@var{h}, @var{m},
4473 @var{s})} is equivalent to @code{@var{h}*60*60 + @var{m}*60 +
4474 @var{s}}.)
4475 @end deftypefn
4476
4477 @node Time Extraction, Date Construction, Time Construction, Time & Date
4478 @subsubsection Functions that Examine Times
4479 @cindex extraction, of time
4480 @cindex time examination
4481 @cindex examination, of times
4482 @cindex time, lengths of
4483
4484 These functions take numeric arguments in PSPP time format and
4485 give numeric results.
4486
4487 @cindex days
4488 @cindex time, in days
4489 @deftypefn {Function} {} CTIME.DAYS (@var{time})
4490 Results in the number of days and fractional days in @var{time}.
4491 (@code{CTIME.DAYS(@var{x})} is equivalent to @code{@var{x}/60/60/24}.)
4492 @end deftypefn
4493
4494 @cindex hours
4495 @cindex time, in hours
4496 @deftypefn {Function} {} CTIME.HOURS (@var{time})
4497 Results in the number of hours and fractional hours in @var{time}.
4498 (@code{CTIME.HOURS(@var{x})} is equivalent to @code{@var{x}/60/60}.)
4499 @end deftypefn
4500
4501 @cindex minutes
4502 @cindex time, in minutes
4503 @deftypefn {Function} {} CTIME.MINUTES (@var{time})
4504 Results in the number of minutes and fractional minutes in @var{time}.
4505 (@code{CTIME.MINUTES(@var{x})} is equivalent to @code{@var{x}/60}.)
4506 @end deftypefn
4507
4508 @cindex seconds
4509 @cindex time, in seconds
4510 @deftypefn {Function} {} CTIME.SECONDS (@var{time})
4511 Results in the number of seconds and fractional seconds in @var{time}.
4512 (@code{CTIME.SECONDS} does nothing; @code{CTIME.SECONDS(@var{x})} is
4513 equivalent to @code{@var{x}}.)
4514 @end deftypefn
4515
4516 @node Date Construction, Date Extraction, Time Extraction, Time & Date
4517 @subsubsection Functions that Produce Dates
4518 @cindex dates, constructing
4519 @cindex constructing dates
4520
4521 @cindex arguments, of date construction functions
4522 These functions take numeric arguments and give numeric results in the
4523 PSPP date format.  Arguments taken by these functions are:
4524
4525 @table @var
4526 @item day
4527 Refers to a day of the month between 1 and 31.
4528
4529 @item month
4530 Refers to a month of the year between 1 and 12.
4531
4532 @item quarter
4533 Refers to a quarter of the year between 1 and 4.  The quarters of the
4534 year begin on the first days of months 1, 4, 7, and 10.
4535
4536 @item week
4537 Refers to a week of the year between 1 and 53.
4538
4539 @item yday
4540 Refers to a day of the year between 1 and 366.
4541
4542 @item year
4543 Refers to a year between 1582 and 19999.
4544 @end table
4545
4546 @cindex arguments, invalid
4547 If these functions' arguments are out-of-range, they are correctly
4548 normalized before conversion to date format.  Non-integers are rounded
4549 toward zero.
4550
4551 @cindex day-month-year
4552 @cindex dates, day-month-year
4553 @deftypefn {Function} {} DATE.DMY (@var{day}, @var{month}, @var{year})
4554 @deftypefnx {Function} {} DATE.MDY (@var{month}, @var{day}, @var{year})
4555 Results in a date value corresponding to the midnight before day
4556 @var{day} of month @var{month} of year @var{year}.
4557 @end deftypefn
4558
4559 @cindex month-year
4560 @cindex dates, month-year
4561 @deftypefn {Function} {} DATE.MOYR (@var{month}, @var{year})
4562 Results in a date value corresponding to the midnight before the first
4563 day of month @var{month} of year @var{year}.
4564 @end deftypefn
4565
4566 @cindex quarter-year
4567 @cindex dates, quarter-year
4568 @deftypefn {Function} {} DATE.QYR (@var{quarter}, @var{year})
4569 Results in a date value corresponding to the midnight before the first
4570 day of quarter @var{quarter} of year @var{year}.
4571 @end deftypefn
4572
4573 @cindex week-year
4574 @cindex dates, week-year
4575 @deftypefn {Function} {} DATE.WKYR (@var{week}, @var{year})
4576 Results in a date value corresponding to the midnight before the first
4577 day of week @var{week} of year @var{year}.
4578 @end deftypefn
4579
4580 @cindex year-day
4581 @cindex dates, year-day
4582 @deftypefn {Function} {} DATE.YRDAY (@var{year}, @var{yday})
4583 Results in a date value corresponding to the midnight before day
4584 @var{yday} of year @var{year}.
4585 @end deftypefn
4586
4587 @node Date Extraction,  , Date Construction, Time & Date
4588 @subsubsection Functions that Examine Dates
4589 @cindex extraction, of dates
4590 @cindex date examination
4591
4592 @cindex arguments, of date extraction functions
4593 These functions take numeric arguments in PSPP date or time
4594 format and give numeric results.  These names are used for arguments:
4595
4596 @table @var
4597 @item date
4598 A numeric value in PSPP date format.
4599
4600 @item time
4601 A numeric value in PSPP time format.
4602
4603 @item time-or-date
4604 A numeric value in PSPP time or date format.
4605 @end table
4606
4607 @cindex days
4608 @cindex dates, in days
4609 @cindex time, in days
4610 @deftypefn {Function} {} XDATE.DATE (@var{time-or-date})
4611 For a time, results in the time corresponding to the number of whole
4612 days @var{date-or-time} includes.  For a date, results in the date
4613 corresponding to the latest midnight at or before @var{date-or-time};
4614 that is, gives the date that @var{date-or-time} is in.
4615 (XDATE.DATE(@var{x}) is equivalent to TRUNC(@var{x}/86400)*86400.)
4616 Applying this function to a time is a Portability: none feature.
4617 @end deftypefn
4618
4619 @cindex hours
4620 @cindex dates, in hours
4621 @cindex time, in hours
4622 @deftypefn {Function} {} XDATE.HOUR (@var{time-or-date})
4623 For a time, results in the number of whole hours beyond the number of
4624 whole days represented by @var{date-or-time}.  For a date, results in
4625 the hour (as an integer between 0 and 23) corresponding to
4626 @var{date-or-time}.  (XDATE.HOUR(@var{x}) is equivalent to
4627 MOD(TRUNC(@var{x}/3600),24))  Applying this function to a time is a
4628 Portability: none feature.
4629 @end deftypefn
4630
4631 @cindex day of the year
4632 @cindex dates, day of the year
4633 @deftypefn {Function} {} XDATE.JDAY(@var{date})
4634 Results in the day of the year (as an integer between 1 and 366)
4635 corresponding to @var{date}.
4636 @end deftypefn
4637
4638 @cindex day of the month
4639 @cindex dates, day of the month
4640 @deftypefn {Function} {} XDATE.MDAY(@var{date})
4641 Results in the day of the month (as an integer between 1 and 31)
4642 corresponding to @var{date}.
4643 @end deftypefn
4644
4645 @cindex minutes
4646 @cindex dates, in minutes
4647 @cindex time, in minutes
4648 @deftypefn {Function} {} XDATE.MINUTE(@var{time-or-date})
4649 Results in the number of minutes (as an integer between 0 and 59) after
4650 the last hour in @var{time-or-date}.  (XDATE.MINUTE(@var{x}) is
4651 equivalent to MOD(TRUNC(@var{x}/60),60)) Applying this function to a
4652 time is a Portability: none feature.
4653 @end deftypefn
4654
4655 @cindex months
4656 @cindex dates, in months
4657 @deftypefn {Function} {} XDATE.MONTH(@var{date})
4658 Results in the month of the year (as an integer between 1 and 12)
4659 corresponding to @var{date}.
4660 @end deftypefn
4661
4662 @cindex quarters
4663 @cindex dates, in quarters
4664 @deftypefn {Function} {} XDATE.QUARTER(@var{date})
4665 Results in the quarter of the year (as an integer between 1 and 4)
4666 corresponding to @var{date}.
4667 @end deftypefn
4668
4669 @cindex seconds
4670 @cindex dates, in seconds
4671 @cindex time, in seconds
4672 @deftypefn {Function} {} XDATE.SECOND(@var{time-or-date})
4673 Results in the number of whole seconds after the last whole minute (as
4674 an integer between 0 and 59) in @var{time-or-date}.
4675 (XDATE.SECOND(@var{x}) is equivalent to MOD(@var{x}, 60).)  Applying
4676 this function to a time is a Portability: none feature.
4677 @end deftypefn
4678
4679 @cindex days
4680 @cindex times, in days
4681 @deftypefn {Function} {} XDATE.TDAY(@var{time})
4682 Results in the number of whole days (as an integer) in @var{time}.
4683 (XDATE.TDAY(@var{x}) is equivalent to TRUNC(@var{x}/86400).)
4684 @end deftypefn
4685
4686 @cindex time
4687 @cindex dates, time of day
4688 @deftypefn {Function} {} XDATE.TIME(@var{date})
4689 Results in the time of day at the instant corresponding to @var{date},
4690 in PSPP time format.  This is the number of seconds since
4691 midnight on the day corresponding to @var{date}.  (XDATE.TIME(@var{x}) is
4692 equivalent to TRUNC(@var{x}/86400)*86400.)
4693 @end deftypefn
4694
4695 @cindex week
4696 @cindex dates, in weeks
4697 @deftypefn {Function} {} XDATE.WEEK(@var{date})
4698 Results in the week of the year (as an integer between 1 and 53)
4699 corresponding to @var{date}.
4700 @end deftypefn
4701
4702 @cindex day of the week
4703 @cindex weekday
4704 @cindex dates, day of the week
4705 @cindex dates, in weekdays
4706 @deftypefn {Function} {} XDATE.WKDAY(@var{date})
4707 Results in the day of week (as an integer between 1 and 7) corresponding
4708 to @var{date}.  The days of the week are:
4709
4710 @table @asis
4711 @item 1
4712 Sunday
4713 @item 2
4714 Monday
4715 @item 3
4716 Tuesday
4717 @item 4
4718 Wednesday
4719 @item 5
4720 Thursday
4721 @item 6
4722 Friday
4723 @item 7
4724 Saturday
4725 @end table
4726 @end deftypefn
4727
4728 @cindex years
4729 @cindex dates, in years
4730 @deftypefn {Function} {} XDATE.YEAR (@var{date})
4731 Returns the year (as an integer between 1582 and 19999) corresponding to
4732 @var{date}.
4733 @end deftypefn
4734
4735 @node Miscellaneous Functions, Functions Not Implemented, Time & Date, Functions
4736 @subsection Miscellaneous Functions
4737 @cindex functions, miscellaneous
4738
4739 Miscellaneous functions take various arguments and produce various
4740 results.
4741
4742 @cindex cross-case function
4743 @cindex function, cross-case
4744 @deftypefn {Function} {} LAG (@var{variable})
4745 @var{variable} must be a numeric or string variable name.  @code{LAG}
4746 results in the value of that variable for the case before the current
4747 one.  In case-selection procedures, @code{LAG} results in the value of
4748 the variable for the last case selected.  Results in system-missing (for
4749 numeric variables) or blanks (for string variables) for the first case
4750 or before any cases are selected.
4751 @end deftypefn
4752
4753 @deftypefn {Function} {} LAG (@var{variable}, @var{ncases})
4754 @var{variable} must be a numeric or string variable name.  @var{ncases}
4755 must be a small positive constant integer, although there is no explicit
4756 limit.  (Use of a large value for @var{ncases} will increase memory
4757 consumption, since PSPP must keep @var{ncases} cases in memory.)
4758 @code{LAG (@var{variable}, @var{ncases}} results in the value of
4759 @var{variable} that is @var{ncases} before the case currently being
4760 processed.  See @code{LAG (@var{variable})} above for more details.
4761 @end deftypefn
4762
4763 @cindex date, Julian
4764 @cindex Julian date
4765 @deftypefn {Function} {} YRMODA (@var{year}, @var{month}, @var{day})
4766 @var{year} is a year between 0 and 199 or 1582 and 19999.  @var{month} is
4767 a month between 1 and 12.  @var{day} is a day between 1 and 31.  If
4768 @var{month} or @var{day} is out-of-range, it changes the next higher
4769 unit.  For instance, a @var{day} of 0 refers to the last day of the
4770 previous month, and a @var{month} of 13 refers to the first month of the
4771 next year.  @var{year} must be in range.  If @var{year} is between 0 and
4772 199, 1900 is added.  @var{year}, @var{month}, and @var{day} must all be
4773 integers.
4774
4775 @code{YRMODA} results in the number of days between 15 Oct 1582 and
4776 the date specified, plus one.  The date passed to @code{YRMODA} must be
4777 on or after 15 Oct 1582.  15 Oct 1582 has a value of 1.
4778 @end deftypefn
4779
4780 @node Functions Not Implemented,  , Miscellaneous Functions, Functions
4781 @subsection Functions Not Implemented
4782 @cindex functions, not implemented
4783 @cindex not implemented
4784 @cindex features, not implemented
4785
4786 These functions are not yet implemented and thus not yet documented,
4787 since it's a hassle.
4788
4789 @findex CDF.xxx
4790 @findex CDFNORM
4791 @findex IDF.xxx
4792 @findex NCDF.xxx
4793 @findex PROBIT
4794 @findex RV.xxx
4795
4796 @itemize @bullet
4797 @item
4798 @code{CDF.xxx}
4799 @item
4800 @code{CDFNORM}
4801 @item
4802 @code{IDF.xxx}
4803 @item
4804 @code{NCDF.xxx}
4805 @item
4806 @code{PROBIT}
4807 @item
4808 @code{RV.xxx}
4809 @end itemize
4810
4811 @node Order of Operations,  , Functions, Expressions
4812 @section Operator Precedence
4813 @cindex operator precedence
4814 @cindex precedence, operator
4815 @cindex order of operations
4816 @cindex operations, order of
4817
4818 The following table describes operator precedence.  Smaller-numbered
4819 levels in the table have higher precedence.  Within a level, operations
4820 are performed from left to right, except for level 2 (exponentiation),
4821 where operations are performed from right to left.  If an operator
4822 appears in the table in two places (@code{-}), the first occurrence is
4823 unary, the second is binary.
4824
4825 @enumerate
4826 @item
4827 @code{(  )}
4828 @item
4829 @code{**}
4830 @item
4831 @code{-}
4832 @item
4833 @code{*  /}
4834 @item
4835 @code{+  -}
4836 @item
4837 @code{EQ  GE  GT  LE  LT  NE}
4838 @item
4839 @code{AND  NOT  OR}
4840 @end enumerate
4841
4842 @node Data Input and Output, System and Portable Files, Expressions, Top
4843 @chapter Data Input and Output
4844 @cindex input
4845 @cindex output
4846 @cindex data
4847
4848 Data is the focus of the PSPP language.  This chapter examines
4849 the PSPP commands for defining variables and reading and writing data.
4850
4851 @quotation
4852 @strong{Please note:} Data is not actually read until a procedure is
4853 executed.  These commands tell PSPP how to read data, but they
4854 do not @emph{cause} PSPP to read data.
4855 @end quotation
4856
4857 @menu
4858 * BEGIN DATA::                  Embed data within a syntax file.
4859 * CLEAR TRANSFORMATIONS::       Clear pending transformations.
4860 * DATA LIST::                   Fundamental data reading command.
4861 * END CASE::                    Output the current case.
4862 * END FILE::                    Terminate the current input program.
4863 * FILE HANDLE::                 Support for fixed-length records.
4864 * INPUT PROGRAM::               Support for complex input programs.
4865 * LIST::                        List cases in the active file.
4866 * MATRIX DATA::                 Read matrices in text format.
4867 * NEW FILE::                    Clear the active file and dictionary.
4868 * PRINT::                       Display values in print formats.
4869 * PRINT EJECT::                 Eject the current page then print.
4870 * PRINT SPACE::                 Print blank lines.
4871 * REREAD::                      Take another look at the previous input line.
4872 * REPEATING DATA::              Multiple cases on a single line.
4873 * WRITE::                       Display values in write formats.
4874 @end menu
4875
4876 @node BEGIN DATA, CLEAR TRANSFORMATIONS, Data Input and Output, Data Input and Output
4877 @section BEGIN DATA
4878 @vindex BEGIN DATA
4879 @vindex END DATA
4880 @cindex Embedding data in syntax files
4881 @cindex Data, embedding in syntax files
4882
4883 @display
4884 BEGIN DATA.
4885 @dots{}
4886 END DATA.
4887 @end display
4888
4889 BEGIN DATA and END DATA can be used to embed raw ASCII data in a PSPP
4890 syntax file.  DATA LIST or another input procedure must be used before
4891 BEGIN DATA (@pxref{DATA LIST}).  BEGIN DATA and END DATA must be used
4892 together.  The END DATA command must appear by itself on a single line,
4893 with no leading whitespace and exactly one space between the words
4894 @code{END} and @code{DATA}, followed immediately by the terminal dot,
4895 like this:
4896
4897 @example
4898 END DATA.
4899 @end example
4900
4901 @node CLEAR TRANSFORMATIONS, DATA LIST, BEGIN DATA, Data Input and Output
4902 @section CLEAR TRANSFORMATIONS
4903 @vindex CLEAR TRANSFORMATIONS
4904
4905 @display
4906 CLEAR TRANSFORMATIONS.
4907 @end display
4908
4909 The CLEAR TRANSFORMATIONS command clears out all pending
4910 transformations.  It does not cancel the current input program.  It is
4911 valid only when PSPP is interactive, not in syntax files.
4912
4913 @node DATA LIST, END CASE, CLEAR TRANSFORMATIONS, Data Input and Output
4914 @section DATA LIST
4915 @vindex DATA LIST
4916 @cindex reading data from a file
4917 @cindex data, reading from a file
4918 @cindex data, embedding in syntax files
4919 @cindex embedding data in syntax files
4920
4921 Used to read text or binary data, DATA LIST is the most
4922 fundamental data-reading command.  Even the more sophisticated input
4923 methods use DATA LIST commands as a building block.
4924 Understanding DATA LIST is important to understanding how to use
4925 PSPP to read your data files.
4926
4927 There are two major variants of DATA LIST, which are fixed
4928 format and free format.  In addition, free format has a minor variant,
4929 list format, which is discussed in terms of its differences from vanilla
4930 free format.
4931
4932 Each form of DATA LIST is described in detail below.
4933
4934 @menu
4935 * DATA LIST FIXED::             Fixed columnar locations for data.
4936 * DATA LIST FREE::              Any spacing you like.
4937 * DATA LIST LIST::              Each case must be on a single line.
4938 @end menu
4939
4940 @node DATA LIST FIXED, DATA LIST FREE, DATA LIST, DATA LIST
4941 @subsection DATA LIST FIXED
4942 @vindex DATA LIST FIXED
4943 @cindex reading fixed-format data
4944 @cindex fixed-format data, reading
4945 @cindex data, fixed-format, reading
4946 @cindex embedding fixed-format data
4947
4948 @display
4949 DATA LIST [FIXED]
4950         @{TABLE,NOTABLE@}
4951         FILE='filename'
4952         RECORDS=record_count
4953         END=end_var
4954         /[line_no] var_spec@dots{}
4955
4956 where each var_spec takes one of the forms
4957         var_list start-end [type_spec]
4958         var_list (fortran_spec)
4959 @end display
4960
4961 DATA LIST FIXED is used to read data files that have values at fixed
4962 positions on each line of single-line or multiline records.  The
4963 keyword FIXED is optional.
4964
4965 The FILE subcommand must be used if input is to be taken from an
4966 external file.  It may be used to specify a filename as a string or a
4967 file handle (@pxref{FILE HANDLE}).  If the FILE subcommand is not used,
4968 then input is assumed to be specified within the command file using
4969 BEGIN DATA@dots{}END DATA (@pxref{BEGIN DATA}).
4970
4971 The optional RECORDS subcommand, which takes a single integer as an
4972 argument, is used to specify the number of lines per record.  If RECORDS
4973 is not specified, then the number of lines per record is calculated from
4974 the list of variable specifications later in the DATA LIST command.
4975
4976 The END subcommand is only useful in conjunction with the INPUT PROGRAM
4977 input procedure, and for that reason it is not discussed here
4978 (@pxref{INPUT PROGRAM}).
4979
4980 DATA LIST can optionally output a table describing how the data file
4981 will be read.  The TABLE subcommand enables this output, and NOTABLE
4982 disables it.  The default is to output the table.
4983
4984 The list of variables to be read from the data list must come last in
4985 the DATA LIST command.  Each line in the data record is introduced by a
4986 slash (@samp{/}).  Optionally, a line number may follow the slash.
4987 Following, any number of variable specifications may be present.
4988
4989 Each variable specification consists of a list of variable names
4990 followed by a description of their location on the input line.  Sets of
4991 variables may specified using DATA LIST's TO convention (@pxref{Sets of
4992 Variables}).  There are two ways to specify the location of the variable
4993 on the line: SPSS style and FORTRAN style.
4994
4995 With SPSS style, the starting column and ending column for the field
4996 are specified after the variable name, separated by a dash (@samp{-}).
4997 For instance, the third through fifth columns on a line would be
4998 specified @samp{3-5}.  By default, variables are considered to be in
4999 @samp{F} format (@pxref{Input/Output Formats}).  (This default can be
5000 changed; see @ref{SET} for more information.)
5001
5002 When using SPSS style, to use a variable format other than the default,
5003 specify the format type in parentheses after the column numbers.  For
5004 instance, for alphanumeric @samp{A} format, use @samp{(A)}.  
5005
5006 In addition, implied decimal places can be specified in parentheses
5007 after the column numbers.  As an example, suppose that a data file has a
5008 field in which the characters @samp{1234} should be interpreted as
5009 having the value 12.34.  Then this field has two implied decimal places,
5010 and the corresponding specification would be @samp{(2)}.  If a field
5011 that has implied decimal places contains a decimal point, then the
5012 implied decimal places are not applied.
5013
5014 Changing the variable format and adding implied decimal places can be
5015 done together; for instance, @samp{(N,5)}.
5016
5017 When using SPSS style, the input and output width of each variable is
5018 computed from the field width.  The field width must be evenly divisible
5019 into the number of variables specified.
5020
5021 FORTRAN style is an altogether different approach to specifying field
5022 locations.  With this approach, a list of variable input format
5023 specifications, separated by commas, are placed after the variable names
5024 inside parentheses.  Each format specifier advances as many characters
5025 into the input line as it uses.
5026
5027 In addition to the standard format specifiers (@pxref{Input/Output
5028 Formats}), FORTRAN style defines some extensions:
5029
5030 @table @asis
5031 @item @code{X}
5032 Advance the current column on this line by one character position.
5033
5034 @item @code{T}@var{x}
5035 Set the current column on this line to column @var{x}, with column
5036 numbers considered to begin with 1 at the left margin.
5037
5038 @item @code{NEWREC}@var{x}
5039 Skip forward @var{x} lines in the current record, resetting the active
5040 column to the left margin.
5041
5042 @item Repeat count
5043 Any format specifier may be preceded by a number.  This causes the
5044 action of that format specifier to be repeated the specified number of
5045 times.
5046
5047 @item (@var{spec1}, @dots{}, @var{specN})
5048 Group the given specifiers together.  This is most useful when preceded
5049 by a repeat count.  Groups may be nested arbitrarily.
5050 @end table
5051
5052 FORTRAN and SPSS styles may be freely intermixed.  SPSS style leaves the
5053 active column immediately after the ending column specified.  Record
5054 motion using @code{NEWREC} in FORTRAN style also applies to later
5055 FORTRAN and SPSS specifiers.
5056  
5057 @menu
5058 * DATA LIST FIXED Examples::    Examples of DATA LIST FIXED.
5059 @end menu
5060
5061 @node DATA LIST FIXED Examples,  , DATA LIST FIXED, DATA LIST FIXED
5062 @unnumberedsubsubsec Examples
5063
5064 @enumerate
5065 @item
5066 @example
5067 DATA LIST TABLE /NAME 1-10 (A) INFO1 TO INFO3 12-17 (1).
5068
5069 BEGIN DATA.
5070 John Smith 102311
5071 Bob Arnold 122015
5072 Bill Yates  918 6
5073 END DATA.
5074 @end example
5075
5076 Defines the following variables:
5077
5078 @itemize @bullet
5079 @item
5080 @code{NAME}, a 10-character-wide long string variable, in columns 1
5081 through 10.
5082
5083 @item
5084 @code{INFO1}, a numeric variable, in columns 12 through 13.
5085
5086 @item
5087 @code{INFO2}, a numeric variable, in columns 14 through 15.
5088
5089 @item
5090 @code{INFO3}, a numeric variable, in columns 16 through 17.
5091 @end itemize
5092
5093 The @code{BEGIN DATA}/@code{END DATA} commands cause three cases to be
5094 defined:
5095
5096 @example
5097 Case   NAME         INFO1   INFO2   INFO3
5098    1   John Smith     10      23      11
5099    2   Bob Arnold     12      20      15
5100    3   Bill Yates      9      18       6
5101 @end example
5102
5103 The @code{TABLE} keyword causes PSPP to print out a table
5104 describing the four variables defined.
5105
5106 @item
5107 @example
5108 DAT LIS FIL="survey.dat"
5109         /ID 1-5 NAME 7-36 (A) SURNAME 38-67 (A) MINITIAL 69 (A)
5110         /Q01 TO Q50 7-56
5111         /.
5112 @end example
5113
5114 Defines the following variables:
5115
5116 @itemize @bullet
5117 @item
5118 @code{ID}, a numeric variable, in columns 1-5 of the first record.
5119
5120 @item
5121 @code{NAME}, a 30-character long string variable, in columns 7-36 of the
5122 first record.
5123
5124 @item
5125 @code{SURNAME}, a 30-character long string variable, in columns 38-67 of
5126 the first record.
5127
5128 @item
5129 @code{MINITIAL}, a 1-character short string variable, in column 69 of
5130 the first record.
5131
5132 @item
5133 Fifty variables @code{Q01}, @code{Q02}, @code{Q03}, @dots{}, @code{Q49},
5134 @code{Q50}, all numeric, @code{Q01} in column 7, @code{Q02} in column 8,
5135 @dots{}, @code{Q49} in column 55, @code{Q50} in column 56, all in the second
5136 record.
5137 @end itemize
5138
5139 Cases are separated by a blank record.
5140
5141 Data is read from file @file{survey.dat} in the current directory.
5142
5143 This example shows keywords abbreviated to their first 3 letters.
5144
5145 @end enumerate
5146
5147 @node DATA LIST FREE, DATA LIST LIST, DATA LIST FIXED, DATA LIST
5148 @subsection DATA LIST FREE
5149 @vindex DATA LIST FREE
5150
5151 @display
5152 DATA LIST FREE
5153         [@{NOTABLE,TABLE@}]
5154         FILE='filename'
5155         END=end_var
5156         /var_spec@dots{}
5157
5158 where each var_spec takes one of the forms
5159         var_list [(type_spec)]
5160         var_list *
5161 @end display
5162
5163 In free format, the input data is structured as a series of comma- or
5164 whitespace-delimited fields (end of line is one form of whitespace; it
5165 is not treated specially).  Field contents may be surrounded by matched
5166 pairs of apostrophes (@samp{'}) or quotes (@samp{"}), or they may be
5167 unenclosed.  For any type of field leading white space (up to the
5168 apostrophe or quote, if any) is not included in the field.
5169
5170 Multiple consecutive delimiters are equivalent to a single delimiter.
5171 To specify an empty field, write an empty set of single or double
5172 quotes; for instance, @samp{""}.
5173
5174 The NOTABLE and TABLE subcommands are as in DATA LIST FIXED above.
5175 NOTABLE is the default.
5176
5177 The FILE and END subcommands are as in DATA LIST FIXED above.
5178
5179 The variables to be parsed are given as a single list of variable names.
5180 This list must be introduced by a single slash (@samp{/}).  The set of
5181 variable names may contain format specifications in parentheses
5182 (@pxref{Input/Output Formats}).  Format specifications apply to all
5183 variables back to the previous parenthesized format specification.  
5184
5185 In addition, an asterisk may be used to indicate that all variables
5186 preceding it are to have input/output format @samp{F8.0}.
5187
5188 Specified field widths are ignored on input, although all normal limits
5189 on field width apply, but they are honored on output.
5190
5191 @node DATA LIST LIST,  , DATA LIST FREE, DATA LIST
5192 @subsection DATA LIST LIST
5193 @vindex DATA LIST LIST
5194
5195 @display
5196 DATA LIST LIST
5197         [@{NOTABLE,TABLE@}]
5198         FILE='filename'
5199         END=end_var
5200         /var_spec@dots{}
5201
5202 where each var_spec takes one of the forms
5203         var_list [(type_spec)]
5204         var_list *
5205 @end display
5206
5207 Syntactically and semantically, DATA LIST LIST is equivalent to DATA
5208 LIST FREE, with one exception: each input line is expected to correspond
5209 to exactly one input record.  If more or fewer fields are found on an
5210 input line than expected, an appropriate diagnostic is issued.
5211
5212 @node END CASE, END FILE, DATA LIST, Data Input and Output
5213 @section END CASE
5214 @vindex END CASE
5215
5216 @display
5217 END CASE.
5218 @end display
5219
5220 END CASE is used within INPUT PROGRAM to output the current case.
5221 @xref{INPUT PROGRAM}.
5222
5223 @node END FILE, FILE HANDLE, END CASE, Data Input and Output
5224 @section END FILE
5225 @vindex END FILE
5226
5227 @display
5228 END FILE.
5229 @end display
5230
5231 END FILE is used within INPUT PROGRAM to terminate the current input
5232 program.  @xref{INPUT PROGRAM}.
5233
5234 @node FILE HANDLE, INPUT PROGRAM, END FILE, Data Input and Output
5235 @section FILE HANDLE
5236 @vindex FILE HANDLE
5237
5238 @display
5239 FILE HANDLE handle_name
5240         /NAME='filename'
5241         /RECFORM=@{VARIABLE,FIXED,SPANNED@}
5242         /LRECL=rec_len
5243         /MODE=@{CHARACTER,IMAGE,BINARY,MULTIPUNCH,360@}
5244 @end display
5245
5246 Use the FILE HANDLE command to define the attributes of a file that does
5247 not use conventional variable-length records terminated by newline
5248 characters.
5249
5250 Specify the file handle name as an identifier.  Any given identifier may
5251 only appear once in a PSPP run.  File handles may not be reassigned to a
5252 different file.  The file handle name must immediately follow the FILE
5253 HANDLE command name.
5254
5255 The NAME subcommand specifies the name of the file associated with the
5256 handle.  It is the only required subcommand.
5257
5258 The RECFORM subcommand specifies how the file is laid out.  VARIABLE
5259 specifies variable-length lines terminated with newlines, and it is the
5260 default.  FIXED specifies fixed-length records.  SPANNED is not
5261 supported.
5262
5263 LRECL specifies the length of fixed-length records.  It is required if
5264 @code{/RECFORM FIXED} is specified.  
5265
5266 MODE specifies a file mode.  CHARACTER, the default, causes the data
5267 file to be opened in ANSI C text mode.  BINARY causes the data file to
5268 be opened in ANSI C binary mode.  The other possibilities are not
5269 supported.
5270
5271 @node INPUT PROGRAM, LIST, FILE HANDLE, Data Input and Output
5272 @section INPUT PROGRAM
5273 @vindex INPUT PROGRAM
5274
5275 @display
5276 INPUT PROGRAM.
5277 @dots{} input commands @dots{}
5278 END INPUT PROGRAM.
5279 @end display
5280
5281 The INPUT PROGRAM@dots{}END INPUT PROGRAM construct is used to specify a
5282 complex input program.  By placing data input commands within INPUT
5283 PROGRAM, PSPP programs can take advantage of more complex file
5284 structures than available by using DATA LIST by itself.
5285
5286 The first sort of extended input program is to simply put multiple DATA
5287 LIST commands within the INPUT PROGRAM.  This will cause all of the data
5288 files to be read in parallel.  Input will stop when end of file is
5289 reached on any of the data files.
5290
5291 Transformations, such as conditional and looping constructs, can also be
5292 included within an INPUT PROGRAM.  These can be used to combine input
5293 from several data files in more complex ways.  However, input will still
5294 stop when end of file is reached on any of the data files.
5295
5296 To prevent INPUT PROGRAM from terminating at the first end of file, use
5297 the END subcommand on DATA LIST.  This subcommand takes a variable name,
5298 which should be a numeric scratch variable (@pxref{Scratch Variables}).
5299 (It need not be a scratch variable but otherwise the results can be
5300 surprising.)  The value of this variable is set to 0 when reading the
5301 data file, or 1 when end of file is encountered.
5302
5303 Some additional commands are useful in conjunction with INPUT PROGRAM.
5304 END CASE is the first one.  Normally each loop through the INPUT PROGRAM
5305 structure produces one case.  But with END CASE you can control exactly
5306 when cases are output.  When END CASE is used, looping from the end of
5307 INPUT PROGRAM to the beginning does not cause a case to be output.
5308
5309 END FILE is the other command.  When the END subcommand is used on DATA
5310 LIST, there is no way for the INPUT PROGRAM construct to stop looping,
5311 so an infinite loop results.  The END FILE command, when executed,
5312 stops the flow of input data and passes out of the INPUT PROGRAM
5313 structure.
5314
5315 All this is very confusing.  A few examples should help to clarify.
5316
5317 @example
5318 INPUT PROGRAM.
5319         DATA LIST NOTABLE FILE='a.data'/X 1-10.
5320         DATA LIST NOTABLE FILE='b.data'/Y 1-10.
5321 END INPUT PROGRAM.
5322 LIST.
5323 @end example
5324
5325 The example above reads variable X from file @file{a.data} and variable
5326 Y from file @file{b.data}.  If one file is shorter than the other then
5327 the extra data in the longer file is ignored.
5328
5329 @example
5330 INPUT PROGRAM.
5331         NUMERIC #A #B.
5332         
5333         DO IF NOT #A.
5334                 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
5335         END IF.
5336         DO IF NOT #B.
5337                 DATA LIST NOTABLE END=#B FILE='b.data'/Y 1-10.
5338         END IF.
5339         DO IF #A AND #B.
5340                 END FILE.
5341         END IF.
5342         END CASE.
5343 END INPUT PROGRAM.
5344 LIST.
5345 @end example
5346
5347 This example reads variable X from @file{a.data} and variable Y from
5348 @file{b.data}.  If one file is shorter than the other then the missing
5349 field is set to the system-missing value alongside the present value for
5350 the remaining length of the longer file.
5351
5352 @example
5353 INPUT PROGRAM.
5354         NUMERIC #A #B.
5355
5356         DO IF #A.
5357                 DATA LIST NOTABLE END=#B FILE='b.data'/X 1-10.
5358                 DO IF #B.
5359                         END FILE.
5360                 ELSE.
5361                         END CASE.
5362                 END IF.
5363         ELSE.
5364                 DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10.
5365                 DO IF NOT #A.
5366                         END CASE.
5367                 END IF.
5368         END IF.
5369 END INPUT PROGRAM.
5370 LIST.
5371 @end example
5372
5373 The above example reads data from file @file{a.data}, then from
5374 @file{b.data}, and concatenates them into a single active file.
5375
5376 @example
5377 INPUT PROGRAM.
5378         NUMERIC #EOF.
5379
5380         LOOP IF NOT #EOF.
5381                 DATA LIST NOTABLE END=#EOF FILE='a.data'/X 1-10.
5382                 DO IF NOT #EOF.
5383                         END CASE.
5384                 END IF.
5385         END LOOP.
5386
5387         COMPUTE #EOF = 0.
5388         LOOP IF NOT #EOF.
5389                 DATA LIST NOTABLE END=#EOF FILE='b.data'/X 1-10.
5390                 DO IF NOT #EOF.
5391                         END CASE.
5392                 END IF.
5393         END LOOP.
5394
5395         END FILE.
5396 END INPUT PROGRAM.
5397 LIST.
5398 @end example
5399
5400 The above example does the same thing as the previous example, in a
5401 different way.
5402
5403 @example
5404 INPUT PROGRAM.
5405         LOOP #I=1 TO 50.
5406                 COMPUTE X=UNIFORM(10).
5407                 END CASE.
5408         END LOOP.
5409         END FILE.
5410 END INPUT PROGRAM.
5411 LIST/FORMAT=NUMBERED.
5412 @end example
5413
5414 The above example causes an active file to be created consisting of 50
5415 random variates between 0 and 10.
5416
5417 @node LIST, MATRIX DATA, INPUT PROGRAM, Data Input and Output
5418 @section LIST
5419 @vindex LIST
5420
5421 @display
5422 LIST
5423         /VARIABLES=var_list
5424         /CASES=FROM start_index TO end_index BY incr_index
5425         /FORMAT=@{UNNUMBERED,NUMBERED@} @{WRAP,SINGLE@} 
5426                 @{NOWEIGHT,WEIGHT@}
5427 @end display
5428
5429 The LIST procedure prints the values of specified variables to the
5430 listing file.
5431
5432 The VARIABLES subcommand specifies the variables whose values are to be
5433 printed.  Keyword VARIABLES is optional.  If VARIABLES subcommand is not
5434 specified then all variables in the active file are printed.
5435
5436 The CASES subcommand can be used to specify a subset of cases to be
5437 printed.  Specify FROM and the case number of the first case to print,
5438 TO and the case number of the last case to print, and BY and the number
5439 of cases to advance between printing cases, or any subset of those
5440 settings.  If CASES is not specified then all cases are printed.
5441
5442 The FORMAT subcommand can be used to change the output format.  NUMBERED
5443 will print case numbers along with each case; UNNUMBERED, the default,
5444 causes the case numbers to be omitted.  The WRAP and SINGLE settings are
5445 currently not used.  WEIGHT will cause case weights to be printed along
5446 with variable values; NOWEIGHT, the default, causes case weights to be
5447 omitted from the output.
5448
5449 Case numbers start from 1.  They are counted after all transformations
5450 have been considered.
5451
5452 LIST will attempt to fit all the values on a single line.  If necessary,
5453 variable names will be display vertically in order to fit.  If values
5454 cannot fit on a single line, then a multi-line format will be used.
5455
5456 LIST is a procedure.  It causes the data to be read.
5457
5458 @node MATRIX DATA, NEW FILE, LIST, Data Input and Output
5459 @section MATRIX DATA
5460 @vindex MATRIX DATA
5461
5462 @display
5463 MATRIX DATA
5464         /VARIABLES=var_list
5465         /FILE='filename'
5466         /FORMAT=@{LIST,FREE@} @{LOWER,UPPER,FULL@} @{DIAGONAL,NODIAGONAL@}
5467         /SPLIT=@{new_var,var_list@}
5468         /FACTORS=var_list
5469         /CELLS=n_cells
5470         /N=n
5471         /CONTENTS=@{N_VECTOR,N_SCALAR,N_MATRIX,MEAN,STDDEV,COUNT,MSE,
5472                    DFE,MAT,COV,CORR,PROX@}
5473 @end display
5474
5475 The MATRIX DATA command reads square matrices in one of several textual
5476 formats.  MATRIX DATA clears the dictionary and replaces it and reads a
5477 data file.
5478
5479 Use VARIABLES to specify the variables that form the rows and columns of
5480 the matrices.  You may not specify a variable named VARNAME_.  You
5481 should specify VARIABLES first.
5482
5483 Specify the file to read on FILE, either as a file name string or a file
5484 handle (@pxref{FILE HANDLE}).  If FILE is not specified then matrix data
5485 must immediately follow MATRIX DATA with a BEGIN DATA@dots{}END DATA
5486 construct (@pxref{BEGIN DATA}).
5487
5488 The FORMAT subcommand specifies how the matrices are formatted.  LIST,
5489 the default, indicates that there is one line per row of matrix data;
5490 FREE allows single matrix rows to be broken across multiple lines.  This
5491 is analogous to the difference between DATA LIST FREE and DATA LIST LIST
5492 (@pxref{DATA LIST}).  LOWER, the default, indicates that the lower
5493 triangle of the matrix is given; UPPER indicates the upper triangle; and
5494 FULL indicates that the entire matrix is given.  DIAGONAL, the default,
5495 indicates that the diagonal is part of the data; NODIAGONAL indicates
5496 that it is omitted.  DIAGONAL/NODIAGONAL have no effect when FULL is
5497 specified.
5498
5499 The SPLIT subcommand is used to specify SPLIT FILE variables for the
5500 input matrices (@pxref{SPLIT FILE}).  Specify either a single variable
5501 not specified on VARIABLES, or one or more variables that are specified
5502 on VARIABLES.  In the former case, the SPLIT values are not present in
5503 the data and ROWTYPE_ may not be specified on VARIABLES.  In the latter
5504 case, the SPLIT values are present in the data.
5505
5506 Specify a list of factor variables on FACTORS.  Factor variables must
5507 also be listed on VARIABLES.  Factor variables are used when there are
5508 some variables where, for each possible combination of their values,
5509 statistics on the matrix variables are included in the data.
5510
5511 If FACTORS is specified and ROWTYPE_ is not specified on VARIABLES, the
5512 CELLS subcommand is required.  Specify the number of factor variable
5513 combinations that are given.  For instance, if factor variable A has 2
5514 values and factor variable B has 3 values, specify 6.
5515
5516 The N subcommand specifies a population number of observations.  When N
5517 is specified, one N record is output for each SPLIT FILE.
5518
5519 Use CONTENTS to specify what sort of information the matrices include.
5520 Each possible option is described in more detail below.  When ROWTYPE_
5521 is specified on VARIABLES, CONTENTS is optional; otherwise, if CONTENTS
5522 is not specified then /CONTENTS=CORR is assumed.
5523
5524 @table @asis
5525 @item N
5526 @item N_VECTOR
5527 Number of observations as a vector, one value for each variable.
5528 @item N_SCALAR
5529 Number of observations as a single value.
5530 @item N_MATRIX
5531 Matrix of counts.
5532 @item MEAN
5533 Vector of means.
5534 @item STDDEV
5535 Vector of standard deviations.
5536 @item COUNT
5537 Vector of counts.
5538 @item MSE
5539 Vector of mean squared errors.
5540 @item DFE
5541 Vector of degrees of freedom.
5542 @item MAT
5543 Generic matrix.
5544 @item COV
5545 Covariance matrix.
5546 @item CORR
5547 Correlation matrix.
5548 @item PROX
5549 Proximities matrix.
5550 @end table
5551
5552 The exact semantics of the matrices read by MATRIX DATA are complex.
5553 Right now MATRIX DATA isn't too useful due to a lack of procedures
5554 accepting or producing related data, so these semantics aren't
5555 documented.  Later, they'll be described here in detail.
5556
5557 @node NEW FILE, PRINT, MATRIX DATA, Data Input and Output
5558 @section NEW FILE
5559 @vindex NEW FILE
5560
5561 @display
5562 NEW FILE.
5563 @end display
5564
5565 The NEW FILE command clears the current active file.
5566
5567 @node PRINT, PRINT EJECT, NEW FILE, Data Input and Output
5568 @section PRINT
5569 @vindex PRINT
5570
5571 @display
5572 PRINT 
5573         OUTFILE='filename'
5574         RECORDS=n_lines
5575         @{NOTABLE,TABLE@}
5576         /[line_no] arg@dots{}
5577
5578 arg takes one of the following forms:
5579         'string' [start-end]
5580         var_list start-end [type_spec]
5581         var_list (fortran_spec)
5582         var_list *
5583 @end display
5584
5585 The PRINT transformation writes variable data to an output file.  PRINT
5586 is executed when a procedure causes the data to be read.  In order to
5587 execute the PRINT transformation without invoking a procedure, use the
5588 EXECUTE command (@pxref{EXECUTE}).
5589
5590 All PRINT subcommands are optional.
5591
5592 The OUTFILE subcommand specifies the file to receive the output.  The
5593 file may be a file name as a string or a file handle (@pxref{FILE
5594 HANDLE}).  If OUTFILE is not present then output will be sent to PSPP's
5595 output listing file.
5596
5597 The RECORDS subcommand specifies the number of lines to be output.  The
5598 number of lines may optionally be surrounded by parentheses.
5599
5600 TABLE will cause the PRINT command to output a table to the listing file
5601 that describes what it will print to the output file.  NOTABLE, the
5602 default, suppresses this output table.
5603
5604 Introduce the strings and variables to be printed with a slash
5605 (@samp{/}).  Optionally, the slash may be followed by a number
5606 indicating which output line will be specified.  In the absence of this
5607 line number, the next line number will be specified.  Multiple lines may
5608 be specified using multiple slashes with the intended output for a line
5609 following its respective slash.
5610
5611 Literal strings may be printed.  Specify the string itself.  Optionally
5612 the string may be followed by a column number or range of column
5613 numbers, specifying the location on the line for the string to be
5614 printed.  Otherwise, the string will be printed at the current position
5615 on the line.
5616
5617 Variables to be printed can be specified in the same ways as available
5618 for DATA LIST FIXED (@pxref{DATA LIST FIXED}).  In addition, a variable
5619 list may be followed by an asterisk (@samp{*}), which indicates that the
5620 variables should be printed in their dictionary print formats, separated
5621 by spaces.  A variable list followed by a slash or the end of command
5622 will be interpreted the same way.
5623
5624 If a FORTRAN type specification is used to move backwards on the current
5625 line, then text is written at that point on the line, the line will be
5626 truncated to that length, although additional text being added will
5627 again extend the line to that length.
5628
5629 @node PRINT EJECT, PRINT SPACE, PRINT, Data Input and Output
5630 @section PRINT EJECT
5631 @vindex PRINT EJECT
5632
5633 @display
5634 PRINT EJECT 
5635         OUTFILE='filename'
5636         RECORDS=n_lines
5637         @{NOTABLE,TABLE@}
5638         /[line_no] arg@dots{}
5639
5640 arg takes one of the following forms:
5641         'string' [start-end]
5642         var_list start-end [type_spec]
5643         var_list (fortran_spec)
5644         var_list *
5645 @end display
5646
5647 PRINT EJECT is used to write data to an output file.  Before the data is
5648 written, the current page in the listing file is ejected.
5649
5650 @xref{PRINT}, for more information on syntax and usage.
5651
5652 @node PRINT SPACE, REREAD, PRINT EJECT, Data Input and Output
5653 @section PRINT SPACE
5654 @vindex PRINT SPACE
5655
5656 @display
5657 PRINT SPACE OUTFILE='filename' n_lines.
5658 @end display
5659
5660 The PRINT SPACE prints one or more blank lines to an output file.
5661
5662 The OUTFILE subcommand is optional.  It may be used to direct output to
5663 a file specified by file name as a string or file handle (@pxref{FILE
5664 HANDLE}).  If OUTFILE is not specified then output will be directed to
5665 the listing file.
5666
5667 n_lines is also optional.  If present, it is an expression
5668 (@pxref{Expressions}) specifying the number of blank lines to be
5669 printed.  The expression must evaluate to a nonnegative value.
5670
5671 @node REREAD, REPEATING DATA, PRINT SPACE, Data Input and Output
5672 @section REREAD
5673 @vindex REREAD
5674
5675 @display
5676 REREAD FILE=handle COLUMN=column.
5677 @end display
5678
5679 The REREAD transformation allows the previous input line in a data file
5680 already processed by DATA LIST or another input command to be re-read
5681 for further processing.
5682
5683 The FILE subcommand, which is optional, is used to specify the file to
5684 have its line re-read.  The file must be specified in the form of a file
5685 handle (@pxref{FILE HANDLE}).  If FILE is not specified then the last
5686 file specified on DATA LIST will be assumed (last file specified
5687 lexically, not in terms of flow-of-control).
5688
5689 By default, the line re-read is re-read in its entirety.  With the
5690 COLUMN subcommand, a prefix of the line can be exempted from
5691 re-reading.  Specify an expression (@pxref{Expressions}) evaluating to
5692 the first column that should be included in the re-read line.  Columns
5693 are numbered from 1 at the left margin.
5694
5695 Multiple REREAD commands will not back up in the data file.  Instead,
5696 they will re-read the same line multiple times.
5697
5698 @node REPEATING DATA, WRITE, REREAD, Data Input and Output
5699 @section REPEATING DATA
5700 @vindex REPEATING DATA
5701
5702 @display
5703 REPEATING DATA
5704         /STARTS=start-end
5705         /OCCURS=n_occurs
5706         /FILE='filename'
5707         /LENGTH=length
5708         /CONTINUED[=cont_start-cont_end]
5709         /ID=id_start-id_end=id_var
5710         /@{TABLE,NOTABLE@}
5711         /DATA=var_spec@dots{}
5712
5713 where each var_spec takes one of the forms
5714         var_list start-end [type_spec]
5715         var_list (fortran_spec)
5716 @end display
5717
5718 The REPEATING DATA command is used to parse groups of data repeating in
5719 a uniform format, possibly with several groups on a single line.  Each
5720 group of data corresponds with one case.  REPEATING DATA may only be
5721 used within an INPUT PROGRAM structure.  When used with DATA LIST, it
5722 can be used to parse groups of cases that share a subset of variables
5723 but differ in their other data.
5724
5725 The STARTS subcommand is required.  Specify a range of columns, using
5726 literal numbers or numeric variable names.  This range specifies the
5727 columns on the first line that are used to contain groups of data.  The
5728 ending column is optional.  If it is not specified, then the record
5729 width of the input file is used.  For the inline file (@pxref{BEGIN
5730 DATA}) this is 80 columns; for a file with fixed record widths it is the
5731 record width; for other files it is 1024 characters by default.
5732
5733 The OCCURS subcommand is required.  It must be a number or the name of a
5734 numeric variable.  Its value is the number of groups present in the
5735 current record.
5736
5737 The DATA subcommand is required.  It must be the last subcommand
5738 specified.  It is used to specify the data present within each repeating
5739 group.  Column numbers are specified relative to the beginning of a
5740 group at column 1.  Data is specified in the same way as with DATA LIST
5741 FIXED (@pxref{DATA LIST FIXED}).
5742
5743 All other subcommands are optional.
5744
5745 FILE specifies the file to read, either a file name as a string or a
5746 file handle (@pxref{FILE HANDLE}).  If FILE is not present then the
5747 default is the last file handle used on DATA LIST (lexically, not in
5748 terms of flow of control).
5749
5750 By default REPEATING DATA will output a table describing how it will
5751 parse the input data.  Specifying NOTABLE will disable this behavior;
5752 specifying TABLE will explicitly enable it.
5753
5754 The LENGTH subcommand specifies the length in characters of each group.
5755 If it is not present then length is inferred from the DATA subcommand.
5756 LENGTH can be a number or a variable name.
5757
5758 Normally all the data groups are expected to be present on a single
5759 line.  Use the CONTINUED command to indicate that data can be continued
5760 onto additional lines.  If data on continuation lines starts at the left
5761 margin and continues through the entire field width, no column
5762 specifications are necessary on CONTINUED.  Otherwise, specify the
5763 possible range of columns in the same way as on STARTS.
5764
5765 When data groups are continued from line to line, it's easily possible
5766 for cases to get out of sync if hand editing is not done carefully.  The
5767 ID subcommand allows a case identifier to be present on each line of
5768 repeating data groups.  REPEATING DATA will check for the same
5769 identifier on each line and report mismatches.  Specify the range of
5770 columns that the identifier will occupy, followed by an equals sign
5771 (@samp{=}) and the identifier variable name.  The variable must already
5772 have been declared with NUMERIC or another command.
5773
5774 @node WRITE,  , REPEATING DATA, Data Input and Output
5775 @section WRITE
5776 @vindex WRITE
5777
5778 @display
5779 WRITE 
5780         OUTFILE='filename'
5781         RECORDS=n_lines
5782         @{NOTABLE,TABLE@}
5783         /[line_no] arg@dots{}
5784
5785 arg takes one of the following forms:
5786         'string' [start-end]
5787         var_list start-end [type_spec]
5788         var_list (fortran_spec)
5789         var_list *
5790 @end display
5791
5792 WRITE is used to write text or binary data to an output file.  
5793
5794 @xref{PRINT}, for more information on syntax and usage.  The main
5795 difference between PRINT and WRITE is that whereas by default PRINT uses
5796 variables' print formats, WRITE uses write formats.
5797
5798 The sole additional difference is that if WRITE is used to send output
5799 to a binary file, carriage control characters will not be output.
5800 @xref{FILE HANDLE}, for information on how to declare a file as binary.
5801
5802 @node System and Portable Files, Variable Attributes, Data Input and Output, Top
5803 @chapter System Files and Portable Files
5804
5805 The commands in this chapter read, write, and examine system files and
5806 portable files.
5807
5808 @menu
5809 * APPLY DICTIONARY::            Apply system file dictionary to active file.
5810 * EXPORT::                      Write to a portable file.
5811 * GET::                         Read from a system file.
5812 * IMPORT::                      Read from a portable file.
5813 * MATCH FILES::                 Merge system files.
5814 * SAVE::                        Write to a system file.
5815 * SYSFILE INFO::                Display system file dictionary.
5816 * XSAVE::                       Write to a system file, as a transform.
5817 @end menu
5818
5819 @node APPLY DICTIONARY, EXPORT, System and Portable Files, System and Portable Files
5820 @section APPLY DICTIONARY
5821 @vindex APPLY DICTIONARY
5822
5823 @display
5824 APPLY DICTIONARY FROM='filename'.
5825 @end display
5826
5827 The APPLY DICTIONARY command applies the variable labels, value labels,
5828 and missing values from variables in a system file to corresponding
5829 variables in the active file.  In some cases it also updates the
5830 weighting variable.
5831
5832 Specify a system file with a file name string or as a file handle
5833 (@pxref{FILE HANDLE}).  The dictionary in the system file will be read,
5834 but it will not replace the active file dictionary.  The system file's
5835 data will not be read.
5836
5837 Only variables with names that exist in both the active file and the
5838 system file are considered.  Variables with the same name but different
5839 types (numeric, string) will cause an error message.  Otherwise, the
5840 system file variables' attributes will replace those in their matching
5841 active file variables, as described below.
5842
5843 If a system file variable has a variable label, then it will replace the
5844 active file variable's variable label.  If the system file variable does
5845 not have a variable label, then the active file variable's variable
5846 label, if any, will be retained.
5847
5848 If the active file variable is numeric or short string, then value
5849 labels and missing values, if any, will be copied to the active file
5850 variable.  If the system file variable does not have value labels or
5851 missing values, then those in the active file variable, if any, will not
5852 be disturbed.
5853
5854 Finally, weighting of the active file is updated (@pxref{WEIGHT}).  If
5855 the active file has a weighting variable, and the system file does not,
5856 or if the weighting variable in the system file does not exist in the
5857 active file, then the active file weighting variable, if any, is
5858 retained.  Otherwise, the weighting variable in the system file becomes
5859 the active file weighting variable.
5860
5861 APPLY DICTIONARY takes effect immediately.  It does not read the active
5862 file.  The system file is not modified.
5863
5864 @node EXPORT, GET, APPLY DICTIONARY, System and Portable Files
5865 @section EXPORT
5866 @vindex EXPORT
5867
5868 @display
5869 EXPORT
5870         /OUTFILE='filename'
5871         /DROP=var_list
5872         /KEEP=var_list
5873         /RENAME=(src_names=target_names)@dots{}
5874 @end display
5875
5876 The EXPORT procedure writes the active file dictionary and data to a
5877 specified portable file.
5878
5879 The OUTFILE subcommand, which is the only required subcommand, specifies
5880 the portable file to be written as a file name string or a file handle
5881 (@pxref{FILE HANDLE}).
5882
5883 DROP, KEEP, and RENAME follow the same format as the SAVE procedure
5884 (@pxref{SAVE}).
5885
5886 EXPORT is a procedure.  It causes the active file to be read.
5887
5888 @node GET, IMPORT, EXPORT, System and Portable Files
5889 @section GET
5890 @vindex GET
5891
5892 @display
5893 GET
5894         /FILE='filename'
5895         /DROP=var_list
5896         /KEEP=var_list
5897         /RENAME=(src_names=target_names)@dots{}
5898 @end display
5899
5900 The GET transformation clears the current dictionary and active file and
5901 replaces them with the dictionary and data from a specified system file.
5902
5903 The FILE subcommand is the only required subcommand.  Specify the system
5904 file to be read as a string file name or a file handle (@pxref{FILE
5905 HANDLE}).
5906
5907 By default, all the variables in a system file are read.  The DROP
5908 subcommand can be used to specify a list of variables that are not to be
5909 read.  By contrast, the KEEP subcommand can be used to specify variable
5910 that are to be read, with all other variables not read.
5911
5912 Normally variables in a system file retain the names that they were
5913 saved under.  Use the RENAME subcommand to change these names.  Specify,
5914 within parentheses, a list of variable names followed by an equals sign
5915 (@samp{=}) and the names that they should be renamed to.  Multiple
5916 parenthesized groups of variable names can be included on a single
5917 RENAME subcommand.  Variables' names may be swapped using a RENAME
5918 subcommand of the form @samp{/RENAME=(A B=B A)}.
5919
5920 Alternate syntax for the RENAME subcommand allows the parentheses to be
5921 eliminated.  When this is done, only a single variable may be renamed at
5922 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
5923 deprecated.
5924
5925 DROP, KEEP, and RENAME are performed in left-to-right order.  They each
5926 may be present any number of times.
5927
5928 Please note that DROP, KEEP, and RENAME do not cause the system file on
5929 disk to be modified.  Only the active file read from the system file is
5930 changed.
5931
5932 GET does not cause the data to be read, only the dictionary.  The data
5933 is read later, when a procedure is executed.
5934
5935 @node IMPORT, MATCH FILES, GET, System and Portable Files
5936 @section IMPORT
5937 @vindex IMPORT
5938
5939 @display
5940 IMPORT
5941         /FILE='filename'
5942         /TYPE=@{COMM,TAPE@}
5943         /DROP=var_list
5944         /KEEP=var_list
5945         /RENAME=(src_names=target_names)@dots{}
5946 @end display
5947
5948 The IMPORT transformation clears the active file dictionary and data and
5949 replaces them with a dictionary and data from a portable file on disk.
5950
5951 The FILE subcommand, which is the only required subcommand, specifies
5952 the portable file to be read as a file name string or a file handle
5953 (@pxref{FILE HANDLE}).
5954
5955 The TYPE subcommand is currently not used.
5956
5957 DROP, KEEP, and RENAME follow the syntax used by GET (@pxref{GET}).
5958
5959 IMPORT does not cause the data to be read, only the dictionary.  The
5960 data is read later, when a procedure is executed.
5961
5962 @node MATCH FILES, SAVE, IMPORT, System and Portable Files
5963 @section MATCH FILES
5964 @vindex MATCH FILES
5965
5966 @display
5967 MATCH FILES
5968         /BY var_list
5969         /@{FILE,TABLE@}=@{*,'filename'@}
5970         /DROP=var_list
5971         /KEEP=var_list
5972         /RENAME=(src_names=target_names)@dots{}
5973         /IN=var_name
5974         /FIRST=var_name
5975         /LAST=var_name
5976         /MAP
5977 @end display
5978
5979 The MATCH FILES command merges one or more system files, optionally
5980 including the active file.  Records with the same values for BY
5981 variables are combined into a single record.  Records with different
5982 values are output in order.  Thus, multiple sorted system files are
5983 combined into a single sorted system file based on the value of the BY
5984 variables.
5985
5986 The BY subcommand specifies a list of variables that are used to match
5987 records from each of the system files.  Variables specified must exist
5988 in all the files specified on FILE and TABLE.  BY should usually be
5989 specified.  If TABLE is used then BY is required.
5990
5991 Specify FILE with a system file as a file name string or file handle
5992 (@pxref{FILE HANDLE}).  An asterisk (@samp{*}) may also be specified to
5993 indicate the current active file.  The files specified on FILE are
5994 merged together based on the BY variables, or combined case-by-case if
5995 BY is not specified.  Normally at least two FILE subcommands should be
5996 specified.
5997
5998 Specify TABLE with a system file in order to use it as a @dfn{table
5999 lookup file}.  Records in table lookup files are not used up after
6000 they've been used once.  This means that data in table lookup files can
6001 correspond to any number of records in FILE files.  Table lookup files
6002 correspond to lookup tables in traditional relational database systems.
6003 It is incorrect to have records with duplicate BY values in table lookup
6004 files.
6005
6006 Any number of FILE and TABLE subcommands may be specified.  Each
6007 instance of FILE or TABLE can be followed by DROP, KEEP, and/or RENAME
6008 subcommands.  These take the same form as the corresponding subcommands
6009 of GET (@pxref{GET}), and perform the same functions.
6010
6011 Variables belonging to files that are not present for the current case
6012 are set to the system-missing value for numeric variables or spaces for
6013 string variables.
6014
6015 IN, FIRST, LAST, and MAP are currently not used.
6016
6017 @node SAVE, SYSFILE INFO, MATCH FILES, System and Portable Files
6018 @section SAVE
6019 @vindex SAVE
6020
6021 @display
6022 SAVE
6023         /OUTFILE='filename'
6024         /@{COMPRESSED,UNCOMPRESSED@}
6025         /DROP=var_list
6026         /KEEP=var_list
6027         /RENAME=(src_names=target_names)@dots{}
6028 @end display
6029
6030 The SAVE procedure causes the dictionary and data in the active file to
6031 be written to a system file.
6032
6033 The FILE subcommand is the only required subcommand.  Specify the system
6034 file to be written as a string file name or a file handle (@pxref{FILE
6035 HANDLE}).
6036
6037 The COMPRESS and UNCOMPRESS subcommand determine whether the saved
6038 system file is compressed.  By default, system files are compressed.
6039 This default can be changed with the SET command (@pxref{SET}).
6040
6041 By default, all the variables in the active file dictionary are written
6042 to the system file.  The DROP subcommand can be used to specify a list
6043 of variables not to be written.  In contrast, KEEP specifies variables
6044 to be written, with all variables not specified not written.
6045
6046 Normally variables are saved to a system file under the same names they
6047 have in the active file.  Use the RENAME command to change these names.
6048 Specify, within parentheses, a list of variable names followed by an
6049 equals sign (@samp{=}) and the names that they should be renamed to.
6050 Multiple parenthesized groups of variable names can be included on a
6051 single RENAME subcommand.  Variables' names may be swapped using a
6052 RENAME subcommand of the form @samp{/RENAME=(A B=B A)}.
6053
6054 Alternate syntax for the RENAME subcommand allows the parentheses to be
6055 eliminated.  When this is done, only a single variable may be renamed at
6056 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
6057 deprecated.
6058
6059 DROP, KEEP, and RENAME are performed in left-to-right order.  They each
6060 may be present any number of times.
6061
6062 Please note that DROP, KEEP, and RENAME do not cause the active file to
6063 be modified.  Only the system file written to disk is changed.
6064
6065 SAVE causes the data to be read.  It is a procedure.
6066
6067 @node SYSFILE INFO, XSAVE, SAVE, System and Portable Files
6068 @section SYSFILE INFO
6069 @vindex SYSFILE INFO
6070
6071 @display 
6072 SYSFILE INFO FILE='filename'.
6073 @end display
6074
6075 The SYSFILE INFO command reads the dictionary in a system file and
6076 displays the information in its dictionary.
6077
6078 Specify a file name or file handle.  SYSFILE INFO will read that file as
6079 a system file and display information on its dictionary.
6080
6081 The file does not replace the current active file.
6082
6083 @node XSAVE,  , SYSFILE INFO, System and Portable Files
6084 @section XSAVE
6085 @vindex XSAVE
6086
6087 @display
6088 XSAVE
6089         /FILE='filename'
6090         /@{COMPRESSED,UNCOMPRESSED@}
6091         /DROP=var_list
6092         /KEEP=var_list
6093         /RENAME=(src_names=target_names)@dots{}
6094 @end display
6095
6096 The XSAVE transformation writes the active file dictionary and data to a
6097 system file stored on disk.
6098
6099 XSAVE is a transformation, not a procedure.  It is executed when the
6100 data is read by a procedure or procedure-like command.  In all other
6101 respects, XSAVE is identical to SAVE.  @xref{SAVE}, for more information
6102 on syntax and usage.
6103
6104 @node Variable Attributes, Data Manipulation, System and Portable Files, Top
6105 @chapter Manipulating variables
6106
6107 The variables in the active file dictionary are important.  There are
6108 several utility functions for examining and adjusting them.
6109
6110 @menu
6111 * ADD VALUE LABELS::            Add value labels to variables.
6112 * DISPLAY::                     Display variable names & descriptions.
6113 * DISPLAY VECTORS::             Display a list of vectors.
6114 * FORMATS::                     Set print and write formats.
6115 * LEAVE::                       Don't clear variables between cases.
6116 * MISSING VALUES::              Set missing values for variables.
6117 * MODIFY VARS::                 Rename, reorder, and drop variables.
6118 * NUMERIC::                     Create new numeric variables.
6119 * PRINT FORMATS::               Set variable print formats.
6120 * RENAME VARIABLES::            Rename variables.
6121 * VALUE LABELS::                Set value labels for variables.
6122 * STRING::                      Create new string variables.
6123 * VARIABLE LABELS::             Set variable labels for variables.
6124 * VECTOR::                      Declare an array of variables.
6125 * WRITE FORMATS::               Set variable write formats.
6126 @end menu
6127
6128 @node ADD VALUE LABELS, DISPLAY, Variable Attributes, Variable Attributes
6129 @section ADD VALUE LABELS
6130 @vindex ADD VALUE LABELS
6131
6132 @display 
6133 ADD VALUE LABELS
6134         /var_list value 'label' [value 'label']@dots{}
6135 @end display
6136
6137 ADD VALUE LABELS has the same syntax and purpose as VALUE LABELS (see
6138 above), but it does not clear away value labels from the variables
6139 before adding the ones specified.
6140
6141 @node DISPLAY, DISPLAY VECTORS, ADD VALUE LABELS, Variable Attributes
6142 @section DISPLAY
6143 @vindex DISPLAY
6144
6145 @display
6146 DISPLAY @{NAMES,INDEX,LABELS,VARIABLES,DICTIONARY,SCRATCH@}
6147         [SORTED] [var_list]
6148 @end display
6149
6150 DISPLAY displays requested information on variables.  Variables can
6151 optionally be sorted alphabetically.  The entire dictionary or just
6152 specified variables can be described.
6153
6154 One of the following keywords can be present:
6155
6156 @table @asis
6157 @item NAMES
6158 The variables' names are displayed.
6159
6160 @item INDEX
6161 The variables' names are displayed along with a value describing their
6162 position within the active file dictionary.
6163
6164 @item LABELS
6165 Variable names, positions, and variable labels are displayed.
6166
6167 @item VARIABLES
6168 Variable names, positions, print and write formats, and missing values
6169 are displayed.
6170
6171 @item DICTIONARY
6172 Variable names, positions, print and write formats, missing values,
6173 variable labels, and value labels are displayed.
6174
6175 @item SCRATCH
6176 Varible names are displayed, for scratch variables only (@pxref{Scratch
6177 Variables}).
6178 @end table
6179
6180 If SORTED is specified, then the variables are displayed in ascending
6181 order based on their names; otherwise, they are displayed in the order
6182 that they occur in the active file dictionary.
6183
6184 @node DISPLAY VECTORS, FORMATS, DISPLAY, Variable Attributes
6185 @section DISPLAY VECTORS
6186 @vindex DISPLAY VECTORS
6187
6188 @display
6189 DISPLAY VECTORS.
6190 @end display
6191
6192 The DISPLAY VECTORS command causes a list of the currently declared
6193 vectors to be displayed.
6194
6195 @node FORMATS, LEAVE, DISPLAY VECTORS, Variable Attributes
6196 @section FORMATS
6197 @vindex FORMATS
6198
6199 @display
6200 FORMATS var_list (fmt_spec).
6201 @end display
6202
6203 The FORMATS command set the print and write formats for the specified
6204 variables to the specified format specification.  @xref{Input/Output
6205 Formats}.
6206
6207 Specify a list of variables followed by a format specification in
6208 parentheses.  The print and write formats of the specified variables
6209 will be changed.
6210
6211 Additional lists of variables and formats may be included if they are
6212 delimited by a slash (@samp{/}).
6213
6214 The FORMATS command takes effect immediately.  It is not affected by
6215 conditional and looping structures such as DO IF or LOOP.
6216
6217 @node LEAVE, MISSING VALUES, FORMATS, Variable Attributes
6218 @section LEAVE
6219 @vindex LEAVE
6220
6221 @display
6222 LEAVE var_list.
6223 @end display
6224
6225 The LEAVE command prevents the specified variables from being
6226 reinitialized whenever a new case is processed.
6227
6228 Normally, when a data file is processed, every variable in the active
6229 file is initialized to the system-missing value or spaces at the
6230 beginning of processing for each case.  When a variable has been
6231 specified on LEAVE, this is not the case.  Instead, that variable is
6232 initialized to 0 (not system-missing) or spaces for the first case.
6233 After that, it retains its value between cases.
6234
6235 This becomes useful for counters.  For instance, in the example below
6236 the variable SUM maintains a running total of the values in the ITEM
6237 variable.
6238
6239 @example
6240 DATA LIST /ITEM 1-3.
6241 COMPUTE SUM=SUM+ITEM.
6242 PRINT /ITEM SUM.
6243 LEAVE SUM
6244 BEGIN DATA.
6245 123
6246 404
6247 555
6248 999
6249 END DATA.
6250 @end example
6251
6252 @noindent Partial output from this example:
6253
6254 @example
6255 123   123.00
6256 404   527.00
6257 555  1082.00
6258 999  2081.00
6259 @end example
6260
6261 It is best to use the LEAVE command immediately before invoking a
6262 procedure command, because it is reset by certain transformations---for
6263 instance, COMPUTE and IF.  LEAVE is also reset by all procedure
6264 invocations.
6265
6266 @node MISSING VALUES, MODIFY VARS, LEAVE, Variable Attributes
6267 @section MISSING VALUES
6268 @vindex MISSING VALUES
6269
6270 @display
6271 MISSING VALUES var_list (missing_values).
6272
6273 missing_values takes one of the following forms:
6274         num1
6275         num1, num2
6276         num1, num2, num3
6277         num1 THRU num2
6278         num1 THRU num2, num3
6279         string1
6280         string1, string2
6281         string1, string2, string3
6282 As part of a range, LO or LOWEST may take the place of num1;
6283 HI or HIGHEST may take the place of num2.
6284 @end display
6285
6286 The MISSING VALUES command sets user-missing values for numeric and
6287 short string variables.  Long string variables may not have missing
6288 values.
6289
6290 Specify a list of variables, followed by a list of their user-missing
6291 values in parentheses.  Up to three discrete values may be given, or,
6292 for numeric variables only, a range of values optionally accompanied by
6293 a single discrete value.  Ranges may be open-ended on one end, indicated
6294 through the use of the keyword LO or LOWEST or HI or HIGHEST.
6295
6296 The MISSING VALUES command takes effect immediately.  It is not affected
6297 by conditional and looping constructs such as DO IF or LOOP.
6298
6299 @node MODIFY VARS, NUMERIC, MISSING VALUES, Variable Attributes
6300 @section MODIFY VARS
6301 @vindex MODIFY VARS
6302
6303 @display 
6304 MODIFY VARS
6305         /REORDER=@{FORWARD,BACKWARD@} @{POSITIONAL,ALPHA@} (var_list)@dots{}
6306         /RENAME=(old_names=new_names)@dots{}
6307         /@{DROP,KEEP@}=var_list
6308         /MAP    
6309 @end display
6310
6311 The MODIFY VARS commands allows variables in the active file to be
6312 reordered, renamed, or deleted from the active file.
6313
6314 At least one subcommand must be specified, and no subcommand may be
6315 specified more than once.  DROP and KEEP may not both be specified.
6316
6317 The REORDER subcommand changes the order of variables in the active
6318 file.  Specify one or more lists of variable names in parentheses.  By
6319 default, each list of variables is rearranged into the specified order.
6320 To put the variables into the reverse of the specified order, put
6321 keyword BACKWARD before the parentheses.  To put them into alphabetical
6322 order in the dictionary, specify keyword ALPHA before the parentheses.
6323 BACKWARD and ALPHA may also be combined.
6324
6325 To rename variables in the active file, specify RENAME, an equals sign
6326 (@samp{=}), and lists of the old variable names and new variable names
6327 separated by another equals sign within parentheses.  There must be the
6328 same number of old and new variable names.  Each old variable is renamed to
6329 the corresponding new variable name.  Multiple parenthesized groups of
6330 variables may be specified.
6331
6332 The DROP subcommand deletes a specified list of variables from the
6333 active file.
6334
6335 The KEEP subcommand keeps the specified list of variables in the active
6336 file.  Any unlisted variables are delete from the active file.
6337
6338 MAP is currently ignored.
6339
6340 MODIFY VARS takes effect immediately.  It does not cause the data to be
6341 read.
6342
6343 @node NUMERIC, PRINT FORMATS, MODIFY VARS, Variable Attributes
6344 @section NUMERIC
6345 @vindex NUMERIC
6346
6347 @display
6348 NUMERIC /var_list [(fmt_spec)].
6349 @end display
6350
6351 The NUMERIC command explicitly declares new numeric variables,
6352 optionally setting their output formats.
6353
6354 Specify a slash (@samp{/}), followed by the names of the new numeric
6355 variables.  If you wish to set their output formats, follow their names
6356 by an output format specification in parentheses (@pxref{Input/Output
6357 Formats}).  If no output format specification is given then the
6358 variables will default to F8.2.
6359
6360 Variables created with NUMERIC will be initialized to the system-missing
6361 value.
6362
6363 @node PRINT FORMATS, RENAME VARIABLES, NUMERIC, Variable Attributes
6364 @section PRINT FORMATS
6365 @vindex PRINT FORMATS
6366
6367 @display
6368 PRINT FORMATS var_list (fmt_spec).
6369 @end display
6370
6371 The PRINT FORMATS command sets the print formats for the specified
6372 variables to the specified format specification.
6373
6374 Syntax is identical to that of FORMATS (@pxref{FORMATS}), but the PRINT
6375 FORMATS command sets only print formats, not write formats.
6376
6377 @node RENAME VARIABLES, VALUE LABELS, PRINT FORMATS, Variable Attributes
6378 @section RENAME VARIABLES
6379 @vindex RENAME VARIABLES
6380
6381 @display
6382 RENAME VARIABLES (old_names=new_names)@dots{} .
6383 @end display
6384
6385 The RENAME VARIABLES command allows the names of variables in the active
6386 file to be changed.
6387
6388 To rename variables, specify lists of the old variable names and new
6389 variable names, separated by an equals sign (@samp{=}), within
6390 parentheses.  There must be the same number of old and new variable
6391 names.  Each old variable is renamed to the corresponding new variable
6392 name.  Multiple parenthesized groups of variables may be specified.
6393
6394 RENAME VARIABLES takes effect immediately.  It does not cause the data
6395 to be read.
6396
6397 @node VALUE LABELS, STRING, RENAME VARIABLES, Variable Attributes
6398 @section VALUE LABELS
6399 @vindex VALUE LABELS
6400
6401 @display 
6402 VALUE LABELS
6403         /var_list value 'label' [value 'label']@dots{}
6404 @end display
6405
6406 The VALUE LABELS command allows values of numeric and short string
6407 variables to be associated with labels.  In this way, a short value can
6408 stand for a long value.
6409
6410 In order to set up value labels for a set of variables, specify the
6411 variable names after a slash (@samp{/}), followed by a list of values
6412 and their associated labels, separated by spaces.
6413
6414 Before the VALUE LABELS command is executed, any existing value labels
6415 are cleared from the variables specified.
6416
6417 @node STRING, VARIABLE LABELS, VALUE LABELS, Variable Attributes
6418 @section STRING
6419 @vindex STRING
6420
6421 @display
6422 STRING /var_list (fmt_spec).
6423 @end display
6424
6425 The STRING command creates new string variables for use in
6426 transformations.
6427
6428 Specify a slash (@samp{/}), followed by the names of the string
6429 variables to create and the desired output format specification in
6430 parentheses (@pxref{Input/Output Formats}).  Variable widths are
6431 implicitly derived from the specified output formats.
6432
6433 Created variables are initialized to spaces.
6434
6435 @node VARIABLE LABELS, VECTOR, STRING, Variable Attributes
6436 @section VARIABLE LABELS
6437 @vindex VARIABLE LABELS
6438
6439 @display
6440 VARIABLE LABELS
6441         /var_list 'var_label'.
6442 @end display
6443
6444 The VARIABLE LABELS command is used to associate an explanatory name
6445 with a group of variables.  This name (a variable label) is displayed by
6446 statistical procedures.
6447
6448 To assign a variable label to a group of variables, specify a slash
6449 (@samp{/}), followed by the list of variable names and the variable
6450 label as a string.
6451
6452 @node VECTOR, WRITE FORMATS, VARIABLE LABELS, Variable Attributes
6453 @section VECTOR
6454 @vindex VECTOR
6455
6456 @display
6457 Two possible syntaxes:
6458         VECTOR vec_name=var_list.
6459         VECTOR vec_name_list(count).
6460 @end display
6461
6462 The VECTOR command allows a group of variables to be accessed as if they
6463 were consecutive members of an array with a vector(index) notation.
6464
6465 To make a vector out of a set of existing variables, specify a name for
6466 the vector followed by an equals sign (@samp{=}) and the variables that
6467 belong in the vector.
6468
6469 To make a vector and create variables at the same time, specify one or
6470 more vector names followed by a count in parentheses.  This will cause
6471 variables named @code{@var{vec}1} through @code{@var{vec}@var{count}} to
6472 be created as numeric variables.  Variable names including numeric
6473 suffixes may not exceed 8 characters in length, and none of the
6474 variables may exist prior to the VECTOR command.
6475
6476 All the variables in a vector must be the same type.
6477
6478 Vectors created with VECTOR disappear after any procedure or
6479 procedure-like command is executed.  The variables contained in the
6480 vectors remain, unless they are scratch variables (@pxref{Scratch
6481 Variables}).
6482
6483 Variables within a vector may be references in expressions using
6484 vector(index) syntax.
6485
6486 @node WRITE FORMATS,  , VECTOR, Variable Attributes
6487 @section WRITE FORMATS
6488 @vindex WRITE FORMATS
6489
6490 @display
6491 WRITE FORMATS var_list (fmt_spec).
6492 @end display
6493
6494 The WRITE FORMATS command sets the write formats for the specified
6495 variables to the specified format specification.
6496
6497 Syntax is identical to that of FORMATS (@pxref{FORMATS}), but the WRITE
6498 FORMATS command sets only write formats, not print formats.
6499
6500 @node Data Manipulation, Data Selection, Variable Attributes, Top
6501 @chapter Data transformations
6502
6503 The PSPP procedures examined in this chapter manipulate data and
6504 prepare the active file for later analyses.  They do not produce output,
6505 as a rule.
6506
6507 @menu
6508 * AGGREGATE::                   Summarize multiple cases into a single case.
6509 * AUTORECODE::                  Automatic recoding of variables.
6510 * COMPUTE::                     Assigning a variable a calculated value.
6511 * COUNT::                       Counting variables with particular values.
6512 * FLIP::                        Exchange variables with cases.
6513 * IF::                          Conditionally assigning a calculated value.
6514 * RECODE::                      Mapping values from one set to another.
6515 * SORT CASES::                  Sort the active file.
6516 @end menu
6517
6518 @node AGGREGATE, AUTORECODE, Data Manipulation, Data Manipulation
6519 @section AGGREGATE
6520 @vindex AGGREGATE
6521
6522 @display
6523 AGGREGATE
6524         /BREAK=var_list
6525         /PRESORTED
6526         /OUTFILE=@{*,'filename'@}
6527         /DOCUMENT
6528         /MISSING=COLUMNWISE
6529         /dest_vars=agr_func(src_vars, args@dots{})@dots{}
6530 @end display
6531
6532 The AGGREGATE command summarizes groups of cases into single cases.
6533 Cases are divided into groups that have the same values for one or more
6534 variables called @dfn{break variables}.  Several functions are available
6535 for summarizing case contents.
6536
6537 BREAK is the only required subcommand (in addition, at least one
6538 aggregation variable must be specified).  Specify a list of variable
6539 names.  The values of these variables are used to divide the active file
6540 into groups to be summarized.
6541
6542 By default, the active file is sorted based on the break variables
6543 before aggregation takes place.  If the active file is already sorted,
6544 specify PRESORTED to save time.
6545
6546 The OUTFILE subcommand specifies a system file by file name string or
6547 file handle (@pxref{FILE HANDLE}).  The aggregated cases are sent to
6548 this file.  If OUTFILE is not specified, or if @samp{*} is specified,
6549 then the aggregated cases replace the active file.
6550
6551 Normally the aggregate file does not receive the documents from the
6552 active file, even if the aggregate file replaces the active file.
6553 Specify DOCUMENT to have the documents from the active file copied to
6554 the aggregate file.
6555
6556 At least one aggregation variable must be specified.  Specify a list of
6557 aggregation variables, an equals sign (@samp{=}), an aggregation
6558 function name (see the list below), and a list of source variables in
6559 parentheses.  In addition, some aggregation functions expect additional
6560 arguments in the parentheses following the source variable names.
6561
6562 There must be exactly as many source variables as aggregation variables.
6563 Each aggregation variable receives the results of applying the specified
6564 aggregation function to the corresponding source variable.  Most
6565 aggregation functions may be applied to numeric and short and long
6566 string variables.  Others are restricted to numeric values; these are
6567 marked as such in this list below.
6568
6569 Any number of sets of aggregation variables may be specified.
6570
6571 The available aggregation functions are as follows:
6572
6573 @table @asis
6574 @item SUM(var_name)
6575 Sum.  Limited to numeric values.
6576 @item MEAN(var_name)
6577 Arithmetic mean.  Limited to numeric values.
6578 @item SD(var_name)
6579 Standard deviation of the mean.  Limited to numeric values.
6580 @item MAX(var_name)
6581 Maximum value.
6582 @item MIN(var_name)
6583 Minimum value.
6584 @item FGT(var_name, value)
6585 @itemx PGT(var_name, value)
6586 Fraction between 0 and 1, or percentage between 0 and 100, respectively,
6587 of values greater than the specified constant.
6588 @item FLT(var_name, value)
6589 @itemx PLT(var_name, value)
6590 Fraction or percentage, respectively, of values less than the specified
6591 constant.
6592 @item FIN(var_name, low, high)
6593 @itemx PIN(var_name, low, high)
6594 Fraction or percentage, respectively, of values within the specified
6595 inclusive range of constants.
6596 @item FOUT(var_name, low, high)
6597 @itemx POUT(var_name, low, high)
6598 Fraction or percentage, respectively, of values strictly outside the
6599 specified range of constants.
6600 @item N(var_name)
6601 Number of non-missing values.
6602 @item N
6603 Number of cases aggregated to form this group.  Don't supply a source
6604 variable for this aggregation function.
6605 @item NU(var_name)
6606 Number of non-missing values.  Each case is considered to have a weight
6607 of 1, regardless of the current weighting variable (@pxref{WEIGHT}).
6608 @item NU
6609 Number of cases aggregated to form this group.  Each case is considered
6610 to have a weight of 1, regardless of the current weighting variable.
6611 @item NMISS(var_name)
6612 Number of missing values.
6613 @item NUMISS(var_name)
6614 Number of missing values.  Each case is considered to have a weight of
6615 1, regardless of the current weighting variable.
6616 @item FIRST(var_name)
6617 First value in this group.
6618 @item LAST(var_name)
6619 Last value in this group.
6620 @end table
6621
6622 When string values are compared by aggregation functions, they are done
6623 in terms of internal character codes.  On most modern computers, this is
6624 a form of ASCII.
6625
6626 In addition, there is a parallel set of aggregation functions having the
6627 same names as those above, but with a dot after the last character (for
6628 instance, @samp{SUM.}).  These functions are the same as the above,
6629 except that they cause user-missing values, which are normally excluded
6630 from calculations, to be included.
6631
6632 Normally, only a single case (2 for SD and SD.) need be non-missing in
6633 each group in order for the aggregate variable to be non-missing.  If
6634 /MISSING=COLUMNWISE is specified, the behavior reverses: that is, a
6635 single missing value is enough to make the aggregate variable become a
6636 missing value.
6637
6638 AGGREGATE ignores the current SPLIT FILE settings and causes them to be
6639 canceled (@pxref{SPLIT FILE}).  
6640
6641 @node AUTORECODE, COMPUTE, AGGREGATE, Data Manipulation
6642 @section AUTORECODE
6643 @vindex AUTORECODE
6644
6645 @display
6646 AUTORECODE VARIABLES=src_vars INTO dest_vars
6647         /DESCENDING
6648         /PRINT
6649 @end display
6650
6651 The AUTORECODE procedure considers the @var{n} values that a variable
6652 takes on and maps them onto values 1@dots{}@var{n} on a new numeric
6653 variable.
6654
6655 Subcommand VARIABLES is the only required subcommand and must come
6656 first.  Specify VARIABLES, an equals sign (@samp{=}), a list of source
6657 variables, INTO, and a list of target variables.  There must the same
6658 number of source and target variables.  The target variables must not
6659 already exist.
6660
6661 By default, increasing values of a source variable (for a string, this
6662 is based on character code comparisons) are recoded to increasing values
6663 of its target variable.  To cause increasing values of a source variable
6664 to be recoded to decreasing values of its target variable (@var{n} down
6665 to 1), specify DESCENDING.
6666
6667 PRINT is currently ignored.
6668
6669 AUTORECODE is a procedure.  It causes the data to be read.
6670
6671 @node COMPUTE, COUNT, AUTORECODE, Data Manipulation
6672 @section COMPUTE
6673
6674 @display
6675 COMPUTE var_name = expression.
6676 @end display
6677
6678 @code{COMPUTE} creates a variable with the name specified (if
6679 necessary), then evaluates the given expression for every case and
6680 assigns the result to the variable.  @xref{Expressions}.
6681
6682 Numeric variables created or computed by @code{COMPUTE} are assigned an
6683 output width of 8 character with two decimal places (@code{F8.2}).
6684 String variables created or computed by @code{COMPUTE} have the same
6685 width as the existing variable or constant.
6686
6687 COMPUTE is a transformation.  It does not cause the active file to be
6688 read.
6689
6690 @node COUNT, FLIP, COMPUTE, Data Manipulation
6691 @section COUNT
6692
6693 @display
6694 COUNT var_name = var@dots{} (value@dots{}).
6695
6696 Each value takes one of the following forms:
6697         number
6698         string
6699         num1 THRU num2
6700         MISSING
6701         SYSMIS
6702 In addition, num1 and num2 can be LO or LOWEST, or HI or HIGHEST,
6703 respectively.
6704 @end display
6705
6706 @code{COUNT} creates or replaces a numeric @dfn{target} variable that
6707 counts the occurrence of a @dfn{criterion} value or set of values over
6708 one or more @dfn{test} variables for each case.
6709
6710 The target variable values are always nonnegative integers.  They are
6711 never missing.  The target variable is assigned an F8.2 output format.
6712 @xref{Input/Output Formats}.  Any variables, including long and short
6713 string variables, may be test variables.
6714
6715 User-missing values of test variables are treated just like any other
6716 values.  They are @strong{not} treated as system-missing values.
6717 User-missing values that are criterion values or inside ranges of
6718 criterion values are counted as any other values.  However (for numeric
6719 variables), keyword @code{MISSING} may be used to refer to all system-
6720 and user-missing values.
6721
6722
6723 @code{COUNT} target variables are assigned values in the order
6724 specified.  In the command @code{COUNT A=A B(1) /B=A B(2).}, the
6725 following actions occur:
6726
6727 @itemize @minus
6728 @item
6729 The number of occurrences of 1 between @code{A} and @code{B} is counted.
6730
6731 @item
6732 @code{A} is assigned this value.
6733
6734 @item
6735 The number of occurrences of 1 between @code{B} and the @strong{new}
6736 value of @code{A} is counted.
6737
6738 @item
6739 @code{B} is assigned this value.
6740 @end itemize
6741
6742 Despite this ordering, all @code{COUNT} criterion variables must exist
6743 before the procedure is executed---they may not be created as target
6744 variables earlier in the command!  Break such a command into two
6745 separate commands.
6746
6747 The examples below may help to clarify.
6748
6749 @enumerate A
6750 @item
6751 Assuming @code{Q0}, @code{Q2}, @dots{}, @code{Q9} are numeric variables,
6752 the following commands:
6753
6754 @enumerate
6755 @item
6756 Count the number of times the value 1 occurs through these variables
6757 for each case and assigns the count to variable @code{QCOUNT}.  
6758
6759 @item
6760 Print out the total number of times the value 1 occurs throughout
6761 @emph{all} cases using @code{DESCRIPTIVES}.  @xref{DESCRIPTIVES}, for
6762 details.
6763 @end enumerate
6764
6765 @example
6766 COUNT QCOUNT=Q0 TO Q9(1).
6767 DESCRIPTIVES QCOUNT /STATISTICS=SUM.
6768 @end example
6769
6770 @item
6771 Given these same variables, the following commands:
6772
6773 @enumerate
6774 @item
6775 Count the number of valid values of these variables for each case and
6776 assigns the count to variable @code{QVALID}.
6777
6778 @item
6779 Multiplies each value of @code{QVALID} by 10 to obtain a percentage of
6780 valid values, using @code{COMPUTE}.  @xref{COMPUTE}, for details.
6781
6782 @item
6783 Print out the percentage of valid values across all cases, using
6784 @code{DESCRIPTIVES}.  @xref{DESCRIPTIVES}, for details.
6785 @end enumerate
6786
6787 @example
6788 COUNT QVALID=Q0 TO Q9 (LO THRU HI).
6789 COMPUTE QVALID=QVALID*10.
6790 DESCRIPTIVES QVALID /STATISTICS=MEAN.
6791 @end example
6792 @end enumerate
6793
6794 @node FLIP, IF, COUNT, Data Manipulation
6795 @section FLIP
6796 @vindex FLIP
6797
6798 @display
6799 FLIP /VARIABLES=var_list /NEWNAMES=var_name.
6800 @end display
6801
6802 The FLIP command transposes rows and columns in the active file.  It
6803 causes cases to be swapped with variables, and vice versa.
6804
6805 There are no required subcommands.  The VARIABLES subcommand specifies
6806 variables that will be transformed into cases.  Variables not specified
6807 are discarded.  By default, all variables are selected for
6808 transposition.
6809
6810 The variables specified by NEWNAMES, which must be a string variable, is
6811 used to give names to the variables created by FLIP.  If NEWNAMES is not
6812 specified then the default is a variable named CASE_LBL, if it exists.
6813 If it does not then the variables created by FLIP are named VAR000
6814 through VAR999, then VAR1000, VAR1001, and so on.
6815
6816 When a NEWNAMES variable is available, the names must be canonicalized
6817 before becoming variable names.  Invalid characters are replaced by
6818 letter @samp{V} in the first position, or by @samp{_} in subsequent
6819 positions.  If the name thus generated is not unique, then numeric
6820 extensions are added, starting with 1, until a unique name is found or
6821 there are no remaining possibilities.  If the latter occurs then the
6822 FLIP operation aborts.
6823
6824 The resultant dictionary contains a CASE_LBL variable, which stores the
6825 names of the variables in the dictionary before the transposition.  If
6826 the active file is subsequently transposed using FLIP, this variable can
6827 be used to recreate the original variable names.
6828
6829 @node IF, RECODE, FLIP, Data Manipulation
6830 @section IF
6831
6832 @display
6833 Two possible syntaxes: 
6834         IF test_expr target_var=target_expr.
6835         IF test_expr target_vec(target_index)=target_expr.
6836 @end display
6837
6838 The IF transformation conditionally assigns the value of a target
6839 expression to a target variable, based on the truth of a test
6840 expression.
6841
6842 Specify a boolean-valued expression (@pxref{Expressions}) to be tested
6843 following the IF keyword.  This expression is calculated for each case.
6844 If the value is true, then the value of target_expr is computed and
6845 assigned to target_var.  If the value is false or missing, nothing is
6846 done.  Numeric and short and long string variables may be used.  The
6847 type of target_expr must match the type of target_var.
6848
6849 For numeric variables only, target_var need not exist before the IF
6850 transformation is executed.  In this case, target_var is assigned the
6851 system-missing value if the IF condition is not true.  String variables
6852 must be declared before they can be used as targets for IF.
6853
6854 In addition to ordinary variables, the target variable may be an element
6855 of a vector.  In this case, the vector index must be specified in
6856 parentheses following the vector name.
6857
6858 @node RECODE, SORT CASES, IF, Data Manipulation
6859 @section RECODE
6860
6861 @display
6862 RECODE var_list (src_value@dots{}=dest_value)@dots{} [INTO var_list].
6863
6864 src_value may take the following forms:
6865         number
6866         string
6867         num1 THRU num2
6868         MISSING
6869         SYSMIS
6870         ELSE
6871 Open-ended ranges may be specified using LO or LOWEST for num1
6872 or HI or HIGHEST for num2.
6873
6874 dest_value may take the following forms:
6875         num
6876         string
6877         SYSMIS
6878         COPY
6879 @end display
6880
6881 The RECODE command is used to translate data from one range of values to
6882 another, using flexible user-specified mappings.  Data may be remapped
6883 in-place or copied to new variables.  Numeric, short string, and long
6884 string data can be recoded.
6885
6886 Specify the list of source variables, followed by one or more mapping
6887 specifications each enclosed in parentheses.  If the data is to be
6888 copied to new variables, specify INTO, then the list of target
6889 variables.  String target variables must already have been declared
6890 using STRING or another transformation, but numeric target variables can
6891 be created on the fly.  There must be exactly as many target variables
6892 as source variables.  Each source variable is remapped into its
6893 corresponding target variable.
6894
6895 When INTO is not used, the input and output variables must be of the
6896 same type.  Otherwise, string values can be recoded into numeric values,
6897 and vice versa.  When this is done and there is no mapping for a
6898 particular value, either a value consisting of all spaces or the
6899 system-missing value is assigned, depending on variable type.
6900
6901 Mappings are considered from left to right.  The first src_value that
6902 matches the value of the source variable causes the target variable to
6903 receive the value indicated by the dest_value.  Literal number, string,
6904 and range src_value's should be self-explanatory.  MISSING as a
6905 src_value matches any user- or system-missing value.  SYSMIS matches the
6906 system missing value only.  ELSE is a catch-all that matches anything.
6907 It should be the last src_value specified.
6908
6909 Numeric and string dest_value's should also be self-explanatory.  COPY
6910 causes the input values to be copied to the output.  This is only value
6911 if the source and target variables are of the same type.  SYSMIS
6912 indicates the system-missing value.
6913
6914 If the source variables are strings and the target variables are
6915 numeric, then there is one additional mapping available: (CONVERT),
6916 which must be the last specified mapping.  CONVERT causes a number
6917 specified as a string to be converted to a numeric value.  If the string
6918 cannot be parsed as a number, then the system-missing value is assigned.
6919
6920 Multiple recodings can be specified on the same RECODE command.
6921 Introduce additional recodings with a slash (@samp{/}) in order to
6922 separate them from the previous recodings.
6923
6924 @node SORT CASES,  , RECODE, Data Manipulation
6925 @section SORT CASES
6926 @vindex SORT CASES
6927
6928 @display
6929 SORT CASES BY var_list.
6930 @end display
6931
6932 SORT CASES sorts the active file by the values of one or more
6933 variables.
6934
6935 Specify BY and a list of variables to sort by.  By default, variables
6936 are sorted in ascending order.  To override sort order, specify (D) or
6937 (DOWN) after a list of variables to get descending order, or (A) or (UP)
6938 for ascending order.  These apply to the entire list of variables
6939 preceding them.
6940
6941 SORT CASES is a procedure.  It causes the data to be read.
6942
6943 SORT CASES will attempt to sort the entire active file in main memory.
6944 If main memory is exhausted then it will use a merge sort algorithm that
6945 involves writing and reading numerous temporary files.  Environment
6946 variables determine the temporary files' location.  The first of
6947 SPSSTMPDIR, SPSSXTMPDIR, or TMPDIR that is set determines the location.
6948 Otherwise, if the compiler environment defined P_tmpdir, that is used.
6949 Otherwise, under Unix-like OSes /tmp is used; under MS-DOS, the first of
6950 TEMP, TMP, or root on the current drive is used; under other OSes, the
6951 current directory.
6952
6953 @node Data Selection, Conditionals and Looping, Data Manipulation, Top
6954 @chapter Selecting data for analysis
6955
6956 This chapter documents PSPP commands that temporarily or permanently
6957 select data records from the active file for analysis.
6958
6959 @menu
6960 * FILTER::                      Exclude cases based on a variable.
6961 * N OF CASES::                  Limit the size of the active file.
6962 * PROCESS IF::                  Temporarily excluding cases.
6963 * SAMPLE::                      Select a specified proportion of cases.
6964 * SELECT IF::                   Permanently delete selected cases.
6965 * SPLIT FILE::                  Do multiple analyses with one command.
6966 * TEMPORARY::                   Make transformations' effects temporary.
6967 * WEIGHT::                      Weight cases by a variable.
6968 @end menu
6969
6970 @node FILTER, N OF CASES, Data Selection, Data Selection
6971 @section FILTER
6972 @vindex FILTER
6973
6974 @display
6975 FILTER BY var_name.
6976 FILTER OFF.
6977 @end display
6978
6979 The FILTER command allows a boolean-valued variable to be used to select
6980 cases from the data stream for processing.
6981
6982 In order to set up filtering, specify BY and a variable name.  Keyword
6983 BY is optional but recommended.  Cases which have a zero or system- or
6984 user-missing value are excluded from analysis, but not deleted from the
6985 data stream.  Cases with other values are analyzed.
6986
6987 Use FILTER OFF to turn off case filtering.
6988
6989 Filtering takes place immediately before cases pass to a procedure for
6990 analysis.  Only one filter variable may be active at once.  Normally,
6991 case filtering continues until it is explicitly turned off with FILTER
6992 OFF.  However, if FILTER is placed after TEMPORARY, then filtering stops
6993 after execution of the next procedure or procedure-like command.
6994
6995 @node N OF CASES, PROCESS IF, FILTER, Data Selection
6996 @section N OF CASES
6997 @vindex N OF CASES
6998
6999 @display
7000 N [OF CASES] num_of_cases [ESTIMATED].
7001 @end display
7002
7003 Sometimes you may want to disregard cases of your input.  The @code{N}
7004 command can be used to do this.  @code{N 100} tells PSPP to
7005 disregard all cases after the first 100.
7006
7007 If the value specified for @code{N} is greater than the number of cases
7008 read in, the value is ignored.
7009
7010 @code{N} does not discard cases or cause them not to be read in.  It
7011 just causes cases beyond the last one specified to be ignored by data
7012 analysis commands.
7013
7014 A later @code{N} command can increase or decrease the number of cases
7015 selected.  (To select all the cases without knowing how many there are,
7016 specify a very high number: 100000 or whatever you think is large enough.)
7017
7018 Transformation procedures performed after @code{N} is executed
7019 @emph{do} cause cases to be discarded.
7020
7021 The @code{SAMPLE}, @code{PROCESS IF}, and @code{SELECT IF} commands have
7022 precedence over @code{N}---the same results are obtained by both of the
7023 following fragments, given the same random number seeds:
7024
7025 @example
7026 @i{@dots{}set up, read in data@dots{}}
7027 N 100.
7028 SAMPLE .5.
7029 @i{@dots{}analyze data@dots{}}
7030
7031 @i{@dots{}set up, read in data@dots{}}  
7032 SAMPLE .5.
7033 N 100.
7034 @i{@dots{}analyze data@dots{}}
7035 @end example
7036
7037 Both fragments above first randomly sample approximately half of the
7038 cases, then select the first 100 of those sampled.
7039
7040 @code{N} with the @code{ESTIMATED} keyword can be used to give an
7041 estimated number of cases before DATA LIST or another command to
7042 read in data.  (@code{ESTIMATED} never limits the number of cases
7043 processed by procedures.)
7044
7045 @node PROCESS IF, SAMPLE, N OF CASES, Data Selection
7046 @section PROCESS IF
7047 @vindex PROCESS IF
7048
7049 @example
7050 PROCESS IF expression.
7051 @end example
7052
7053 The PROCESS IF command is used to temporarily eliminate cases from the
7054 data stream.  Its effects are active only through the execution of the
7055 next procedure or procedure-like command.
7056
7057 Specify a boolean expression (@pxref{Expressions}).  If the value of the
7058 expression is true for a particular case, the case will be analyzed.  If
7059 the expression has a false or missing value, then the case will be
7060 deleted from the data stream for this procedure only.
7061
7062 Regardless of its placement relative to other commands, PROCESS IF
7063 always takes effect immediately before data passes to the procedure.
7064 Only one PROCESS IF command may be in effect at any given time.
7065
7066 The effects of PROCESS IF are similar not identical to the effects of
7067 executing TEMPORARY then SELECT IF (@pxref{SELECT IF}).
7068
7069 Use of PROCESS IF is deprecated.  It is included for compatibility with
7070 old command files.  New syntax files should use SELECT IF or FILTER
7071 instead.
7072
7073 @node SAMPLE, SELECT IF, PROCESS IF, Data Selection
7074 @section SAMPLE
7075 @vindex SAMPLE
7076
7077 @display
7078 SAMPLE num1 [FROM num2].
7079 @end display
7080
7081 @code{SAMPLE} is used to randomly sample a proportion of the cases in
7082 the active file.  @code{SAMPLE} is temporary, affecting only the next
7083 procedure, unless that is a data transformation, such as @code{SELECT IF}
7084 or @code{RECODE}.
7085
7086 The proportion to sample can be expressed as a single number between 0
7087 and 1.  If @code{k} is the number specified, and @code{N} is the number
7088 of currently-selected cases in the active file, then after
7089 @code{SAMPLE @var{k}.}, there will be @code{k*N}, plus or minus one, cases
7090 selected.
7091
7092 The proportion to sample can also be specified in the style @code{SAMPLE
7093 @var{m} FROM @var{N}}.  With this style, cases are selected as follows:
7094
7095 @enumerate
7096 @item
7097 If @var{N} is equal to the number of currently-selected cases in the
7098 active file, exactly @var{m} cases will be selected.
7099
7100 @item
7101 If @var{N} is greater than the number of currently-selected cases in the
7102 active file, an equivalent proportion of cases will be selected.
7103
7104 @item
7105 If @var{N} is less than the number of currently-selected cases in the
7106 active, exactly @var{m} cases will be selected @emph{from the first
7107 @var{N} cases in the active file.}
7108 @end enumerate
7109
7110 @code{SAMPLE}, @code{SELECT IF}, and @code{PROCESS IF} are performed in
7111 the order specified by the syntax file.
7112
7113 @code{SAMPLE} is ignored before @code{SORT CASES}.
7114
7115 @code{SAMPLE} is always performed before @code{N OF CASES}, regardless
7116 of ordering in the syntax file.  @xref{N OF CASES}.
7117
7118 The same values for @code{SAMPLE} may result in different samples.  To
7119 obtain the same sample, use the @code{SET} command to set the random
7120 number seed to the same value before each @code{SAMPLE}.  By default,
7121 the random number seed is based on the system time.
7122
7123 @node SELECT IF, SPLIT FILE, SAMPLE, Data Selection
7124 @section SELECT IF
7125 @vindex SELECT IF
7126
7127 @display
7128 SELECT IF expression.
7129 @end display
7130
7131 The SELECT IF command is used to select particular cases for analysis
7132 based on the value of a boolean expression.  Cases not selected are
7133 permanently eliminated, unless TEMPORARY is in effect
7134 (@pxref{TEMPORARY}).
7135
7136 Specify a boolean expression (@pxref{Expressions}).  If the value of the
7137 expression is true for a particular case, the case will be analyzed.  If
7138 the expression has a false or missing value, then the case will be
7139 deleted from the data stream.
7140
7141 Always place SELECT IF commands as early in the command file as
7142 possible.  Cases that are deleted early can be processed more
7143 efficiently in time and space.
7144
7145 @node SPLIT FILE, TEMPORARY, SELECT IF, Data Selection
7146 @section SPLIT FILE
7147 @vindex SPLIT FILE
7148
7149 @display
7150 Two possible syntaxes:
7151         SPLIT FILE BY var_list.
7152         SPLIT FILE OFF.
7153 @end display
7154
7155 The SPLIT FILE command allows multiple sets of data present in one data
7156 file to be analyzed separately using single statistical procedure
7157 commands.
7158
7159 Specify a list of variable names in order to analyze multiple sets of
7160 data separately.  Groups of cases having the same values for these
7161 variables are analyzed by statistical procedure commands as one group.
7162 An independent analysis is carried out for each group of cases, and the
7163 variable values for the group are printed along with the analysis.
7164
7165 Specify OFF in order to disable SPLIT FILE and resume analysis of the
7166 entire active file as a single group of data.
7167
7168 @node TEMPORARY, WEIGHT, SPLIT FILE, Data Selection
7169 @section TEMPORARY
7170 @vindex TEMPORARY
7171
7172 @display
7173 TEMPORARY.
7174 @end display
7175
7176 The TEMPORARY command is used to make the effects of transformations
7177 following its execution temporary.  These transformations will
7178 affect only the execution of the next procedure or procedure-like
7179 command.  Their effects will not be saved to the active file.
7180
7181 The only specification is the command name.
7182
7183 TEMPORARY may not appear within a DO IF or LOOP construct.  It may
7184 appear only once between procedures and procedure-like commands.
7185
7186 An example may help to clarify:
7187
7188 @example
7189 DATA LIST /X 1-2.
7190 BEGIN DATA.
7191  2
7192  4
7193 10
7194 15
7195 20
7196 24
7197 END DATA.
7198 COMPUTE X=X/2.
7199 TEMPORARY.
7200 COMPUTE X=X+3.
7201 DESCRIPTIVES X.
7202 DESCRIPTIVES X.
7203 @end example
7204
7205 The data read by the first DESCRIPTIVES command are 4, 5, 8,
7206 10.5, 13, 15.  The data read by the first DESCRIPTIVES command are 1, 2,
7207 5, 7.5, 10, 12.
7208
7209 @node WEIGHT,  , TEMPORARY, Data Selection
7210 @section WEIGHT
7211 @vindex WEIGHT
7212
7213 @display
7214 WEIGHT BY var_name.
7215 WEIGHT OFF.
7216 @end display
7217
7218 WEIGHT can be used to assign cases varying weights in order to
7219 change the frequency distribution of the active file.  Execution of
7220 WEIGHT is delayed until data have been read in.
7221
7222 If a variable name is specified, WEIGHT causes the values of that
7223 variable to be used as weighting factors for subsequent statistical
7224 procedures.  Use of keyword BY is optional but recommended.  Weighting
7225 variables must be numeric.  Scratch variables may not be used for
7226 weighting (@pxref{Scratch Variables}).
7227
7228 When OFF is specified, subsequent statistical procedures will weight all
7229 cases equally.
7230
7231 Weighting values do not need to be integers.  However, negative and
7232 system- and user-missing values for the weighting variable are
7233 interpreted as weighting factors of 0.
7234
7235 WEIGHT does not cause cases in the active file to be replicated in
7236 memory.
7237
7238 @node Conditionals and Looping, Statistics, Data Selection, Top
7239 @chapter Conditional and Looping Constructs
7240 @cindex conditionals
7241 @cindex loops
7242 @cindex flow of control
7243 @cindex control flow
7244
7245 This chapter documents PSPP commands used for conditional execution,
7246 looping, and flow of control.
7247
7248 @menu
7249 * BREAK::                       Exit a loop.
7250 * DO IF::                       Conditionally execute a block of code.
7251 * DO REPEAT::                   Textually repeat a code block.
7252 * LOOP::                        Repeat a block of code.
7253 @end menu
7254
7255 @node BREAK, DO IF, Conditionals and Looping, Conditionals and Looping
7256 @section BREAK
7257 @vindex BREAK
7258
7259 @display
7260 BREAK.
7261 @end display
7262
7263 BREAK terminates execution of the innermost currently executing LOOP
7264 construct.
7265
7266 BREAK is allowed only inside a LOOP construct.  @xref{LOOP}, for more
7267 details.
7268
7269 @node DO IF, DO REPEAT, BREAK, Conditionals and Looping
7270 @section DO IF
7271 @vindex DO IF
7272
7273 @display
7274 DO IF condition.
7275         @dots{}
7276 [ELSE IF condition.
7277         @dots{}
7278 ]@dots{}
7279 [ELSE.
7280         @dots{}]
7281 END IF.
7282 @end display
7283
7284 The DO IF command allows one of several sets of transformations to be
7285 executed, depending on user-specified conditions.
7286
7287 Specify a boolean expression.  If the condition is true, then the block
7288 of code following DO IF is executed.  If the condition is missing, then
7289 none of the code blocks is executed.  If the condition is false, then
7290 the boolean expressions on the first ELSE IF, if present, is tested in
7291 turn, with the same rules applied.  If all expressions evaluate to
7292 false, then the ELSE code block is executed, if it is present.
7293
7294 @node DO REPEAT, LOOP, DO IF, Conditionals and Looping
7295 @section DO REPEAT
7296 @vindex DO REPEAT
7297
7298 @display
7299 DO REPEAT repvar_name=expansion@dots{}.
7300         @dots{}
7301 END REPEAT [PRINT].
7302
7303 expansion takes one of the following forms:
7304         var_list
7305         num_or_range@dots{}
7306         'string'@dots{}
7307
7308 num_or_range takes one of the following forms:
7309         number
7310         num1 TO num2
7311 @end display
7312
7313 The DO REPEAT command causes a block of code to be repeated a number of
7314 times with different variables, numbers, or strings textually
7315 substituted into the block with each repetition.
7316
7317 Specify a repeat variable name followed by an equals sign (@samp{=}) and
7318 the list of replacements.  Replacements can be a list of variables
7319 (which may be existing variables or new variables or a combination
7320 thereof), of numbers, or of strings.  When new variable names are
7321 specified, DO REPEAT creates them as numeric variables.  When numbers
7322 are specified, runs of integers may be indicated with TO notation, for
7323 instance @samp{1 TO 5} and @samp{1 2 3 4 5} would be equivalent.  There
7324 is no equivalent notation for string values.
7325
7326 Multiple repeat variables can be specified.  When this is done, each
7327 variable must have the same number of replacements.
7328
7329 The code within DO REPEAT is repeated as many times as there are
7330 replacements for each variable.  The first time, the first value for
7331 each repeat variable is substituted; the second time, the second value
7332 for each repeat variable is substituted; and so on.
7333
7334 Repeat variable substitutions work like macros.  They take place
7335 anywhere in a line that the repeat variable name occurs as a token,
7336 including command and subcommand names.  For this reason it is not a
7337 good idea to select words commonly used in command and subcommand names
7338 as repeat variable identifiers.
7339
7340 If PRINT is specified on END REPEAT, the commands after substitutions
7341 are made are printed to the listing file, prefixed by a plus sign
7342 (@samp{+}).
7343
7344 @node LOOP,  , DO REPEAT, Conditionals and Looping
7345 @section LOOP
7346 @vindex LOOP
7347
7348 @display
7349 LOOP [index_var=start TO end [BY incr]] [IF condition].
7350         @dots{}
7351 END LOOP [IF condition].
7352 @end display
7353
7354 The LOOP command allows a group of commands to be iterated.  A number of
7355 termination options are offered.
7356
7357 Specify index_var in order to make that variable count from one value to
7358 another by a particular increment.  index_var must be a pre-existing
7359 numeric variable.  start, end, and incr are numeric expressions
7360 (@pxref{Expressions}.)  
7361
7362 During the first iteration, index_var is set to the value of start.
7363 During each successive iteration, index_var is increased by the value of
7364 incr.  If end > start, then the loop terminates when index_var > end;
7365 otherwise it terminates when index_var < end.  If incr is not specified
7366 then it defaults to +1 or -1 as appropriate.
7367
7368 If end > start and incr < 0, or if end < start and incr > 0, then the
7369 loop is never executed.  index_var is nevertheless set to the value of
7370 start.
7371
7372 Modifying index_var within the loop is allowed, but it has no effect on
7373 the value of index_var in the next iteration.
7374
7375 Specify a boolean expression for the condition on the LOOP command to
7376 cause the loop to be executed only if the condition is true.  If the
7377 condition is false or missing before the loop contents are executed the
7378 first time, the loop contents are not executed at all.
7379
7380 If index and condition clauses are both present on LOOP, the index
7381 clause is always evaluated first.
7382
7383 Specify a boolean expression for the condition on the END LOOP to cause
7384 the loop to terminate if the condition is not true after the enclosed
7385 code block is executed.  The condition is evaluated at the end of the
7386 loop, not at the beginning.
7387
7388 If the index clause and both condition clauses are not present, then the
7389 loop is executed MXLOOPS (@pxref{SET}) times or until BREAK
7390 (@pxref{BREAK}) is executed.
7391
7392 The BREAK command provides another way to terminate execution of a LOOP
7393 construct.
7394
7395 @node Statistics, Utilities, Conditionals and Looping, Top
7396 @chapter Statistics
7397
7398 This chapter documents the statistical procedures that PSPP supports so
7399 far.
7400
7401 @menu
7402 * DESCRIPTIVES::                Descriptive statistics.
7403 * FREQUENCIES::                 Frequency tables.
7404 * CROSSTABS::                   Crosstabulation tables.
7405 @end menu
7406
7407 @node DESCRIPTIVES, FREQUENCIES, Statistics, Statistics
7408 @section DESCRIPTIVES
7409
7410 @display
7411 DESCRIPTIVES
7412         /VARIABLES=var_list
7413         /MISSING=@{VARIABLE,LISTWISE@} @{INCLUDE,NOINCLUDE@}
7414         /FORMAT=@{LABELS,NOLABELS@} @{NOINDEX,INDEX@} @{LINE,SERIAL@}
7415         /SAVE
7416         /STATISTICS=@{ALL,MEAN,SEMEAN,STDDEV,VARIANCE,KURTOSIS,
7417                      SKEWNESS,RANGE,MINIMUM,MAXIMUM,SUM,DEFAULT,
7418                      SESKEWNESS,SEKURTOSIS@}
7419         /SORT=@{NONE,MEAN,SEMEAN,STDDEV,VARIANCE,KURTOSIS,SKEWNESS,
7420                RANGE,MINIMUM,MAXIMUM,SUM,SESKEWNESS,SEKURTOSIS,NAME@}
7421               @{A,D@}
7422 @end display
7423
7424 The DESCRIPTIVES procedure reads the active file and outputs descriptive
7425 statistics requested by the user.  In addition, it can optionally
7426 compute Z-scores.
7427
7428 The VARIABLES subcommand, which is required, specifies the list of
7429 variables to be analyzed.  Keyword VARIABLES is optional.
7430
7431 All other subcommands are optional:
7432
7433 The MISSING subcommand determines the handling of missing variables.  If
7434 INCLUDE is set, then user-missing values are included in the
7435 calculations.  If NOINCLUDE is set, which is the default, user-missing
7436 values are excluded.  If VARIABLE is set, then missing values are
7437 excluded on a variable by variable basis; if LISTWISE is set, then
7438 the entire case is excluded whenever any value in that case has a
7439 system-missing or, if INCLUDE is set, user-missing value.
7440
7441 The FORMAT subcommand affects the output format.  Currently the
7442 LABELS/NOLABELS and NOINDEX/INDEX settings is not used.  When SERIAL is
7443 set, both valid and missing number of cases are listed in the output;
7444 when NOSERIAL is set, only valid cases are listed.
7445
7446 The SAVE subcommand causes DESCRIPTIVES to calculate Z scores for all
7447 the specified variables.  The Z scores are saved to new variables.
7448 Variable names are generated by trying first the original variable name
7449 with Z prepended and truncated to a maximum of 8 characters, then the
7450 names ZSC000 through ZSC999, STDZ00 through STDZ09, ZZZZ00 through
7451 ZZZZ09, ZQZQ00 through ZQZQ09, in that sequence.  In addition, Z score
7452 variable names can be specified explicitly on VARIABLES in the variable
7453 list by enclosing them in parentheses after each variable.
7454
7455 The STATISTICS subcommand specifies the statistics to be displayed:
7456
7457 @table @code
7458 @item ALL
7459 All of the statistics below.
7460 @item MEAN
7461 Arithmetic mean.
7462 @item SEMEAN
7463 Standard error of the mean.
7464 @item STDDEV
7465 Standard deviation.
7466 @item VARIANCE
7467 Variance.
7468 @item KURTOSIS
7469 Kurtosis and standard error of the kurtosis.
7470 @item SKEWNESS
7471 Skewness and standard error of the skewness.
7472 @item RANGE
7473 Range.
7474 @item MINIMUM
7475 Minimum value.
7476 @item MAXIMUM
7477 Maximum value.
7478 @item SUM
7479 Sum.
7480 @item DEFAULT
7481 Mean, standard deviation of the mean, minimum, maximum.
7482 @item SEKURTOSIS
7483 Standard error of the kurtosis.
7484 @item SESKEWNESS
7485 Standard error of the skewness.
7486 @end table
7487
7488 The SORT subcommand specifies how the statistics should be sorted.  Most
7489 of the possible values should be self-explanatory.  NAME causes the
7490 statistics to be sorted by name.  By default, the statistics are listed
7491 in the order that they are specified on the VARIABLES subcommand.  The A
7492 and D settings request an ascending or descending sort order,
7493 respectively.
7494
7495 @node FREQUENCIES, CROSSTABS, DESCRIPTIVES, Statistics
7496 @section FREQUENCIES
7497
7498 @display
7499 FREQUENCIES
7500         /VARIABLES=var_list
7501         /FORMAT=@{TABLE,NOTABLE,LIMIT(limit)@}
7502                 @{STANDARD,CONDENSE,ONEPAGE[(onepage_limit)]@}
7503                 @{LABELS,NOLABELS@}
7504                 @{AVALUE,DVALUE,AFREQ,DFREQ@}
7505                 @{SINGLE,DOUBLE@}
7506                 @{OLDPAGE,NEWPAGE@}
7507         /MISSING=@{EXCLUDE,INCLUDE@}
7508         /STATISTICS=@{DEFAULT,MEAN,SEMEAN,MEDIAN,MODE,STDDEV,VARIANCE,
7509                      KURTOSIS,SKEWNESS,RANGE,MINIMUM,MAXIMUM,SUM,
7510                      SESKEWNESS,SEKURTOSIS,ALL,NONE@}
7511         /NTILES=ntiles
7512         /PERCENTILES=percent@dots{}
7513
7514 (These options are not currently implemented.)
7515         /BARCHART=@dots{}
7516         /HISTOGRAM=@dots{}
7517         /HBAR=@dots{}
7518         /GROUPED=@dots{}
7519
7520 (Integer mode.)
7521         /VARIABLES=var_list (low,high)@dots{}
7522 @end display
7523
7524 FREQUENCIES causes the data to be read and frequency tables to be built
7525 and output for specified variables.  FREQUENCIES can also calculate and
7526 display descriptive statistics (including median and mode) and
7527 percentiles.
7528
7529 In the future, FREQUENCIES will also support graphical output in the
7530 form of bar charts and histograms.  In addition, it will be able to
7531 support percentiles for grouped data.  (As a historical note, these
7532 options were supported in a version of PSPP written years ago, but the
7533 code has not survived.)
7534
7535 The VARIABLES subcommand is the only required subcommand.  Specify the
7536 variables to be analyzed.  In most cases, this is all that is required.
7537 This is known as @dfn{general mode}.
7538
7539 Occasionally, one may want to invoke a special mode called @dfn{integer
7540 mode}.  Normally, in general mode, PSPP will automatically determine
7541 what values occur in the data.  In integer mode, the user specifies the
7542 range of values that the data assumes.  To invoke this mode, specify a
7543 range of data values in parentheses, separated by a comma.  Data values
7544 inside the range are truncated to the nearest integer, then assigned to
7545 that value.  If values occur outside this range, they are discarded.
7546
7547 The FORMAT subcommand controls the output format.  It has several
7548 possible settings:  
7549
7550 @itemize @bullet
7551 @item
7552 TABLE, the default, causes a frequency table to be output for every
7553 variable specified.  NOTABLE prevents them from being output.  LIMIT
7554 with a numeric argument causes them to be output except when there are
7555 more than the specified number of values in the table.
7556
7557 @item
7558 STANDARD frequency tables contain more complete information, but also to
7559 take up more space on the printed page.  CONDENSE frequency tables are
7560 less informative but take up less space.  ONEPAGE with a numeric
7561 argument will output standard frequency tables if there are the
7562 specified number of values or less, condensed tables otherwise.  ONEPAGE
7563 without an argument defaults to a threshold of 50 values.
7564
7565 @item
7566 LABELS causes value labels to be displayed in STANDARD frequency
7567 tables.  NOLABLES prevents this.
7568
7569 @item
7570 Normally frequency tables are sorted in ascending order by value.  This
7571 is AVALUE.  DVALUE tables are sorted in descending order by value.
7572 AFREQ and DFREQ tables are sorted in ascending and descending order,
7573 respectively, by frequency count.
7574
7575 @item
7576 SINGLE spaced frequency tables are closely spaced.  DOUBLE spaced
7577 frequency tables have wider spacing.
7578
7579 @item
7580 OLDPAGE and NEWPAGE are not currently used.
7581 @end itemize
7582
7583 The MISSING subcommand controls the handling of user-missing values.
7584 When EXCLUDE, the default, is set, user-missing values are not included
7585 in frequency tables or statistics.  When INCLUDE is set, user-missing
7586 are included.  System-missing values are never included in statistics,
7587 but are listed in frequency tables.
7588
7589 The available STATISTICS are the same as available in DESCRIPTIVES
7590 (@pxref{DESCRIPTIVES}), with the addition of MEDIAN, the data's median
7591 value, and MODE, the mode.  (If there are multiple modes, the smallest
7592 value is reported.)  By default, the mean, standard deviation of the
7593 mean, minimum, and maximum are reported for each variable.
7594
7595 NTILES causes the specified quartiles to be reported.  For instance,
7596 @code{/NTILES=4} would cause quartiles to be reported.  In addition,
7597 particular percentiles can be requested with the PERCENTILES subcommand.
7598
7599 @node CROSSTABS,  , FREQUENCIES, Statistics
7600 @section CROSSTABS
7601
7602 @display
7603 CROSSTABS
7604         /TABLES=var_list BY var_list [BY var_list]@dots{}
7605         /MISSING=@{TABLE,INCLUDE,REPORT@}
7606         /WRITE=@{NONE,CELLS,ALL@}
7607         /FORMAT=@{TABLES,NOTABLES@}
7608                 @{LABELS,NOLABELS,NOVALLABS@}
7609                 @{PIVOT,NOPIVOT@}
7610                 @{AVALUE,DVALUE@}
7611                 @{NOINDEX,INDEX@}
7612                 @{BOX,NOBOX@}
7613         /CELLS=@{COUNT,ROW,COLUMN,TOTAL,EXPECTED,RESIDUAL,SRESIDUAL,
7614                 ASRESIDUAL,ALL,NONE@}
7615         /STATISTICS=@{CHISQ,PHI,CC,LAMBDA,UC,BTAU,CTAU,RISK,GAMMA,D,
7616                      KAPPA,ETA,CORR,ALL,NONE@}
7617         
7618 (Integer mode.)
7619         /VARIABLES=var_list (low,high)@dots{}
7620 @end display
7621
7622 CROSSTABS reads the active file and builds and displays crosstabulation
7623 tables requested by the user.  It can calculate several statistics for
7624 each cell in the crosstabulation tables.  In addition, a number of
7625 statistics can be calculated for each table itself.
7626
7627 The TABLES subcommand is used to specify the tables to be reported.  Any
7628 number of dimensions is permitted, and any number of variables per
7629 dimension is allowed.  The TABLES subcommand may be repeated as many
7630 times as needed.  This is the only required subcommand in @dfn{general
7631 mode}.
7632
7633 Occasionally, one may want to invoke a special mode called @dfn{integer
7634 mode}.  Normally, in general mode, PSPP will automatically determine
7635 what values occur in the data.  In integer mode, the user specifies the
7636 range of values that the data assumes.  To invoke this mode, specify the
7637 VARIABLES subcommand, giving a range of data values in parentheses for
7638 each variable to be used on the TABLES subcommand.  Data values inside
7639 the range are truncated to the nearest integer, then assigned to that
7640 value.  If values occur outside this range, they are discarded.  When it
7641 is present, the VARIABLES subcommand must precede the TABLES subcommand.
7642
7643 The MISSING subcommand determines the handling of user-missing values.
7644 When set to TABLE, the default, missing values are dropped on a table by
7645 table basis.  When set to INCLUDE, user-missing values are included in
7646 tables and statistics.  When set to REPORT, which is allowed only in
7647 integer mode, user-missing values are included in tables but marked with
7648 an @samp{M} (for ``missing'') and excluded from statistical
7649 calculations.
7650
7651 Currently the WRITE subcommand is not used.
7652
7653 The FORMAT subcommand controls the characteristics of the
7654 crosstabulation tables to be displayed.  It has a number of possible
7655 settings:
7656
7657 @itemize @bullet
7658 @item
7659 TABLES, the default, causes crosstabulation tables to be output.
7660 NOTABLES suppresses them.
7661
7662 @item
7663 LABELS, the default, allows variable labels and value labels to appear
7664 in the output.  NOLABELS suppresses them.  NOVALLABS displays variable
7665 labels but suppresses value labels.
7666
7667 @item
7668 PIVOT, the default, causes each TABLES subcommand to be displayed in a
7669 pivot table format.  NOPIVOT causes the old-style crosstabulation format
7670 to be used.
7671
7672 @item
7673 AVALUE, the default, causes values to be sorted in ascending order.
7674 DVALUE asserts a descending sort order.
7675
7676 @item
7677 INDEX/NOINDEX is currently ignored.
7678
7679 @item
7680 BOX/NOBOX is currently ignored.
7681 @end itemize
7682
7683 The CELLS subcommand controls the contents of each cell in the displayed
7684 crosstabulation table.  The possible settings are:
7685
7686 @table @asis
7687 @item COUNT
7688 Frequency count.
7689 @item ROW
7690 Row percent.
7691 @item COLUMN
7692 Column percent.
7693 @item TOTAL
7694 Table percent.
7695 @item EXPECTED
7696 Expected value.
7697 @item RESIDUAL 
7698 Residual.
7699 @item SRESIDUAL
7700 Standardized residual.
7701 @item ASRESIDUAL
7702 Adjusted standardized residual.
7703 @item ALL
7704 All of the above.
7705 @item NONE
7706 Suppress cells entirely.
7707 @end table
7708
7709 @samp{/CELLS} without any settings specified requests COUNT, ROW,
7710 COLUMN, and TOTAL.  If CELLS is not specified at all then only COUNT
7711 will be selected.
7712
7713 The STATISTICS subcommand selects statistics for computation:
7714
7715 @table @asis
7716 @item CHISQ
7717 Pearson chi-square, likelihood ratio, Fisher's exact test, continuity
7718 correction, linear-by-linear association.
7719 @item PHI
7720 Phi.
7721 @item CC
7722 Contingency coefficient.
7723 @item LAMBDA
7724 Lambda.
7725 @item UC
7726 Uncertainty coefficient.
7727 @item BTAU
7728 Tau-b.
7729 @item CTAU
7730 Tau-c.
7731 @item RISK
7732 Risk estimate.
7733 @item GAMMA
7734 Gamma.
7735 @item D
7736 Somers' D.
7737 @item KAPPA
7738 Cohen's Kappa.
7739 @item ETA
7740 Eta.
7741 @item CORR
7742 Spearman correlation, Pearson's r.
7743 @item ALL
7744 All of the above.
7745 @item NONE
7746 No statistics.
7747 @end table
7748
7749 Selected statistics are only calculated when appropriate for the
7750 statistic.  Certain statistics require tables of a particular size, and
7751 some statistics are calculated only in integer mode.
7752
7753 @samp{/STATISTICS} without any settings selects CHISQ.  If the
7754 STATISTICS subcommand is not given, no statistics are calculated.
7755
7756 @strong{Please note:} Currently the implementation of CROSSTABS has the
7757 followings bugs:
7758
7759 @itemize @bullet
7760 @item
7761 Pearson's R (but not Spearman!) is off a little.
7762 @item
7763 T values for Spearman's R and Pearson's R are wrong.
7764 @item
7765 How to calculate significance of symmetric and directional measures?
7766 @item
7767 Asymmetric ASEs and T values for lambda are wrong.
7768 @item
7769 ASE of Goodman and Kruskal's tau is not calculated.
7770 @item
7771 ASE of symmetric somers' d is wrong.
7772 @item
7773 Approx. T of uncertainty coefficient is wrong.
7774 @end itemize
7775
7776 Fix for any of these deficiencies would be welcomed.
7777
7778 @node Utilities, Not Implemented, Statistics, Top
7779 @chapter Utilities
7780
7781 Commands that don't fit any other category are placed here.
7782
7783 Most of these commands are not affected by commands like IF and LOOP:
7784 they take effect only once, unconditionally, at the time that they are
7785 encountered in the input.
7786
7787 @menu
7788 * COMMENT::                     Document your syntax file.
7789 * DOCUMENT::                    Document the active file.
7790 * DISPLAY DOCUMENTS::           Display active file documents.
7791 * DISPLAY FILE LABEL::          Display the active file label.
7792 * DROP DOCUMENTS::              Remove documents from the active file.
7793 * EXECUTE::                     Execute pending transformations.
7794 * FILE LABEL::                  Set the active file's label.
7795 * INCLUDE::                     Include a file within the current one.
7796 * QUIT::                        Terminate the PSPP session.
7797 * SET::                         Adjust PSPP runtime parameters.
7798 * SUBTITLE::                    Provide a document subtitle.
7799 * SYSFILE INFO::                Display the dictionary in a system file.
7800 * TITLE::                       Provide a document title.
7801 @end menu
7802
7803 @node COMMENT, DOCUMENT, Utilities, Utilities
7804 @section COMMENT
7805 @vindex COMMENT
7806 @vindex *
7807
7808 @display 
7809 Two possibles syntaxes:
7810         COMMENT comment text @dots{} .
7811         *comment text @dots{} .
7812 @end display
7813
7814 The COMMENT command is ignored.  It is used to provide information to
7815 the author and other readers of the PSPP syntax file.  
7816
7817 A COMMENT command can extend over any number of lines.  Don't forget to
7818 terminate it with a dot or a blank line!
7819
7820 @node DOCUMENT, DISPLAY DOCUMENTS, COMMENT, Utilities
7821 @section DOCUMENT
7822 @vindex DOCUMENT
7823
7824 @display
7825 DOCUMENT documentary_text.
7826 @end display
7827
7828 The DOCUMENT command adds one or more lines of descriptive commentary to
7829 the active file.  Documents added in this way are saved to system files.
7830 They can be viewed using SYSFILE INFO or DISPLAY DOCUMENTS.  They can be
7831 removed from the active file with DROP DOCUMENTS.
7832
7833 Specify the documentary text following the DOCUMENT keyword.  You can
7834 extend the documentary text over as many lines as necessary.  Lines are
7835 truncated at 80 characters width.  Don't forget to terminate the
7836 DOCUMENT command with a dot or a blank line.
7837
7838 @node DISPLAY DOCUMENTS, DISPLAY FILE LABEL, DOCUMENT, Utilities
7839 @section DISPLAY DOCUMENTS
7840 @vindex DISPLAY DOCUMENTS
7841
7842 @display
7843 DISPLAY DOCUMENTS.
7844 @end display
7845
7846 DISPLAY DOCUMENTS displays the documents in the active file.  Each
7847 document is preceded by a line giving the time and date that it was
7848 added.  @xref{DOCUMENT}.
7849
7850 @node DISPLAY FILE LABEL, DROP DOCUMENTS, DISPLAY DOCUMENTS, Utilities
7851 @section DISPLAY FILE LABEL
7852 @vindex DISPLAY FILE LABEL
7853
7854 @display
7855 DISPLAY FILE LABEL.
7856 @end display
7857
7858 DISPLAY FILE LABEL displays the file label contained in the active file,
7859 if any.  @xref{FILE LABEL}.
7860
7861 @node DROP DOCUMENTS, EXECUTE, DISPLAY FILE LABEL, Utilities
7862 @section DROP DOCUMENTS
7863 @vindex DROP DOCUMENTS
7864
7865 @display
7866 DROP DOCUMENTS.
7867 @end display
7868
7869 The DROP DOCUMENTS command removes all documents from the active file.
7870 New documents can be added with the DOCUMENT utility (@pxref{DOCUMENT}).
7871
7872 DROP DOCUMENTS only changes the active file.  It does not modify any
7873 system files stored on disk.
7874
7875 @node EXECUTE, FILE LABEL, DROP DOCUMENTS, Utilities
7876 @section EXECUTE
7877 @vindex EXECUTE
7878
7879 @display
7880 EXECUTE.
7881 @end display
7882
7883 The EXECUTE utility causes the active file to be read and all pending
7884 transformations to be executed.
7885
7886 @node FILE LABEL, INCLUDE, EXECUTE, Utilities
7887 @section FILE LABEL
7888 @vindex FILE LABEL
7889
7890 @display
7891 FILE LABEL file_label.
7892 @end display
7893
7894 Use the FILE LABEL command to provide a title for the active file.  This
7895 title will be saved into system files and portable files that are
7896 created during this PSPP run.
7897
7898 It is not necessary to include quotes around file_label.  If they are
7899 included then they become part of the file label.
7900
7901 @node INCLUDE, QUIT, FILE LABEL, Utilities
7902 @section INCLUDE
7903 @vindex INCLUDE
7904 @vindex @@
7905
7906 @display
7907 Two possible syntaxes:
7908         INCLUDE 'filename'.
7909         @@filename.
7910 @end display
7911
7912 The INCLUDE command causes the PSPP command processor to read an
7913 additional command file as if it were included bodily in the current
7914 command file.
7915
7916 INCLUDE files may be nested to any depth, up to the limit of available
7917 memory.
7918
7919 @node QUIT, SET, INCLUDE, Utilities
7920 @section QUIT
7921 @vindex QUIT
7922
7923 @display
7924 Two possible syntaxes:
7925         QUIT.
7926         EXIT.
7927 @end display
7928
7929 The QUIT command terminates the current PSPP session and returns control
7930 to the operating system.  
7931
7932 This command is not valid within a command file.
7933
7934 @node SET, SUBTITLE, QUIT, Utilities
7935 @section SET
7936 @vindex SET
7937
7938 @display
7939 SET
7940
7941 (data input)
7942         /BLANKS=@{SYSMIS,'.',number@}
7943         /DECIMAL=@{DOT,COMMA@}
7944         /FORMAT=fmt_spec
7945
7946 (program input)
7947         /ENDCMD='.'
7948         /NULLINE=@{ON,OFF@}
7949
7950 (interaction)
7951         /CPROMPT='cprompt_string'
7952         /DPROMPT='dprompt_string'
7953         /ERRORBREAK=@{OFF,ON@}
7954         /MXERRS=max_errs
7955         /MXWARNS=max_warnings
7956         /PROMPT='prompt'
7957         /VIEWLENGTH=@{MINIMUM,MEDIAN,MAXIMUM,n_lines@}
7958         /VIEWWIDTH=n_characters
7959
7960 (program execution)
7961         /MEXPAND=@{ON,OFF@}
7962         /MITERATE=max_iterations
7963         /MNEST=max_nest
7964         /MPRINT=@{ON,OFF@}
7965         /MXLOOPS=max_loops
7966         /SEED=@{RANDOM,seed_value@}
7967         /UNDEFINED=@{WARN,NOWARN@}
7968
7969 (data output)
7970         /CC@{A,B,C,D,E@}=@{'npre,pre,suf,nsuf','npre.pre.suf.nsuf'@}
7971         /DECIMAL=@{DOT,COMMA@}
7972         /FORMAT=fmt_spec
7973
7974 (output routing)
7975         /ECHO=@{ON,OFF@}
7976         /ERRORS=@{ON,OFF,TERMINAL,LISTING,BOTH,NONE@}
7977         /INCLUDE=@{ON,OFF@}
7978         /MESSAGES=@{ON,OFF,TERMINAL,LISTING,BOTH,NONE@}
7979         /PRINTBACK=@{ON,OFF@}
7980         /RESULTS=@{ON,OFF,TERMINAL,LISTING,BOTH,NONE@}
7981
7982 (output activation)
7983         /LISTING=@{ON,OFF@}
7984         /PRINTER=@{ON,OFF@}
7985         /SCREEN=@{ON,OFF@}
7986
7987 (output driver options)
7988         /HEADERS=@{NO,YES,BLANK@}
7989         /LENGTH=@{NONE,length_in_lines@}
7990         /LISTING=filename
7991         /MORE=@{ON,OFF@}
7992         /PAGER=@{OFF,"pager_name"@}
7993         /WIDTH=@{NARROW,WIDTH,n_characters@}
7994
7995 (logging)
7996         /JOURNAL=@{ON,OFF@} [filename]
7997         /LOG=@{ON,OFF@} [filename]
7998
7999 (system files)
8000         /COMPRESSION=@{ON,OFF@}
8001         /SCOMPRESSION=@{ON,OFF@}
8002
8003 (security)
8004         /SAFER=ON
8005
8006 (obsolete settings accepted for compatibility, but ignored)
8007         /AUTOMENU=@{ON,OFF@}
8008         /BEEP=@{ON,OFF@}
8009         /BLOCK='c'
8010         /BOXSTRING=@{'xxx','xxxxxxxxxxx'@}
8011         /CASE=@{UPPER,UPLOW@}
8012         /COLOR=@dots{}
8013         /CPI=cpi_value
8014         /DISK=@{ON,OFF@}
8015         /EJECT=@{ON,OFF@}
8016         /HELPWINDOWS=@{ON,OFF@}
8017         /HIGHRES=@{ON,OFF@}
8018         /HISTOGRAM='c'
8019         /LOWRES=@{AUTO,ON,OFF@}
8020         /LPI=lpi_value
8021         /MENUS=@{STANDARD,EXTENDED@}
8022         /MXMEMORY=max_memory
8023         /PTRANSLATE=@{ON,OFF@}
8024         /RCOLORS=@dots{}
8025         /RUNREVIEW=@{AUTO,MANUAL@}
8026         /SCRIPTTAB='c'
8027         /TB1=@{'xxx','xxxxxxxxxxx'@}
8028         /TBFONTS='string'
8029         /WORKDEV=drive_letter
8030         /WORKSPACE=workspace_size
8031         /XSORT=@{YES,NO@}
8032 @end display
8033
8034 The SET command allows the user to adjust several parameters relating to
8035 PSPP's execution.  Since there are many subcommands to this command, its
8036 subcommands will be examined in groups.
8037
8038 As a general comment, ON and YES are considered synonymous, and
8039 so are OFF and NO, when used as subcommand values.
8040
8041 The data input subcommands affect the way that data is read from data
8042 files.  The data input subcommands are
8043
8044 @table @asis
8045 @item BLANKS
8046 This is the value assigned to an item data item that is empty or
8047 contains only whitespace.  An argument of SYSMIS or '.' will cause the
8048 system-missing value to be assigned to null items.  This is the
8049 default.  Any real value may be assigned.
8050
8051 @item DECIMAL
8052 The default DOT setting causes the decimal point character to be
8053 @samp{.}.  A setting of COMMA causes the decimal point character to be
8054 @samp{,}.
8055
8056 @item FORMAT
8057 Allows the default numeric input/output format to be specified.  The
8058 default is F8.2.  @xref{Input/Output Formats}.
8059 @end table
8060
8061 Program input subcommands affect the way that programs are parsed when
8062 they are typed interactively or run from a script.  They are
8063
8064 @table @asis
8065 @item ENDCMD
8066 This is a single character indicating the end of a command.  The default
8067 is @samp{.}.  Don't change this.
8068
8069 @item NULLINE
8070 Whether a blank line is interpreted as ending the current command.  The
8071 default is ON.
8072 @end table
8073
8074 Interaction subcommands affect the way that PSPP interacts with an
8075 online user.  The interaction subcommands are
8076
8077 @table @asis
8078 @item CPROMPT
8079 The command continuation prompt.  The default is @samp{    > }.
8080
8081 @item DPROMPT
8082 Prompt used when expecting data input within BEGIN DATA (@pxref{BEGIN
8083 DATA}).  The default is @samp{data> }.
8084
8085 @item ERRORBREAK
8086 Whether an error causes PSPP to stop processing the current command
8087 file after finishing the current command.  The default is OFF.
8088
8089 @item MXERRS
8090 The maximum number of errors before PSPP halts processing of the current
8091 command file.  The default is 50.
8092
8093 @item MXWARNS
8094 The maximum number of warnings + errors before PSPP halts processing the
8095 current command file.  The default is 100.
8096
8097 @item PROMPT
8098 The command prompt.  The default is @samp{PSPP> }.
8099
8100 @item VIEWLENGTH
8101 The length of the screen in lines.  MINIMUM means 25 lines, MEDIAN and
8102 MAXIMUM mean 43 lines.  Otherwise specify the number of lines.  Normally
8103 PSPP should auto-detect your screen size so this shouldn't have to be
8104 used.
8105
8106 @item VIEWWIDTH
8107 The width of the screen in characters.  Normally 80 or 132.
8108 @end table
8109
8110 Program execution subcommands control the way that PSPP commands
8111 execute.  The program execution subcommands are
8112
8113 @table @asis
8114 @item MEXPAND
8115 @itemx MITERATE
8116 @itemx MNEST
8117 @itemx MPRINT
8118 Currently not used.
8119
8120 @item MXLOOPS
8121 The maximum number of iterations for an uncontrolled loop.
8122
8123 @item SEED
8124 The initial pseudo-random number seed.  Set to a real number or to
8125 RANDOM, which will obtain an initial seed from the current time of day.
8126
8127 @item UNDEFINED
8128 Currently not used.
8129 @end table
8130
8131 Data output subcommands affect the format of output data.  These
8132 subcommands are
8133
8134 @table @asis
8135 @item CCA
8136 @itemx CCB
8137 @itemx CCC
8138 @itemx CCD
8139 @itemx CCE
8140 Set up custom currency formats.  The argument is a string which must
8141 contain exactly three commas or exactly three periods.  If commas, then
8142 the grouping character for the currency format is @samp{,}, and the
8143 decimal point character is @samp{.}; if periods, then the situation is
8144 reversed.  
8145
8146 The commas or periods divide the string into four fields, which are, in
8147 order, the negative prefix, prefix, suffix, and negative suffix.  When a
8148 value is formatted using the custom currency format, the prefix precedes
8149 the value formatted and the suffix follows it.  In addition, if the
8150 value is negative, the negative prefix precedes the prefix and the
8151 negative suffix follows the suffix.
8152
8153 @item DECIMAL
8154 The default DOT setting causes the decimal point character to be
8155 @samp{.}.  A setting of COMMA causes the decimal point character to be
8156 @samp{,}.
8157
8158 @item FORMAT
8159 Allows the default numeric input/output format to be specified.  The
8160 default is F8.2.  @xref{Input/Output Formats}.
8161 @end table
8162
8163 Output routing subcommands affect where the output of transformations
8164 and procedures is sent.  These subcommands are
8165
8166 @table @asis
8167 @item ECHO
8168
8169 If turned on, commands are written to the listing file as they are read
8170 from command files.  The default is OFF.
8171
8172 @itemx ERRORS
8173 @itemx INCLUDE
8174 @itemx MESSAGES
8175 @item PRINTBACK
8176 @item RESULTS
8177 Currently not used.
8178 @end table
8179
8180 Output activation subcommands affect whether output devices of
8181 particular types are enabled.  These subcommands are
8182
8183 @table @asis
8184 @item LISTING
8185 Enable or disable listing devices.
8186
8187 @item PRINTER
8188 Enable or disable printer devices.
8189
8190 @item SCREEN
8191 Enable or disable screen devices.
8192 @end table
8193
8194 Output driver option subcommands affect output drivers' settings.  These
8195 subcommands are
8196
8197 @table @asis
8198 @item HEADERS
8199 @itemx LENGTH
8200 @itemx LISTING
8201 @itemx MORE
8202 @itemx PAGER 
8203 @itemx WIDTH
8204 Currently not used.
8205 @end table
8206
8207 Logging subcommands affect logging of commands executed to external
8208 files.  These subcommands are
8209
8210 @table @asis
8211 @item JOURNAL
8212 @item LOG
8213 Not currently used.
8214 @end table
8215
8216 System file subcommands affect the default format of system files
8217 produced by PSPP.  These subcommands are
8218
8219 @table @asis
8220 @item COMPRESSION
8221 Not currently used.
8222
8223 @item SCOMPRESSION
8224 Whether system files created by SAVE or XSAVE are compressed by default.
8225 The default is ON.
8226 @end table
8227
8228 Security subcommands affect the operations that commands are allowed to
8229 perform.  The security subcommands are
8230
8231 @table @asis
8232 @item SAFER
8233 When set, this setting cannot ever be reset, for obvious security
8234 reasons.  Setting this option disables the following operations:
8235
8236 @itemize @bullet
8237 @item
8238 The ERASE command.
8239 @item
8240 The HOST command.
8241 @item
8242 Pipe filenames (filenames beginning or ending with @samp{|}).
8243 @item
8244 @end itemize
8245
8246 Be aware that this setting does not guarantee safety (commands can still
8247 overwrite files, for instance) but it is an improvement.
8248 @end table
8249
8250 @node SUBTITLE, TITLE, SET, Utilities
8251 @section SUBTITLE
8252 @vindex SUBTITLE
8253
8254 @display
8255 Two possible syntaxes:
8256         SUBTITLE 'subtitle_string'.
8257         SUBTITLE subtitle_string.
8258 @end display
8259
8260 The SUBTITLE command is used to provide a subtitle to a particular PSPP
8261 run.  This subtitle appears at the top of each output page below the
8262 title, if titles are enabled on the output device.
8263
8264 Specify a subtitle as a string in quotes.  The alternate syntax that did
8265 not require quotes is now obsolete.  If it is used then the subtitle is
8266 converted to all uppercase.
8267
8268 @node TITLE,  , SUBTITLE, Utilities
8269 @section TITLE
8270 @vindex TITLE
8271
8272 @display
8273 Two possible syntaxes:
8274         TITLE 'title_string'.
8275         TITLE title_string.
8276 @end display
8277
8278 The TITLE command is used to provide a title to a particular PSPP run.
8279 This title appears at the top of each output page, if titles are enabled
8280 on the output device.
8281
8282 Specify a title as a string in quotes.  The alternate syntax that did
8283 not require quotes is now obsolete.  If it is used then the title is
8284 converted to all uppercase.
8285
8286 @node Not Implemented, Data File Format, Utilities, Top
8287 @chapter Not Implemented
8288
8289 This chapter lists parts of the PSPP language that are not yet
8290 implemented.
8291
8292 The following transformations and utilities are not yet implemented, but
8293 they will be supported in a later release.
8294
8295 @itemize @bullet
8296 @item
8297 ADD FILES
8298 @item
8299 DEFINE
8300 @item
8301 FILE TYPE
8302 @item
8303 GET SAS
8304 @item
8305 GET TRANSLATE
8306 @item
8307 MCONVERT
8308 @item
8309 PRESERVE
8310 @item
8311 PROCEDURE OUTPUT
8312 @item
8313 RESTORE
8314 @item
8315 SAVE TRANSLATE
8316 @item
8317 SHOW
8318 @item
8319 UPDATE
8320 @end itemize
8321
8322 The following transformations and utilities are not implemented.  There
8323 are no plans to support them in future releases.  Contributions to
8324 implement them will still be accepted.
8325
8326 @itemize @bullet
8327 @item
8328 EDIT
8329 @item
8330 GET DATABASE
8331 @item
8332 GET OSIRIS
8333 @item
8334 GET SCSS
8335 @item
8336 GSET
8337 @item
8338 HELP
8339 @item
8340 INFO
8341 @item
8342 INPUT MATRIX
8343 @item
8344 KEYED DATA LIST
8345 @item
8346 NUMBERED and UNNUMBERED
8347 @item
8348 OPTIONS
8349 @item
8350 REVIEW
8351 @item
8352 SAVE SCSS
8353 @item
8354 SPSS MANAGER
8355 @item
8356 STATISTICS
8357 @end itemize
8358
8359 @node Data File Format, Portable File Format, Not Implemented, Top
8360 @chapter Data File Format
8361
8362 PSPP necessarily uses the same format for system files as do the
8363 products with which it is compatible.  This chapter is a description of
8364 that format.
8365
8366 There are three data types used in system files: 32-bit integers, 64-bit
8367 floating points, and 1-byte characters.  In this document these will
8368 simply be referred to as @code{int32}, @code{flt64}, and @code{char},
8369 the names that are used in the PSPP source code.  Every field of type
8370 @code{int32} or @code{flt64} is aligned on a 32-bit boundary.
8371
8372 The endianness of data in PSPP system files is not specified.  System
8373 files output on a computer of a particular endianness will have the
8374 endianness of that computer.  However, PSPP can read files of either
8375 endianness, regardless of its host computer's endianness.  PSPP
8376 translates endianness for both integer and floating point numbers.
8377
8378 Floating point formats are also not specified.  PSPP does not
8379 translate between floating point formats.  This is unlikely to be a
8380 problem as all modern computer architectures use IEEE 754 format for
8381 floating point representation.
8382
8383 The PSPP system-missing value is represented by the largest possible
8384 negative number in the floating point format; in C, this is most likely
8385 @code{-DBL_MAX}.  There are two other important values used in missing
8386 values: @code{HIGHEST} and @code{LOWEST}.  These are represented by the
8387 largest possible positive number (probably @code{DBL_MAX}) and the
8388 second-largest negative number.  The latter must be determined in a
8389 system-dependent manner; in IEEE 754 format it is represented by value
8390 @code{0xffeffffffffffffe}.
8391
8392 System files are divided into records.  Each record begins with an
8393 @code{int32} giving a numeric record type.  Individual record types are
8394 described below:
8395
8396 @menu
8397 * File Header Record::          
8398 * Variable Record::             
8399 * Value Label Record::          
8400 * Value Label Variable Record::  
8401 * Document Record::             
8402 * Machine int32 Info Record::   
8403 * Machine flt64 Info Record::   
8404 * Miscellaneous Informational Records::  
8405 * Dictionary Termination Record::  
8406 * Data Record::                 
8407 @end menu
8408
8409 @node File Header Record, Variable Record, Data File Format, Data File Format
8410 @section File Header Record
8411
8412 The file header is always the first record in the file.
8413
8414 @example
8415 struct sysfile_header
8416   @{
8417     char                rec_type[4];
8418     char                prod_name[60];
8419     int32               layout_code;
8420     int32               case_size;
8421     int32               compressed;
8422     int32               weight_index;
8423     int32               ncases;
8424     flt64               bias;
8425     char                creation_date[9];
8426     char                creation_time[8];
8427     char                file_label[64];
8428     char                padding[3];
8429   @};
8430 @end example
8431
8432 @table @code
8433 @item char rec_type[4];
8434 Record type code.  Always set to @samp{$FL2}.  This is the only record
8435 for which the record type is not of type @code{int32}.
8436
8437 @item char prod_name[60];
8438 Product identification string.  This always begins with the characters
8439 @samp{@@(#) SPSS DATA FILE}.  PSPP uses the remaining characters to
8440 give its version and the operating system name; for example, @samp{GNU
8441 pspp 0.1.4 - sparc-sun-solaris2.5.2}.  The string is truncated if it
8442 would be longer than 60 characters; otherwise it is padded on the right
8443 with spaces.
8444
8445 @item int32 layout_code;
8446 Always set to 2.  PSPP reads this value in order to determine the
8447 file's endianness.
8448
8449 @item int32 case_size;
8450 Number of data elements per case.  This is the number of variables,
8451 except that long string variables add extra data elements (one for every
8452 8 characters after the first 8).
8453
8454 @item int32 compressed;
8455 Set to 1 if the data in the file is compressed, 0 otherwise.
8456
8457 @item int32 weight_index;
8458 If one of the variables in the data set is used as a weighting variable,
8459 set to the index of that variable.  Otherwise, set to 0.
8460
8461 @item int32 ncases;
8462 Set to the number of cases in the file if it is known, or -1 otherwise.
8463
8464 In the general case it is not possible to determine the number of cases
8465 that will be output to a system file at the time that the header is
8466 written.  The way that this is dealt with is by writing the entire
8467 system file, including the header, then seeking back to the beginning of
8468 the file and writing just the @code{ncases} field.  For `files' in which
8469 this is not valid, the seek operation fails.  In this case,
8470 @code{ncases} remains -1.
8471
8472 @item flt64 bias;
8473 Compression bias.  Always set to 100.  The significance of this value is
8474 that only numbers between @code{(1 - bias)} and @code{(251 - bias)} can
8475 be compressed.
8476
8477 @item char creation_date[9];
8478 Set to the date of creation of the system file, in @samp{dd mmm yy}
8479 format, with the month as standard English abbreviations, using an
8480 initial capital letter and following with lowercase.  If the date is not
8481 available then this field is arbitrarily set to @samp{01 Jan 70}.
8482
8483 @item char creation_time[8];
8484 Set to the time of creation of the system file, in @samp{hh:mm:ss}
8485 format and using 24-hour time.  If the time is not available then this
8486 field is arbitrarily set to @samp{00:00:00}.
8487
8488 @item char file_label[64];
8489 Set the the file label declared by the user, if any.  Padded on the
8490 right with spaces.
8491
8492 @item char padding[3];
8493 Ignored padding bytes to make the structure a multiple of 32 bits in
8494 length.  Set to zeros.
8495 @end table
8496
8497 @node Variable Record, Value Label Record, File Header Record, Data File Format
8498 @section Variable Record
8499
8500 Immediately following the header must come the variable records.  There
8501 must be one variable record for every variable and every 8 characters in
8502 a long string beyond the first 8; i.e., there must be exactly as many
8503 variable records as the value specified for @code{case_size} in the file
8504 header record.
8505
8506 @example
8507 struct sysfile_variable
8508   @{
8509     int32               rec_type;
8510     int32               type;
8511     int32               has_var_label;
8512     int32               n_missing_values;
8513     int32               print;
8514     int32               write;
8515     char                name[8];
8516
8517     /* The following two fields are present 
8518        only if has_var_label is 1. */
8519     int32               label_len;
8520     char                label[/* variable length */];
8521
8522     /* The following field is present only
8523        if n_missing_values is not 0. */
8524     flt64               missing_values[/* variable length*/];
8525   @};
8526 @end example
8527
8528 @table @code
8529 @item int32 rec_type;
8530 Record type code.  Always set to 2.
8531
8532 @item int32 type;
8533 Variable type code.  Set to 0 for a numeric variable.  For a short
8534 string variable or the first part of a long string variable, this is set
8535 to the width of the string.  For the second and subsequent parts of a
8536 long string variable, set to -1, and the remaining fields in the
8537 structure are ignored.
8538
8539 @item int32 has_var_label;
8540 If this variable has a variable label, set to 1; otherwise, set to 0.
8541
8542 @item int32 n_missing_values;
8543 If the variable has no missing values, set to 0.  If the variable has
8544 one, two, or three discrete missing values, set to 1, 2, or 3,
8545 respectively.  If the variable has a range for missing variables, set to
8546 -2; if the variable has a range for missing variables plus a single
8547 discrete value, set to -3.
8548
8549 @item int32 print;
8550 Print format for this variable.  See below.
8551
8552 @item int32 write;
8553 Write format for this variable.  See below.
8554
8555 @item char name[8];
8556 Variable name.  The variable name must begin with a capital letter or
8557 the at-sign (@samp{@@}).  Subsequent characters may also be octothorpes
8558 (@samp{#}), dollar signs (@samp{$}), underscores (@samp{_}), or full
8559 stops (@samp{.}).  The variable name is padded on the right with spaces.
8560
8561 @item int32 label_len;
8562 This field is present only if @code{has_var_label} is set to 1.  It is
8563 set to the length, in characters, of the variable label, which must be a
8564 number between 0 and 120.
8565
8566 @item char label[/* variable length */];
8567 This field is present only if @code{has_var_label} is set to 1.  It has
8568 length @code{label_len}, rounded up to the nearest multiple of 32 bits.
8569 The first @code{label_len} characters are the variable's variable label.
8570
8571 @item flt64 missing_values[/* variable length */];
8572 This field is present only if @code{n_missing_values} is not 0.  It has
8573 the same number of elements as the absolute value of
8574 @code{n_missing_values}.  For discrete missing values, each element
8575 represents one missing value.  When a range is present, the first
8576 element denotes the minimum value in the range, and the second element
8577 denotes the maximum value in the range.  When a range plus a value are
8578 present, the third element denotes the additional discrete missing
8579 value.  HIGHEST and LOWEST are indicated as described in the chapter
8580 introduction.
8581 @end table
8582
8583 The @code{print} and @code{write} members of sysfile_variable are output
8584 formats coded into @code{int32} types.  The LSB (least-significant byte)
8585 of the @code{int32} represents the number of decimal places, and the
8586 next two bytes in order of increasing significance represent field width
8587 and format type, respectively.  The MSB (most-significant byte) is not
8588 used and should be set to zero.
8589
8590 Format types are defined as follows:
8591 @table @asis
8592 @item 0
8593 Not used.
8594 @item 1
8595 @code{A}
8596 @item 2
8597 @code{AHEX}
8598 @item 3
8599 @code{COMMA}
8600 @item 4
8601 @code{DOLLAR}
8602 @item 5
8603 @code{F}
8604 @item 6
8605 @code{IB}
8606 @item 7
8607 @code{PIBHEX}
8608 @item 8
8609 @code{P}
8610 @item 9
8611 @code{PIB}
8612 @item 10
8613 @code{PK}
8614 @item 11
8615 @code{RB}
8616 @item 12
8617 @code{RBHEX}
8618 @item 13
8619 Not used.
8620 @item 14
8621 Not used.
8622 @item 15
8623 @code{Z}
8624 @item 16
8625 @code{N}
8626 @item 17
8627 @code{E}
8628 @item 18
8629 Not used.
8630 @item 19
8631 Not used.
8632 @item 20
8633 @code{DATE}
8634 @item 21
8635 @code{TIME}
8636 @item 22
8637 @code{DATETIME}
8638 @item 23
8639 @code{ADATE}
8640 @item 24
8641 @code{JDATE}
8642 @item 25
8643 @code{DTIME}
8644 @item 26
8645 @code{WKDAY}
8646 @item 27
8647 @code{MONTH}
8648 @item 28
8649 @code{MOYR}
8650 @item 29
8651 @code{QYR}
8652 @item 30
8653 @code{WKYR}
8654 @item 31
8655 @code{PCT}
8656 @item 32
8657 @code{DOT}
8658 @item 33
8659 @code{CCA}
8660 @item 34
8661 @code{CCB}
8662 @item 35
8663 @code{CCC}
8664 @item 36
8665 @code{CCD}
8666 @item 37
8667 @code{CCE}
8668 @item 38
8669 @code{EDATE}
8670 @item 39
8671 @code{SDATE}
8672 @end table
8673
8674 @node Value Label Record, Value Label Variable Record, Variable Record, Data File Format
8675 @section Value Label Record
8676
8677 Value label records must follow the variable records and must precede
8678 the header termination record.  Other than this, they may appear
8679 anywhere in the system file.  Every value label record must be
8680 immediately followed by a label variable record, described below.
8681
8682 Value label records begin with @code{rec_type}, an @code{int32} value
8683 set to the record type of 3.  This is followed by @code{count}, an
8684 @code{int32} value set to the number of value labels present in this
8685 record.
8686
8687 These two fields are followed by a series of @code{count} tuples.  Each
8688 tuple is divided into two fields, the value and the label.  The first of
8689 these, the value, is composed of a 64-bit value, which is either a
8690 @code{flt64} value or up to 8 characters (padded on the right to 8
8691 bytes) denoting a short string value.  Whether the value is a
8692 @code{flt64} or a character string is not defined inside the value label
8693 record.
8694
8695 The second field in the tuple, the label, has variable length.  The
8696 first @code{char} is a count of the number of characters in the value
8697 label.  The remainder of the field is the label itself.  The field is
8698 padded on the right to a multiple of 64 bits in length.
8699
8700 @node Value Label Variable Record, Document Record, Value Label Record, Data File Format
8701 @section Value Label Variable Record
8702
8703 Every value label variable record must be immediately preceded by a
8704 value label record, described above.
8705
8706 @example
8707 struct sysfile_value_label_variable
8708   @{
8709      int32              rec_type;
8710      int32              count;
8711      int32              vars[/* variable length */];
8712   @};
8713 @end example
8714
8715 @table @code
8716 @item int32 rec_type;
8717 Record type.  Always set to 4.
8718
8719 @item int32 count;
8720 Number of variables that the associated value labels from the value
8721 label record are to be applied.
8722
8723 @item int32 vars[/* variable length];
8724 A list of variables to which to apply the value labels.  There are
8725 @code{count} elements.
8726 @end table
8727
8728 @node Document Record, Machine int32 Info Record, Value Label Variable Record, Data File Format
8729 @section Document Record
8730
8731 There must be no more than one document record per system file.
8732 Document records must follow the variable records and precede the
8733 dictionary termination record.
8734
8735 @example
8736 struct sysfile_document
8737   @{
8738     int32               rec_type;
8739     int32               n_lines;
8740     char                lines[/* variable length */][80];
8741   @};
8742 @end example
8743
8744 @table @code
8745 @item int32 rec_type;
8746 Record type.  Always set to 6.
8747
8748 @item int32 n_lines;
8749 Number of lines of documents present.
8750
8751 @item char lines[/* variable length */][80];
8752 Document lines.  The number of elements is defined by @code{n_lines}.
8753 Lines shorter than 80 characters are padded on the right with spaces.
8754 @end table
8755
8756 @node Machine int32 Info Record, Machine flt64 Info Record, Document Record, Data File Format
8757 @section Machine @code{int32} Info Record
8758
8759 There must be no more than one machine @code{int32} info record per
8760 system file.  Machine @code{int32} info records must follow the variable
8761 records and precede the dictionary termination record.
8762
8763 @example
8764 struct sysfile_machine_int32_info
8765   @{
8766     /* Header. */
8767     int32               rec_type;
8768     int32               subtype;
8769     int32               size;
8770     int32               count;
8771
8772     /* Data. */
8773     int32               version_major;
8774     int32               version_minor;
8775     int32               version_revision;
8776     int32               machine_code;
8777     int32               floating_point_rep;
8778     int32               compression_code;
8779     int32               endianness;
8780     int32               character_code;
8781   @};
8782 @end example
8783
8784 @table @code
8785 @item int32 rec_type;
8786 Record type.  Always set to 7.
8787
8788 @item int32 subtype;
8789 Record subtype.  Always set to 3.
8790
8791 @item int32 size;
8792 Size of each piece of data in the data part, in bytes.  Always set to 4.
8793
8794 @item int32 count;
8795 Number of pieces of data in the data part.  Always set to 8.
8796
8797 @item int32 version_major;
8798 PSPP major version number.  In version @var{x}.@var{y}.@var{z}, this
8799 is @var{x}.
8800
8801 @item int32 version_minor;
8802 PSPP minor version number.  In version @var{x}.@var{y}.@var{z}, this
8803 is @var{y}.
8804
8805 @item int32 version_revision;
8806 PSPP version revision number.  In version @var{x}.@var{y}.@var{z},
8807 this is @var{z}.
8808
8809 @item int32 machine_code;
8810 Machine code.  PSPP always set this field to value to -1, but other
8811 values may appear.
8812
8813 @item int32 floating_point_rep;
8814 Floating point representation code.  For IEEE 754 systems this is 1.
8815 IBM 370 sets this to 2, and DEC VAX E to 3.
8816
8817 @item int32 compression_code;
8818 Compression code.  Always set to 1.
8819
8820 @item int32 endianness;
8821 Machine endianness.  1 indicates big-endian, 2 indicates little-endian.
8822
8823 @item int32 character_code;
8824 Character code.  1 indicates EBCDIC, 2 indicates 7-bit ASCII, 3
8825 indicates 8-bit ASCII, 4 indicates DEC Kanji.
8826 @end table
8827
8828 @node Machine flt64 Info Record, Miscellaneous Informational Records, Machine int32 Info Record, Data File Format
8829 @section Machine @code{flt64} Info Record
8830
8831 There must be no more than one machine @code{flt64} info record per
8832 system file.  Machine @code{flt64} info records must follow the variable
8833 records and precede the dictionary termination record.
8834
8835 @example
8836 struct sysfile_machine_flt64_info
8837   @{
8838     /* Header. */
8839     int32               rec_type;
8840     int32               subtype;
8841     int32               size;
8842     int32               count;
8843
8844     /* Data. */
8845     flt64               sysmis;
8846     flt64               highest;
8847     flt64               lowest;
8848   @};
8849 @end example
8850
8851 @table @code
8852 @item int32 rec_type;
8853 Record type.  Always set to 3.
8854
8855 @item int32 subtype;
8856 Record subtype.  Always set to 4.
8857
8858 @item int32 size;
8859 Size of each piece of data in the data part, in bytes.  Always set to 4.
8860
8861 @item int32 count;
8862 Number of pieces of data in the data part.  Always set to 3.
8863
8864 @item flt64 sysmis;
8865 The system missing value.
8866
8867 @item flt64 highest;
8868 The value used for HIGHEST in missing values.
8869
8870 @item flt64 lowest;
8871 The value used for LOWEST in missing values.
8872 @end table
8873
8874 @node Miscellaneous Informational Records, Dictionary Termination Record, Machine flt64 Info Record, Data File Format
8875 @section Miscellaneous Informational Records
8876
8877 Miscellaneous informational records must follow the variable records and
8878 precede the dictionary termination record.
8879
8880 Miscellaneous informational records are ignored by PSPP when reading
8881 system files.  They are not written by PSPP when writing system files.
8882
8883 @example
8884 struct sysfile_misc_info
8885   @{
8886     /* Header. */
8887     int32               rec_type;
8888     int32               subtype;
8889     int32               size;
8890     int32               count;
8891
8892     /* Data. */
8893     char                data[/* variable length */];
8894   @};
8895 @end example
8896
8897 @table @code
8898 @item int32 rec_type;
8899 Record type.  Always set to 3.
8900
8901 @item int32 subtype;
8902 Record subtype.  May take any value.
8903
8904 @item int32 size;
8905 Size of each piece of data in the data part.  Should have the value 4 or
8906 8, for @code{int32} and @code{flt64}, respectively.
8907
8908 @item int32 count;
8909 Number of pieces of data in the data part.
8910
8911 @item char data[/* variable length */];
8912 Arbitrary data.  There must be @code{size} times @code{count} bytes of
8913 data.
8914 @end table
8915
8916 @node Dictionary Termination Record, Data Record, Miscellaneous Informational Records, Data File Format
8917 @section Dictionary Termination Record
8918
8919 The dictionary termination record must follow all other records, except
8920 for the actual cases, which it must precede.  There must be exactly one
8921 dictionary termination record in every system file.
8922
8923 @example
8924 struct sysfile_dict_term
8925   @{
8926     int32               rec_type;
8927     int32               filler;
8928   @};
8929 @end example
8930
8931 @table @code
8932 @item int32 rec_type;
8933 Record type.  Always set to 999.
8934
8935 @item int32 filler;
8936 Ignored padding.  Should be set to 0.
8937 @end table
8938
8939 @node Data Record,  , Dictionary Termination Record, Data File Format
8940 @section Data Record
8941
8942 Data records must follow all other records in the data file.  There must
8943 be at least one data record in every system file.
8944
8945 The format of data records varies depending on whether the data is
8946 compressed.  Regardless, the data is arranged in a series of 8-byte
8947 elements.
8948
8949 When data is not compressed, Every case is composed of @code{case_size}
8950 of these 8-byte elements, where @code{case_size} comes from the file
8951 header record (@pxref{File Header Record}).  Each element corresponds to
8952 the variable declared in the respective variable record (@pxref{Variable
8953 Record}).  Numeric values are given in @code{flt64} format; string
8954 values are literal characters string, padded on the right when
8955 necessary.
8956
8957 Compressed data is arranged in the following manner: the first 8-byte
8958 element in the data section is divided into a series of 1-byte command
8959 codes.  These codes have meanings as described below:
8960
8961 @table @asis
8962 @item 0
8963 Ignored.  If the program writing the system file accumulates compressed
8964 data in blocks of fixed length, 0 bytes can be used to pad out extra
8965 bytes remaining at the end of a fixed-size block.
8966
8967 @item 1 through 251
8968 These values indicate that the corresponding numeric variable has the
8969 value @code{(@var{code} - @var{bias})} for the case being read, where
8970 @var{code} is the value of the compression code and @var{bias} is the
8971 variable @code{compression_bias} from the file header.  For example,
8972 code 105 with bias 100.0 (the normal value) indicates a numeric variable
8973 of value 5.
8974
8975 @item 252
8976 End of file.  This code may or may not appear at the end of the data
8977 stream.  PSPP always outputs this code but its use is not required.
8978
8979 @item 253
8980 This value indicates that the numeric or string value is not
8981 compressible.  The value is stored in the 8-byte element following the
8982 current block of command bytes.  If this value appears twice in a block
8983 of command bytes, then it indicates the second element following the
8984 command bytes, and so on.
8985
8986 @item 254
8987 Used to indicate a string value that is all spaces.
8988
8989 @item 255
8990 Used to indicate the system-missing value.
8991 @end table
8992
8993 When the end of the first 8-byte element of command bytes is reached,
8994 any blocks of non-compressible values are skipped, and the next element
8995 of command bytes is read and interpreted, until the end of the file is
8996 reached.
8997
8998 @node Portable File Format, q2c Input Format, Data File Format, Top
8999 @chapter Portable File Format
9000
9001 These days, most computers use the same internal data formats for
9002 integer and floating-point data, if one ignores little differences like
9003 big- versus little-endian byte ordering.  However, occasionally it is
9004 necessary to exchange data between systems with incompatible data
9005 formats.  This is what portable files are designed to do.
9006
9007 @strong{Please note:} Although all of the following information is
9008 correct, as far as the author has been able to ascertain, it is gleaned
9009 from examination of ASCII-formatted portable files only, so some of it
9010 may be incorrect in the general case.
9011
9012 @menu
9013 * Portable File Characters::    
9014 * Portable File Structure::     
9015 * Portable File Header::        
9016 * Version and Date Info Record::  
9017 * Identification Records::      
9018 * Variable Count Record::       
9019 * Variable Records::            
9020 * Value Label Records::         
9021 * Portable File Data::          
9022 @end menu
9023
9024 @node Portable File Characters, Portable File Structure, Portable File Format, Portable File Format
9025 @section Portable File Characters
9026
9027 Portable files are arranged as a series of lines of exactly 80
9028 characters each.  Each line is terminated by a carriage-return,
9029 line-feed sequence (henceforth, ``newline'').  Newlines are not
9030 delimiters: they are only used to avoid line-length limitations existing
9031 on some operating systems.
9032
9033 The file must be terminated with a @samp{Z} character.  In addition, if
9034 the final line in the file does not have exactly 80 characters, then it
9035 is padded on the right with @samp{Z} characters.  (The file contents may
9036 be in any character set; the file contains a description of its own
9037 character set, as explained in the next section.  Therefore, the
9038 @samp{Z} character is not necessarily an ASCII @samp{Z}.)
9039
9040 For the rest of the description of the portable file format, newlines
9041 and the trailing @samp{Z}s will be ignored, as if they did not exist,
9042 because they are not an important part of understanding the file
9043 contents.
9044
9045 @node Portable File Structure, Portable File Header, Portable File Characters, Portable File Format
9046 @section Portable File Structure
9047
9048 Every portable file consists of the following records, in sequence:
9049
9050 @itemize @bullet
9051
9052 @item
9053 File header.
9054
9055 @item
9056 Version and date info.
9057
9058 @item
9059 Product identification.
9060
9061 @item
9062 Subproduct identification (optional).
9063
9064 @item
9065 Variable count.
9066
9067 @item
9068 Variables.  Each variable record may optionally be followed by a
9069 missing value record and a variable label record.
9070
9071 @item
9072 Value labels (optional).
9073
9074 @item
9075 Data.
9076 @end itemize
9077
9078 Most records are identified by a single-character tag code.  The file
9079 header and version info record do not have a tag.
9080
9081 Other than these single-character codes, there are three types of fields
9082 in a portable file: floating-point, integer, and string.  Floating-point
9083 fields have the following format:
9084
9085 @itemize @bullet
9086
9087 @item
9088 Zero or more leading spaces.
9089
9090 @item
9091 Optional asterisk (@samp{*}), which indicates a missing value.  The
9092 asterisk must be followed by a single character, generally a period
9093 (@samp{.}), but it appears that other characters may also be possible.
9094 This completes the specification of a missing value.
9095
9096 @item
9097 Optional minus sign (@samp{-}) to indicate a negative number.
9098
9099 @item
9100 A whole number, consisting of one or more base-30 digits: @samp{0}
9101 through @samp{9} plus capital letters @samp{A} through @samp{T}.
9102
9103 @item
9104 A fraction, consisting of a radix point (@samp{.}) followed by one or
9105 more base-30 digits (optional).
9106
9107 @item
9108 An exponent, consisting of a plus or minus sign (@samp{+} or @samp{-})
9109 followed by one or more base-30 digits (optional).
9110
9111 @item
9112 A forward slash (@samp{/}).
9113 @end itemize
9114
9115 Integer fields take form identical to floating-point fields, but they
9116 may not contain a fraction.
9117
9118 String fields take the form of a integer field having value @var{n},
9119 followed by exactly @var{n} characters, which are the string content.
9120
9121 @node Portable File Header, Version and Date Info Record, Portable File Structure, Portable File Format
9122 @section Portable File Header
9123
9124 Every portable file begins with a 464-byte header, consisting of a
9125 200-byte collection of vanity splash strings, followed by a 256-byte
9126 character set translation table, followed by an 8-byte tag string.
9127
9128 The 200-byte segment is divided into five 40-byte sections, each of
9129 which represents the string @code{ASCII SPSS PORT FILE} in a different
9130 character set encoding.  (If the file is encoded in EBCDIC then the
9131 string is actually @code{EBCDIC SPSS PORT FILE}, and so on.)  These
9132 strings are padded on the right with spaces in their own character set.
9133
9134 It appears that these strings exist only to inform those who might view
9135 the file on a screen, and that they are not parsed by SPSS products.
9136 Thus, they can be safely ignored.  For those interested, the strings are
9137 supposed to be in the following character sets, in the specified order:
9138 EBCDIC, 7-bit ASCII, CDC 6-bit ASCII, 6-bit ASCII, Honeywell 6-bit
9139 ASCII.
9140
9141 The 256-byte segment describes a mapping from the character set used in
9142 the portable file to an arbitrary character set having characters at the
9143 following positions:
9144
9145 @table @asis
9146 @item 0--60
9147
9148 Control characters.  Not important enough to describe in full here.
9149
9150 @item 61--63
9151
9152 Reserved.
9153
9154 @item 64--73
9155
9156 Digits @samp{0} through @samp{9}.
9157
9158 @item 74--99
9159
9160 Capital letters @samp{A} through @samp{Z}. 
9161
9162 @item 100--125
9163
9164 Lowercase letters @samp{a} through @samp{z}.
9165
9166 @item 126
9167
9168 Space.
9169
9170 @item 127--130
9171
9172 Symbols @code{.<(+}
9173
9174 @item 131
9175
9176 Solid vertical pipe.
9177
9178 @item 132--142
9179
9180 Symbols @code{&[]!$*);^-/}
9181
9182 @item 143
9183
9184 Broken vertical pipe.
9185
9186 @item 144--150
9187
9188 Symbols @code{,%_>}?@code{`:}   @c @code{?} is an inverted question mark
9189
9190 @item 151
9191
9192 British pound symbol.
9193
9194 @item 152--155
9195
9196 Symbols @code{@@'="}.
9197
9198 @item 156
9199
9200 Less than or equal symbol.
9201
9202 @item 157
9203
9204 Empty box.
9205
9206 @item 158
9207
9208 Plus or minus.
9209
9210 @item 159
9211
9212 Filled box.
9213
9214 @item 160
9215
9216 Degree symbol.
9217
9218 @item 161
9219
9220 Dagger.
9221
9222 @item 162
9223
9224 Symbol @samp{~}.
9225
9226 @item 163
9227
9228 En dash.
9229
9230 @item 164
9231
9232 Lower left corner box draw.
9233
9234 @item 165
9235
9236 Upper left corner box draw.
9237
9238 @item 166
9239
9240 Greater than or equal symbol.
9241
9242 @item 167--176
9243
9244 Superscript @samp{0} through @samp{9}.
9245
9246 @item 177
9247
9248 Lower right corner box draw.
9249
9250 @item 178
9251
9252 Upper right corner box draw.
9253
9254 @item 179
9255
9256 Not equal symbol.
9257
9258 @item 180
9259
9260 Em dash.
9261
9262 @item 181
9263
9264 Superscript @samp{(}.
9265
9266 @item 182
9267
9268 Superscript @samp{)}.
9269
9270 @item 183
9271
9272 Horizontal dagger (?).
9273
9274 @item 184--186
9275
9276 Symbols @samp{@{@}\}.
9277 @item 187
9278
9279 Cents symbol.
9280
9281 @item 188
9282
9283 Centered dot, or bullet.
9284
9285 @item 189--255
9286
9287 Reserved.
9288 @end table
9289
9290 Symbols that are not defined in a particular character set are set to
9291 the same value as symbol 64; i.e., to @samp{0}.
9292
9293 The 8-byte tag string consists of the exact characters @code{SPSSPORT}
9294 in the portable file's character set, which can be used to verify that
9295 the file is indeed a portable file.
9296
9297 @node Version and Date Info Record, Identification Records, Portable File Header, Portable File Format
9298 @section Version and Date Info Record
9299
9300 This record does not have a tag code.  It has the following structure:
9301
9302 @itemize @bullet
9303 @item
9304 A single character identifying the file format version.  The letter A
9305 represents version 0, and so on.
9306
9307 @item
9308 An 8-character string field giving the file creation date in the format
9309 YYYYMMDD.
9310
9311 @item
9312 A 6-character string field giving the file creation time in the format
9313 HHMMSS.
9314 @end itemize
9315
9316 @node Identification Records, Variable Count Record, Version and Date Info Record, Portable File Format
9317 @section Identification Records
9318
9319 The product identification record has tag code @samp{1}.  It consists of
9320 a single string field giving the name of the product that wrote the
9321 portable file.
9322
9323 The subproduct identification record has tag code @samp{3}.  It
9324 consists of a single string field giving additional information on the
9325 product that wrote the portable file.
9326
9327 @node Variable Count Record, Variable Records, Identification Records, Portable File Format
9328 @section Variable Count Record
9329
9330 The variable count record has tag code @samp{4}.  It consists of two
9331 integer fields.  The first contains the number of variables in the file
9332 dictionary.  The purpose of the second is unknown; it contains the value
9333 161 in all portable files examined so far.
9334
9335 @node Variable Records, Value Label Records, Variable Count Record, Portable File Format
9336 @section Variable Records
9337
9338 Each variable record represents a single variable.  Variable records
9339 have tag code @samp{7}.  They have the following structure:
9340
9341 @itemize @bullet
9342
9343 @item
9344 Width (integer).  This is 0 for a numeric variable, and a number between 1
9345 and 255 for a string variable.
9346
9347 @item
9348 Name (string).  1--8 characters long.  Must be in all capitals.
9349
9350 @item
9351 Print format.  This is a set of three integer fields:
9352
9353 @itemize @minus
9354
9355 @item
9356 Format type (@pxref{Variable Record}).
9357
9358 @item
9359 Format width.  1--40.
9360
9361 @item
9362 Number of decimal places.  1--40.
9363 @end itemize
9364
9365 @item
9366 Write format.  Same structure as the print format described above.
9367 @end itemize
9368
9369 Each variable record can optionally be followed by a missing value
9370 record, which has tag code @samp{8}.  A missing value record has one
9371 field, the missing value itself (a floating-point or string, as
9372 appropriate).  Up to three of these missing value records can be used.
9373
9374 There is also a record for missing value ranges, which has tag code
9375 @samp{B}.  It is followed by two fields representing the range, which
9376 are floating-point or string as appropriate.  If a missing value range
9377 is present, it may be followed by a single missing value record.
9378
9379 Tag codes @samp{9} and @samp{A} represent @code{LO THRU @var{x}} and
9380 @code{@var{x} THRU HI} ranges, respectively.  Each is followed by a
9381 single field representing @var{x}.  If one of the ranges is present, it
9382 may be followed by a single missing value record.
9383
9384 In addition, each variable record can optionally be followed by a
9385 variable label record, which has tag code @samp{C}.  A variable label
9386 record has one field, the variable label itself (string).
9387
9388 @node Value Label Records, Portable File Data, Variable Records, Portable File Format
9389 @section Value Label Records
9390
9391 Value label records have tag code @samp{D}.  They have the following
9392 format:
9393
9394 @itemize @bullet
9395 @item
9396 Variable count (integer).
9397
9398 @item
9399 List of variables (strings).  The variable count specifies the number in
9400 the list.  Variables are specified by their names.  All variables must
9401 be of the same type (numeric or string).
9402
9403 @item
9404 Label count (integer).
9405
9406 @item
9407 List of (value, label) tuples.  The label count specifies the number of
9408 tuples.  Each tuple consists of a value, which is numeric or string as
9409 appropriate to the variables, followed by a label (string).
9410 @end itemize
9411
9412 @node Portable File Data,  , Value Label Records, Portable File Format
9413 @section Portable File Data
9414
9415 The data record has tag code @samp{F}.  There is only one tag for all
9416 the data; thus, all the data must follow the dictionary.  The data is
9417 terminated by the end-of-file marker @samp{Z}, which is not valid as the
9418 beginning of a data element.
9419
9420 Data elements are output in the same order as the variable records
9421 describing them.  String variables are output as string fields, and
9422 numeric variables are output as floating-point fields.
9423
9424 @node q2c Input Format, Bugs, Portable File Format, Top
9425 @chapter @code{q2c} Input Format
9426
9427 PSPP statistical procedures have a bizarre and somewhat irregular
9428 syntax.  Despite this, a parser generator has been written that
9429 adequately addresses many of the possibilities and tries to provide
9430 hooks for the exceptional cases.  This parser generator is named
9431 @code{q2c}.
9432
9433 @menu
9434 * Invoking q2c::                q2c command-line syntax.
9435 * q2c Input Structure::         High-level layout of the input file.
9436 * Grammar Rules::               Syntax of the grammar rules.
9437 @end menu
9438
9439 @node Invoking q2c, q2c Input Structure, q2c Input Format, q2c Input Format
9440 @section Invoking q2c
9441
9442 @example
9443 q2c @var{input.q} @var{output.c}
9444 @end example
9445
9446 @code{q2c} translates a @samp{.q} file into a @samp{.c} file.  It takes
9447 exactly two command-line arguments, which are the input file name and
9448 output file name, respectively.  @code{q2c} does not accept any
9449 command-line options.
9450
9451 @node q2c Input Structure, Grammar Rules, Invoking q2c, q2c Input Format
9452 @section @code{q2c} Input Structure
9453
9454 @code{q2c} input files are divided into two sections: the grammar rules
9455 and the supporting code.  The @dfn{grammar rules}, which make up the
9456 first part of the input, are used to define the syntax of the
9457 statistical procedure to be parsed.  The @dfn{supporting code},
9458 following the grammar rules, are copied largely unchanged to the output
9459 file, except for certain escapes.
9460
9461 The most important lines in the grammar rules are used for defining
9462 procedure syntax.  These lines can be prefixed with a dollar sign
9463 (@samp{$}), which prevents Emacs' CC-mode from munging them.  Besides
9464 this, a bang (@samp{!}) at the beginning of a line causes the line,
9465 minus the bang, to be written verbatim to the output file (useful for
9466 comments).  As a third special case, any line that begins with the exact
9467 characters @code{/* *INDENT} is ignored and not written to the output.
9468 This allows @code{.q} files to be processed through @code{indent}
9469 without being munged.
9470
9471 The syntax of the grammar rules themselves is given in the following
9472 sections.
9473
9474 The supporting code is passed into the output file largely unchanged.
9475 However, the following escapes are supported.  Each escape must appear
9476 on a line by itself.
9477
9478 @table @code
9479 @item /* (header) */
9480
9481 Expands to a series of C @code{#include} directives which include the
9482 headers that are required for the parser generated by @code{q2c}.
9483
9484 @item /* (decls @var{scope}) */
9485
9486 Expands to C variable and data type declarations for the variables and
9487 @code{enum}s input and output by the @code{q2c} parser.  @var{scope}
9488 must be either @code{local} or @code{global}.  @code{local} causes the
9489 declarations to be output as function locals.  @code{global} causes them
9490 to be declared as @code{static} module variables; thus, @code{global} is
9491 a bit of a misnomer.
9492
9493 @item /* (parser) */
9494
9495 Expands to the entire parser.  Must be enclosed within a C function.
9496
9497 @item /* (free) */
9498
9499 Expands to a set of calls to the @code{free} function for variables
9500 declared by the parser.  Only needs to be invoked if subcommands of type
9501 @code{string} are used in the grammar rules.
9502 @end table
9503
9504 @node Grammar Rules,  , q2c Input Structure, q2c Input Format
9505 @section Grammar Rules
9506
9507 The grammar rules describe the format of the syntax that the parser
9508 generated by @code{q2c} will understand.  The way that the grammar rules
9509 are included in @code{q2c} input file are described above.
9510
9511 The grammar rules are divided into tokens of the following types:
9512
9513 @table @asis
9514 @item Identifier (@code{ID})
9515
9516 An identifier token is a sequence of letters, digits, and underscores
9517 (@samp{_}).  Identifiers are @emph{not} case-sensitive.
9518
9519 @item String (@code{STRING})
9520
9521 String tokens are initiated by a double-quote character (@samp{"}) and
9522 consist of all the characters between that double quote and the next
9523 double quote, which must be on the same line as the first.  Within a
9524 string, a backslash can be used as a ``literal escape''.  The only
9525 reasons to use a literal escape are to include a double quote or a
9526 backslash within a string.
9527
9528 @item Special character
9529
9530 Other characters, other than whitespace, constitute tokens in
9531 themselves.
9532
9533 @end table
9534
9535 The syntax of the grammar rules is as follows:
9536
9537 @example
9538 grammar-rules ::= ID : subcommands .
9539 subcommands ::= subcommand
9540             ::= subcommands ; subcommand
9541 @end example
9542
9543 The syntax begins with an ID or STRING token that gives the name of the
9544 procedure to be parsed.  The rest of the syntax consists of subcommands
9545 separated by semicolons (@samp{;}) and terminated with a full stop
9546 (@samp{.}).
9547
9548 @example
9549 subcommand ::= sbc-options ID sbc-defn
9550 sbc-options ::= 
9551             ::= sbc-option
9552             ::= sbc-options sbc-options
9553 sbc-option ::= *
9554            ::= +
9555 sbc-defn ::= opt-prefix = specifiers
9556          ::= [ ID ] = array-sbc
9557          ::= opt-prefix = sbc-special-form
9558 opt-prefix ::=
9559            ::= ( ID )
9560 @end example
9561
9562 Each subcommand can be prefixed with one or more option characters.  An
9563 asterisk (@samp{*}) is used to indicate the default subcommand; the
9564 keyword used for the default subcommand can be omitted in the PSPP
9565 syntax file.  A plus sign (@samp{+}) is used to indicate that a
9566 subcommand can appear more than once; if it is not present then that
9567 subcommand can appear no more than once.
9568
9569 The subcommand name appears after the option characters.
9570
9571 There are three forms of subcommands.  The first and most common form
9572 simply gives an equals sign (@samp{=}) and a list of specifiers, which
9573 can each be set to a single setting.  The second form declares an array,
9574 which is a set of flags that can be individually turned on by the user.
9575 There are also several special forms that do not take a list of
9576 specifiers.
9577
9578 Arrays require an additional @code{ID} argument.  This is used as a
9579 prefix, prepended to the variable names constructed from the
9580 specifiers.  The other forms also allow an optional prefix to be
9581 specified.
9582
9583 @example
9584 array-sbc ::= alternatives
9585           ::= array-sbc , alternatives
9586 alternatives ::= ID
9587              ::= alternatives | ID
9588 @end example
9589
9590 An array subcommand is a set of Boolean values that can independently be
9591 turned on by the user, listed separated by commas (@samp{,}).  If an value has more
9592 than one name then these names are separated by pipes (@samp{|}).
9593
9594 @example
9595 specifiers ::= specifier
9596            ::= specifiers , specifier
9597 specifier ::= opt-id : settings
9598 opt-id ::=
9599        ::= ID
9600 @end example
9601
9602 Ordinary subcommands (other than arrays and special forms) require a
9603 list of specifiers.  Each specifier has an optional name and a list of
9604 settings.  If the name is given then a correspondingly named variable
9605 will be used to store the user's choice of setting.  If no name is given
9606 then there is no way to tell which setting the user picked; in this case
9607 the settings should probably have values attached.
9608
9609 @example
9610 settings ::= setting
9611          ::= settings / setting
9612 setting ::= setting-options ID setting-value
9613 setting-options ::=
9614                 ::= *
9615                 ::= !
9616                 ::= * !
9617 @end example
9618
9619 Individual settings are separated by forward slashes (@samp{/}).  Each
9620 setting can be as little as an @code{ID} token, but options and values
9621 can optionally be included.  The @samp{*} option means that, for this
9622 setting, the @code{ID} can be omitted.  The @samp{!} option means that
9623 this option is the default for its specifier.
9624
9625 @example
9626 setting-value ::=
9627               ::= ( setting-value-2 )
9628               ::= setting-value-2
9629 setting-value-2 ::= setting-value-options setting-value-type : ID 
9630                     setting-value-restriction
9631 setting-value-options ::=
9632                       ::= *
9633 setting-value-type ::= N
9634                    ::= D
9635 setting-value-restriction ::= 
9636                           ::= , STRING
9637 @end example
9638
9639 Settings may have values.  If the value must be enclosed in parentheses,
9640 then enclose the value declaration in parentheses.  Declare the setting
9641 type as @samp{n} or @samp{d} for integer or floating point type,
9642 respectively.  The given @code{ID} is used to construct a variable name.
9643 If option @samp{*} is given, then the value is optional; otherwise it
9644 must be specified whenever the corresponding setting is specified.  A
9645 ``restriction'' can also be specified which is a string giving a C
9646 expression limiting the valid range of the value.  The special escape
9647 @code{%s} should be used within the restriction to refer to the
9648 setting's value variable.
9649
9650 @example
9651 sbc-special-form ::= VAR
9652                  ::= VARLIST varlist-options
9653                  ::= INTEGER opt-list
9654                  ::= DOUBLE opt-list
9655                  ::= PINT
9656                  ::= STRING @r{(the literal word STRING)} string-options
9657                  ::= CUSTOM
9658 varlist-options ::= 
9659                 ::= ( STRING )
9660 opt-list ::=
9661          ::= LIST
9662 string-options ::= 
9663                ::= ( STRING STRING )
9664 @end example
9665
9666 The special forms are of the following types:
9667
9668 @table @code
9669 @item VAR
9670
9671 A single variable name.
9672
9673 @item VARLIST
9674
9675 A list of variables.  If given, the string can be used to provide
9676 @code{PV_@var{*}} options to the call to @code{parse_variables}. 
9677
9678 @item INTEGER
9679
9680 A single integer value.
9681
9682 @item INTEGER LIST
9683
9684 A list of integers separated by spaces or commas.
9685
9686 @item DOUBLE
9687
9688 A single floating-point value.
9689
9690 @item DOUBLE LIST
9691
9692 A list of floating-point values.
9693
9694 @item PINT
9695
9696 A single positive integer value.
9697
9698 @item STRING
9699
9700 A string value.  If the options are given then the first string is an
9701 expression giving a restriction on the value of the string; the second
9702 string is an error message to display when the restriction is violated.
9703
9704 @item CUSTOM
9705
9706 A custom function is used to parse this subcommand.  The function must
9707 have prototype @code{int custom_@var{name} (void)}.  It should return 0
9708 on failure (when it has already issued an appropriate diagnostic), 1 on
9709 success, or 2 if it fails and the calling function should issue a syntax
9710 error on behalf of the custom handler.
9711
9712 @end table
9713
9714 @node Bugs, Function Index, q2c Input Format, Top
9715 @chapter Bugs
9716
9717 @quotation
9718 As of fvwm 0.99 there were exactly 39.342 unidentified bugs.  Identified
9719 bugs have mostly been fixed, though.  Since then 9.34 bugs have been
9720 fixed.  Assuming that there are at least 10 unidentified bugs for every
9721 identified one, that leaves us with 39.342 - 9.34 + 10 * 9.34 = 123.422
9722 unidentified bugs.  If we follow this to its logical conclusion we
9723 will have an infinite number of unidentified bugs before the number of
9724 bugs can start to diminish, at which point the program will be
9725 bug-free.  Since this is a computer program infinity = 3.4028e+38 if you
9726 don't insist on double-precision.  At the current rate of bug discovery
9727 we should expect to achieve this point in 3.37e+27 years.  I guess I
9728 better plan on passing this thing on to my children@enddots{}
9729
9730 ---Robert Nation, @cite{fvwm manpage}.
9731 @end quotation
9732
9733 @menu
9734 * Known bugs::                  Pointers to other files.
9735 * Contacting the Author::       Where to send the bug reports.
9736 @end menu
9737
9738 @node Known bugs, Contacting the Author, Bugs, Bugs
9739 @section Known bugs
9740
9741 This is the list of known bugs in PSPP.  In addition, @xref{Not
9742 Implemented}, and @xref{Functions Not Implemented}, for lists of bugs
9743 due to features not implemented.  For known bugs in individual language
9744 features, see the documentation for that feature.
9745
9746 @itemize @bullet
9747 @item
9748 Nothing has yet been tested exhaustively. Be cautious using PSPP to
9749 make important decisions.
9750
9751 @item
9752 @code{make check} fails on some systems that don't like the syntax.  I'm
9753 not sure why.  If someone could make an attempt to track this down, it
9754 would be appreciated.
9755
9756 @item
9757 PostScript driver bugs:
9758
9759 @itemize @minus
9760 @item
9761 Does not support driver arguments `max-fonts-simult' or
9762 `optimize-text-size'.
9763
9764 @item
9765 Minor problems with font-encodings.
9766
9767 @item
9768 Fails to align fonts along their baselines.
9769
9770 @item
9771 Does not support certain bizarre line intersections--should
9772 never crop up in practice.
9773
9774 @item
9775 Does not gracefully substitute for existing fonts whose
9776 encodings are missing.
9777
9778 @item
9779 Does not perform italic correction or left italic correction
9780 on font changes.
9781
9782 @item
9783 Encapsulated PostScript is unimplemented.
9784 @end itemize
9785
9786 @item
9787 ASCII driver bugs:
9788
9789 @itemize @minus
9790 Does not support `infinite length' or `infinite width' paper.
9791 @end itemize
9792 @end itemize
9793
9794 See below for information on reporting bugs not listed here.
9795
9796 @node Contacting the Author,  , Known bugs, Bugs
9797 @section Contacting the Author
9798
9799 The author can be contacted at e-mail address
9800 @ifinfo
9801 <blp@@gnu.org>.
9802 @end ifinfo
9803 @iftex
9804 @code{<blp@@gnu.org>}.
9805 @end iftex
9806
9807 PSPP bug reports should be sent to 
9808 @ifinfo
9809 <bug-gnu-pspp@@gnu.org>.
9810 @end ifinfo
9811 @iftex
9812 @code{<bug-gnu-pspp@@gnu.org>}.
9813 @end iftex
9814
9815 @node Function Index, Concept Index, Bugs, Top
9816 @chapter Function Index
9817 @printindex fn
9818
9819 @node Concept Index, Command Index, Function Index, Top
9820 @chapter Concept Index
9821 @printindex cp
9822
9823 @node Command Index,  , Concept Index, Top
9824 @chapter Command Index
9825 @printindex vr
9826
9827 @contents
9828 @bye
9829
9830 @c Local Variables:
9831 @c compile-command: "makeinfo pspp.texi"
9832 @c End: