doc: Be more optimistic about PSPP completion.
[pspp-builds.git] / doc / language.texi
1 @node Language
2 @chapter The PSPP language
3 @cindex language, PSPP
4 @cindex PSPP, language
5
6 This chapter discusses elements common to many PSPP commands.
7 Later chapters will describe individual commands in detail.
8
9 @menu
10 * Tokens::                      Characters combine to form tokens.
11 * Commands::                    Tokens combine to form commands.
12 * Syntax Variants::             Batch vs. Interactive mode
13 * Types of Commands::           Commands come in several flavors.
14 * Order of Commands::           Commands combine to form syntax files.
15 * Missing Observations::        Handling missing observations.
16 * Variables::                   The unit of data storage.
17 * Files::                       Files used by PSPP.
18 * File Handles::                How files are named.
19 * BNF::                         How command syntax is described.
20 @end menu
21
22
23 @node Tokens
24 @section Tokens
25 @cindex language, lexical analysis
26 @cindex language, tokens
27 @cindex tokens
28 @cindex lexical analysis
29
30 PSPP divides most syntax file lines into series of short chunks
31 called @dfn{tokens}.
32 Tokens are then grouped to form commands, each of which tells
33 PSPP to take some action---read in data, write out data, perform
34 a statistical procedure, etc.  Each type of token is
35 described below.
36
37 @table @strong
38 @cindex identifiers
39 @item Identifiers
40 Identifiers are names that typically specify variables, commands, or
41 subcommands.  The first character in an identifier must be a letter,
42 @samp{#}, or @samp{@@}.  The remaining characters in the identifier
43 must be letters, digits, or one of the following special characters:
44
45 @example
46 @center @.  _  $  #  @@
47 @end example
48
49 @cindex case-sensitivity
50 Identifiers may be any length, but only the first 64 bytes are
51 significant.  Identifiers are not case-sensitive: @code{foobar},
52 @code{Foobar}, @code{FooBar}, @code{FOOBAR}, and @code{FoObaR} are
53 different representations of the same identifier.
54
55 @cindex identifiers, reserved
56 @cindex reserved identifiers
57 Some identifiers are reserved.  Reserved identifiers may not be used
58 in any context besides those explicitly described in this manual.  The
59 reserved identifiers are:
60
61 @example
62 @center ALL  AND  BY  EQ  GE  GT  LE  LT  NE  NOT  OR  TO  WITH
63 @end example
64
65 @item Keywords
66 Keywords are a subclass of identifiers that form a fixed part of
67 command syntax.  For example, command and subcommand names are
68 keywords.  Keywords may be abbreviated to their first 3 characters if
69 this abbreviation is unambiguous.  (Unique abbreviations of 3 or more
70 characters are also accepted: @samp{FRE}, @samp{FREQ}, and
71 @samp{FREQUENCIES} are equivalent when the last is a keyword.)
72
73 Reserved identifiers are always used as keywords.  Other identifiers
74 may be used both as keywords and as user-defined identifiers, such as
75 variable names.
76
77 @item Numbers
78 @cindex numbers
79 @cindex integers
80 @cindex reals
81 Numbers are expressed in decimal.  A decimal point is optional.
82 Numbers may be expressed in scientific notation by adding @samp{e} and
83 a base-10 exponent, so that @samp{1.234e3} has the value 1234.  Here
84 are some more examples of valid numbers:
85
86 @example
87 -5  3.14159265359  1e100  -.707  8945.
88 @end example
89
90 Negative numbers are expressed with a @samp{-} prefix.  However, in
91 situations where a literal @samp{-} token is expected, what appears to
92 be a negative number is treated as @samp{-} followed by a positive
93 number.
94
95 No white space is allowed within a number token, except for horizontal
96 white space between @samp{-} and the rest of the number.
97
98 The last example above, @samp{8945.} will be interpreted as two
99 tokens, @samp{8945} and @samp{.}, if it is the last token on a line.
100 @xref{Commands, , Forming commands of tokens}.
101
102 @item Strings
103 @cindex strings
104 @cindex @samp{'}
105 @cindex @samp{"}
106 @cindex case-sensitivity
107 Strings are literal sequences of characters enclosed in pairs of
108 single quotes (@samp{'}) or double quotes (@samp{"}).  To include the
109 character used for quoting in the string, double it, e.g.@:
110 @samp{'it''s an apostrophe'}.  White space and case of letters are
111 significant inside strings.
112
113 Strings can be concatenated using @samp{+}, so that @samp{"a" + 'b' +
114 'c'} is equivalent to @samp{'abc'}.  Concatenation is useful for
115 splitting a single string across multiple source lines. The maximum
116 length of a string, after concatenation, is 255 characters.
117
118 Strings may also be expressed as hexadecimal, octal, or binary
119 character values by prefixing the initial quote character by @samp{X},
120 @samp{O}, or @samp{B} or their lowercase equivalents.  Each pair,
121 triplet, or octet of characters, according to the radix, is
122 transformed into a single character with the given value.  If there is
123 an incomplete group of characters, the missing final digits are
124 assumed to be @samp{0}.  These forms of strings are nonportable
125 because numeric values are associated with different characters by
126 different operating systems.  Therefore, their use should be confined
127 to syntax files that will not be widely distributed.
128
129 @cindex characters, reserved
130 @cindex 0
131 @cindex white space
132 The character with value 00 is reserved for
133 internal use by PSPP.  Its use in strings causes an error and
134 replacement by a space character.
135
136 @item Punctuators and Operators
137 @cindex punctuators
138 @cindex operators
139 These tokens are the punctuators and operators:
140
141 @example
142 @center ,  /  =  (  )  +  -  *  /  **  <  <=  <>  >  >=  ~=  &  |  .
143 @end example
144
145 Most of these appear within the syntax of commands, but the period
146 (@samp{.}) punctuator is used only at the end of a command.  It is a
147 punctuator only as the last character on a line (except white space).
148 When it is the last non-space character on a line, a period is not
149 treated as part of another token, even if it would otherwise be part
150 of, e.g.@:, an identifier or a floating-point number.
151
152 Actually, the character that ends a command can be changed with
153 @cmd{SET}'s ENDCMD subcommand (@pxref{SET}), but we do not recommend
154 doing so.  Throughout the remainder of this manual we will assume that
155 the default setting is in effect.
156 @end table
157
158 @node Commands
159 @section Forming commands of tokens
160
161 @cindex PSPP, command structure
162 @cindex language, command structure
163 @cindex commands, structure
164
165 Most PSPP commands share a common structure.  A command begins with a
166 command name, such as @cmd{FREQUENCIES}, @cmd{DATA LIST}, or @cmd{N OF
167 CASES}.  The command name may be abbreviated to its first word, and
168 each word in the command name may be abbreviated to its first three
169 or more characters, where these abbreviations are unambiguous.
170
171 The command name may be followed by one or more @dfn{subcommands}.
172 Each subcommand begins with a subcommand name, which may be
173 abbreviated to its first three letters.  Some subcommands accept a
174 series of one or more specifications, which follow the subcommand
175 name, optionally separated from it by an equals sign
176 (@samp{=}). Specifications may be separated from each other
177 by commas or spaces.  Each subcommand must be separated from the next (if any)
178 by a forward slash (@samp{/}).
179
180 There are multiple ways to mark the end of a command.  The most common
181 way is to end the last line of the command with a period (@samp{.}) as
182 described in the previous section (@pxref{Tokens}).  A blank line, or
183 one that consists only of white space or comments, also ends a command
184 by default, although you can use the NULLINE subcommand of @cmd{SET}
185 to disable this feature (@pxref{SET}).
186
187 @node Syntax Variants
188 @section Variants of syntax.
189
190 @cindex Batch syntax
191 @cindex Interactive syntax
192
193 There are two variants of command syntax, @i{viz}: @dfn{batch} mode and
194 @dfn{interactive} mode.
195 Batch mode is the default when reading commands from a file.
196 Interactive mode is the default when commands are typed at a prompt
197 by a user.
198 Certain commands, such as @cmd{INSERT} (@pxref{INSERT}), may explicitly
199 change the syntax mode. 
200
201 In batch mode, any line that contains a non-space character
202 in the leftmost column begins a new command. 
203 Thus, each command consists of a flush-left line followed by any
204 number of lines indented from the left margin. 
205 In this mode, a plus or minus sign (@samp{+}, @samp{@minus{}}) as the
206 first character in a line is ignored and causes that line to begin a
207 new command, which allows for visual indentation of a command without
208 that command being considered part of the previous command. 
209 The period terminating the end of a command is optional but recommended.
210
211 In interactive mode, each command must  either be terminated with a period,
212 or an empty line must follow the command.
213 The use of (@samp{+} and @samp{@minus{}} as continuation characters is not
214 permitted.
215
216 @node Types of Commands
217 @section Types of Commands
218
219 Commands in PSPP are divided roughly into six categories:
220
221 @table @strong
222 @item Utility commands
223 @cindex utility commands
224 Set or display various global options that affect PSPP operations.
225 May appear anywhere in a syntax file.  @xref{Utilities, , Utility
226 commands}.
227
228 @item File definition commands
229 @cindex file definition commands
230 Give instructions for reading data from text files or from special
231 binary ``system files''.  Most of these commands replace any previous
232 data or variables with new data or
233 variables.  At least one file definition command must appear before the first command in any of
234 the categories below.  @xref{Data Input and Output}.
235
236 @item Input program commands
237 @cindex input program commands
238 Though rarely used, these provide tools for reading data files
239 in arbitrary textual or binary formats.  @xref{INPUT PROGRAM}.
240
241 @item Transformations
242 @cindex transformations
243 Perform operations on data and write data to output files.  Transformations
244 are not carried out until a procedure is executed.  
245
246 @item Restricted transformations
247 @cindex restricted transformations
248 Transformations that cannot appear in certain contexts.  @xref{Order
249 of Commands}, for details.
250
251 @item Procedures
252 @cindex procedures
253 Analyze data, writing results of analyses to the listing file.  Cause
254 transformations specified earlier in the file to be performed.  In a
255 more general sense, a @dfn{procedure} is any command that causes the
256 active file (the data) to be read.
257 @end table
258
259 @node Order of Commands
260 @section Order of Commands
261 @cindex commands, ordering
262 @cindex order of commands
263
264 PSPP does not place many restrictions on ordering of commands.  The
265 main restriction is that variables must be defined before they are otherwise
266 referenced.  This section describes the details of command ordering,
267 but most users will have no need to refer to them.
268
269 PSPP possesses five internal states, called initial, INPUT PROGRAM,
270 FILE TYPE, transformation, and procedure states.  (Please note the
271 distinction between the @cmd{INPUT PROGRAM} and @cmd{FILE TYPE}
272 @emph{commands} and the INPUT PROGRAM and FILE TYPE @emph{states}.)
273
274 PSPP starts in the initial state.  Each successful completion
275 of a command may cause a state transition.  Each type of command has its
276 own rules for state transitions:
277
278 @table @strong
279 @item Utility commands
280 @itemize @bullet
281 @item
282 Valid in any state.
283 @item
284 Do not cause state transitions.  Exception: when @cmd{N OF CASES}
285 is executed in the procedure state, it causes a transition to the
286 transformation state.
287 @end itemize
288
289 @item @cmd{DATA LIST}
290 @itemize @bullet
291 @item
292 Valid in any state.
293 @item
294 When executed in the initial or procedure state, causes a transition to
295 the transformation state.  
296 @item
297 Clears the active file if executed in the procedure or transformation
298 state.
299 @end itemize
300
301 @item @cmd{INPUT PROGRAM}
302 @itemize @bullet
303 @item
304 Invalid in INPUT PROGRAM and FILE TYPE states.
305 @item
306 Causes a transition to the INPUT PROGRAM state.  
307 @item
308 Clears the active file.
309 @end itemize
310
311 @item @cmd{FILE TYPE}
312 @itemize @bullet
313 @item
314 Invalid in INPUT PROGRAM and FILE TYPE states.
315 @item
316 Causes a transition to the FILE TYPE state.
317 @item
318 Clears the active file.
319 @end itemize
320
321 @item Other file definition commands
322 @itemize @bullet
323 @item
324 Invalid in INPUT PROGRAM and FILE TYPE states.
325 @item
326 Cause a transition to the transformation state.
327 @item
328 Clear the active file, except for @cmd{ADD FILES}, @cmd{MATCH FILES},
329 and @cmd{UPDATE}.
330 @end itemize
331
332 @item Transformations
333 @itemize @bullet
334 @item
335 Invalid in initial and FILE TYPE states.
336 @item
337 Cause a transition to the transformation state.
338 @end itemize
339
340 @item Restricted transformations
341 @itemize @bullet
342 @item
343 Invalid in initial, INPUT PROGRAM, and FILE TYPE states.
344 @item
345 Cause a transition to the transformation state.
346 @end itemize
347
348 @item Procedures
349 @itemize @bullet
350 @item
351 Invalid in initial, INPUT PROGRAM, and FILE TYPE states.
352 @item
353 Cause a transition to the procedure state.
354 @end itemize
355 @end table
356
357 @node Missing Observations
358 @section Handling missing observations
359 @cindex missing values
360 @cindex values, missing
361
362 PSPP includes special support for unknown numeric data values.
363 Missing observations are assigned a special value, called the
364 @dfn{system-missing value}.  This ``value'' actually indicates the
365 absence of a value; it means that the actual value is unknown.  Procedures
366 automatically exclude from analyses those observations or cases that
367 have missing values.  Details of missing value exclusion depend on the
368 procedure and can often be controlled by the user; refer to
369 descriptions of individual procedures for details.
370
371 The system-missing value exists only for numeric variables.  String
372 variables always have a defined value, even if it is only a string of
373 spaces.
374
375 Variables, whether numeric or string, can have designated
376 @dfn{user-missing values}.  Every user-missing value is an actual value
377 for that variable.  However, most of the time user-missing values are
378 treated in the same way as the system-missing value.
379
380 For more information on missing values, see the following sections:
381 @ref{Variables}, @ref{MISSING VALUES}, @ref{Expressions}.  See also the
382 documentation on individual procedures for information on how they
383 handle missing values.
384
385 @node Variables
386 @section Variables
387 @cindex variables
388 @cindex dictionary
389
390 Variables are the basic unit of data storage in PSPP.  All the
391 variables in a file taken together, apart from any associated data, are
392 said to form a @dfn{dictionary}.  
393 Some details of variables are described in the sections below.
394
395 @menu
396 * Attributes::                  Attributes of variables.
397 * System Variables::            Variables automatically defined by PSPP.
398 * Sets of Variables::           Lists of variable names.
399 * Input and Output Formats::    Input and output formats.
400 * Scratch Variables::           Variables deleted by procedures.
401 @end menu
402
403 @node Attributes
404 @subsection Attributes of Variables
405 @cindex variables, attributes of
406 @cindex attributes of variables
407 Each variable has a number of attributes, including:
408
409 @table @strong
410 @item Name
411 An identifier, up to 64 bytes long.  Each variable must have a different name.
412 @xref{Tokens}.
413
414 Some system variable names begin with @samp{$}, but user-defined
415 variables' names may not begin with @samp{$}.
416
417 @cindex @samp{.}
418 @cindex period
419 @cindex variable names, ending with period
420 The final character in a variable name should not be @samp{.}, because
421 such an identifier will be misinterpreted when it is the final token
422 on a line: @code{FOO.} will be divided into two separate tokens,
423 @samp{FOO} and @samp{.}, indicating end-of-command.  @xref{Tokens}.
424
425 @cindex @samp{_}
426 The final character in a variable name should not be @samp{_}, because
427 some such identifiers are used for special purposes by PSPP
428 procedures.
429
430 As with all PSPP identifiers, variable names are not case-sensitive.
431 PSPP capitalizes variable names on output the same way they were
432 capitalized at their point of definition in the input.
433
434 @cindex variables, type
435 @cindex type of variables
436 @item Type
437 Numeric or string.
438
439 @cindex variables, width
440 @cindex width of variables
441 @item Width
442 (string variables only) String variables with a width of 8 characters or
443 fewer are called @dfn{short string variables}.  Short string variables
444 may be used in a few contexts where @dfn{long string variables} (those
445 with widths greater than 8) are not allowed.
446
447 @item Position
448 Variables in the dictionary are arranged in a specific order.
449 @cmd{DISPLAY} can be used to show this order: see @ref{DISPLAY}.
450
451 @item Initialization
452 Either reinitialized to 0 or spaces for each case, or left at its
453 existing value.  @xref{LEAVE}.
454
455 @cindex missing values
456 @cindex values, missing
457 @item Missing values
458 Optionally, up to three values, or a range of values, or a specific
459 value plus a range, can be specified as @dfn{user-missing values}.
460 There is also a @dfn{system-missing value} that is assigned to an
461 observation when there is no other obvious value for that observation.
462 Observations with missing values are automatically excluded from
463 analyses.  User-missing values are actual data values, while the
464 system-missing value is not a value at all.  @xref{Missing Observations}.
465
466 @cindex variable labels
467 @cindex labels, variable
468 @item Variable label
469 A string that describes the variable.  @xref{VARIABLE LABELS}.
470
471 @cindex value labels
472 @cindex labels, value
473 @item Value label
474 Optionally, these associate each possible value of the variable with a
475 string.  @xref{VALUE LABELS}.
476
477 @cindex print format
478 @item Print format
479 Display width, format, and (for numeric variables) number of decimal
480 places.  This attribute does not affect how data are stored, just how
481 they are displayed.  Example: a width of 8, with 2 decimal places.
482 @xref{Input and Output Formats}.
483
484 @cindex write format
485 @item Write format
486 Similar to print format, but used by the @cmd{WRITE} command
487 (@pxref{WRITE}).
488
489 @cindex custom attributes
490 @item Custom attributes
491 User-defined associations between names and values.  @xref{VARIABLE
492 ATTRIBUTE}.
493 @end table
494
495 @node System Variables
496 @subsection Variables Automatically Defined by PSPP
497 @cindex system variables
498 @cindex variables, system
499
500 There are seven system variables.  These are not like ordinary
501 variables because system variables are not always stored.  They can be used only
502 in expressions.  These system variables, whose values and output formats
503 cannot be modified, are described below.
504
505 @table @code
506 @cindex @code{$CASENUM}
507 @item $CASENUM
508 Case number of the case at the moment.  This changes as cases are
509 shuffled around.
510
511 @cindex @code{$DATE}
512 @item $DATE
513 Date the PSPP process was started, in format A9, following the
514 pattern @code{DD MMM YY}.
515
516 @cindex @code{$JDATE}
517 @item $JDATE
518 Number of days between 15 Oct 1582 and the time the PSPP process
519 was started.
520
521 @cindex @code{$LENGTH}
522 @item $LENGTH
523 Page length, in lines, in format F11.
524
525 @cindex @code{$SYSMIS}
526 @item $SYSMIS
527 System missing value, in format F1.
528
529 @cindex @code{$TIME}
530 @item $TIME
531 Number of seconds between midnight 14 Oct 1582 and the time the active file
532 was read, in format F20.
533
534 @cindex @code{$WIDTH}
535 @item $WIDTH
536 Page width, in characters, in format F3.
537 @end table
538
539 @node Sets of Variables
540 @subsection Lists of variable names
541 @cindex @code{TO} convention
542 @cindex convention, @code{TO}
543
544 To refer to a set of variables, list their names one after another.
545 Optionally, their names may be separated by commas.  To include a
546 range of variables from the dictionary in the list, write the name of
547 the first and last variable in the range, separated by @code{TO}.  For
548 instance, if the dictionary contains six variables with the names
549 @code{ID}, @code{X1}, @code{X2}, @code{GOAL}, @code{MET}, and
550 @code{NEXTGOAL}, in that order, then @code{X2 TO MET} would include
551 variables @code{X2}, @code{GOAL}, and @code{MET}.
552
553 Commands that define variables, such as @cmd{DATA LIST}, give
554 @code{TO} an alternate meaning.  With these commands, @code{TO} define
555 sequences of variables whose names end in consecutive integers.  The
556 syntax is two identifiers that begin with the same root and end with
557 numbers, separated by @code{TO}.  The syntax @code{X1 TO X5} defines 5
558 variables, named @code{X1}, @code{X2}, @code{X3}, @code{X4}, and
559 @code{X5}.  The syntax @code{ITEM0008 TO ITEM0013} defines 6
560 variables, named @code{ITEM0008}, @code{ITEM0009}, @code{ITEM0010},
561 @code{ITEM0011}, @code{ITEM0012}, and @code{ITEM00013}.  The syntaxes
562 @code{QUES001 TO QUES9} and @code{QUES6 TO QUES3} are invalid.
563
564 After a set of variables has been defined with @cmd{DATA LIST} or
565 another command with this method, the same set can be referenced on
566 later commands using the same syntax.
567
568 @node Input and Output Formats
569 @subsection Input and Output Formats
570
571 @cindex formats
572 An @dfn{input format} describes how to interpret the contents of an
573 input field as a number or a string.  It might specify that the field
574 contains an ordinary decimal number, a time or date, a number in binary
575 or hexadecimal notation, or one of several other notations.  Input
576 formats are used by commands such as @cmd{DATA LIST} that read data or
577 syntax files into the PSPP active file.
578
579 Every input format corresponds to a default @dfn{output format} that
580 specifies the formatting used when the value is output later.  It is
581 always possible to explicitly specify an output format that resembles
582 the input format.  Usually, this is the default, but in cases where the
583 input format is unfriendly to human readability, such as binary or
584 hexadecimal formats, the default output format is an easier-to-read
585 decimal format.
586
587 Every variable has two output formats, called its @dfn{print format} and
588 @dfn{write format}.  Print formats are used in most output contexts;
589 write formats are used only by @cmd{WRITE} (@pxref{WRITE}).  Newly
590 created variables have identical print and write formats, and
591 @cmd{FORMATS}, the most commonly used command for changing formats
592 (@pxref{FORMATS}), sets both of them to the same value as well.  Thus,
593 most of the time, the distinction between print and write formats is
594 unimportant.
595
596 Input and output formats are specified to PSPP with a @dfn{format
597 specification} of the form @code{TYPEw} or @code{TYPEw.d}, where
598 @code{TYPE} is one of the format types described later, @code{w} is a
599 field width measured in columns, and @code{d} is an optional number of
600 decimal places.  If @code{d} is omitted, a value of 0 is assumed.  Some
601 formats do not allow a nonzero @code{d} to be specified.
602
603 The following sections describe the input and output formats supported
604 by PSPP.
605
606 @menu
607 * Basic Numeric Formats::       
608 * Custom Currency Formats::     
609 * Legacy Numeric Formats::      
610 * Binary and Hexadecimal Numeric Formats::  
611 * Time and Date Formats::       
612 * Date Component Formats::      
613 * String Formats::              
614 @end menu
615
616 @node Basic Numeric Formats
617 @subsubsection Basic Numeric Formats
618
619 @cindex numeric formats
620 The basic numeric formats are used for input and output of real numbers
621 in standard or scientific notation.  The following table shows an
622 example of how each format displays positive and negative numbers with
623 the default decimal point setting:
624
625 @float
626 @multitable {DOLLAR10.2} {@code{@tie{}$3,141.59}} {@code{-$3,141.59}}
627 @headitem Format @tab @code{@tie{}3141.59}   @tab @code{-3141.59}
628 @item F8.2       @tab @code{@tie{}3141.59}   @tab @code{-3141.59}
629 @item COMMA9.2   @tab @code{@tie{}3,141.59}  @tab @code{-3,141.59}
630 @item DOT9.2     @tab @code{@tie{}3.141,59}  @tab @code{-3.141,59}
631 @item DOLLAR10.2 @tab @code{@tie{}$3,141.59} @tab @code{-$3,141.59}
632 @item PCT9.2     @tab @code{@tie{}3141.59%}  @tab @code{-3141.59%}
633 @item E8.1       @tab @code{@tie{}3.1E+003}  @tab @code{-3.1E+003}
634 @end multitable
635 @end float
636
637 On output, numbers in F format are expressed in standard decimal
638 notation with the requested number of decimal places.  The other formats
639 output some variation on this style:
640
641 @itemize @bullet
642 @item
643 Numbers in COMMA format are additionally grouped every three digits by
644 inserting a grouping character.  The grouping character is ordinarily a
645 comma, but it can be changed to a period (@pxref{SET DECIMAL}).
646
647 @item
648 DOT format is like COMMA format, but it interchanges the role of the
649 decimal point and grouping characters.  That is, the current grouping
650 character is used as a decimal point and vice versa.
651
652 @item
653 DOLLAR format is like COMMA format, but it prefixes the number with
654 @samp{$}.
655
656 @item
657 PCT format is like F format, but adds @samp{%} after the number.
658
659 @item
660 The E format always produces output in scientific notation.
661 @end itemize
662
663 On input, the basic numeric formats accept positive and numbers in
664 standard decimal notation or scientific notation.  Leading and trailing
665 spaces are allowed.  An empty or all-spaces field, or one that contains
666 only a single period, is treated as the system missing value.
667
668 In scientific notation, the exponent may be introduced by a sign
669 (@samp{+} or @samp{-}), or by one of the letters @samp{e} or @samp{d}
670 (in uppercase or lowercase), or by a letter followed by a sign.  A
671 single space may follow the letter or the sign or both.
672
673 On fixed-format @cmd{DATA LIST} (@pxref{DATA LIST FIXED}) and in a few
674 other contexts, decimals are implied when the field does not contain a
675 decimal point.  In F6.5 format, for example, the field @code{314159} is
676 taken as the value 3.14159 with implied decimals.  Decimals are never
677 implied if an explicit decimal point is present or if scientific
678 notation is used.
679
680 E and F formats accept the basic syntax already described.  The other
681 formats allow some additional variations:
682
683 @itemize @bullet
684 @item
685 COMMA, DOLLAR, and DOT formats ignore grouping characters within the
686 integer part of the input field.  The identity of the grouping
687 character depends on the format.
688
689 @item
690 DOLLAR format allows a dollar sign to precede the number.  In a negative
691 number, the dollar sign may precede or follow the minus sign.
692
693 @item
694 PCT format allows a percent sign to follow the number.
695 @end itemize
696
697 All of the basic number formats have a maximum field width of 40 and
698 accept no more than 16 decimal places, on both input and output.  Some
699 additional restrictions apply:
700
701 @itemize @bullet
702 @item
703 As input formats, the basic numeric formats allow no more decimal places
704 than the field width.  As output formats, the field width must be
705 greater than the number of decimal places; that is, large enough to
706 allow for a decimal point and the number of requested decimal places.
707 DOLLAR and PCT formats must allow an additional column for @samp{$} or
708 @samp{%}.
709
710 @item
711 The default output format for a given input format increases the field
712 width enough to make room for optional input characters.  If an input
713 format calls for decimal places, the width is increased by 1 to make
714 room for an implied decimal point.  COMMA, DOT, and DOLLAR formats also
715 increase the output width to make room for grouping characters.  DOLLAR
716 and PCT further increase the output field width by 1 to make room for
717 @samp{$} or @samp{%}.  The increased output width is capped at 40, the
718 maximum field width.
719
720 @item
721 The E format is exceptional.  For output, E format has a minimum width
722 of 7 plus the number of decimal places.  The default output format for
723 an E input format is an E format with at least 3 decimal places and
724 thus a minimum width of 10.
725 @end itemize
726
727 More details of basic numeric output formatting are given below:
728
729 @itemize @bullet
730 @item
731 Output rounds to nearest, with ties rounded away from zero.  Thus, 2.5
732 is output as @code{3} in F1.0 format, and -1.125 as @code{-1.13} in F5.1
733 format.
734
735 @item
736 The system-missing value is output as a period in a field of spaces,
737 placed in the decimal point's position, or in the rightmost column if no
738 decimal places are requested.  A period is used even if the decimal
739 point character is a comma.
740
741 @item
742 A number that does not fill its field is right-justified within the
743 field.
744
745 @item
746 A number is too large for its field causes decimal places to be dropped
747 to make room.  If dropping decimals does not make enough room,
748 scientific notation is used if the field is wide enough.  If a number
749 does not fit in the field, even in scientific notation, the overflow is
750 indicated by filling the field with asterisks (@samp{*}).
751
752 @item
753 COMMA, DOT, and DOLLAR formats insert grouping characters only if space
754 is available for all of them.  Grouping characters are never inserted
755 when all decimal places must be dropped.  Thus, 1234.56 in COMMA5.2
756 format is output as @samp{@tie{}1235} without a comma, even though there
757 is room for one, because all decimal places were dropped.
758
759 @item
760 DOLLAR or PCT format drop the @samp{$} or @samp{%} only if the number
761 would not fit at all without it.  Scientific notation with @samp{$} or
762 @samp{%} is preferred to ordinary decimal notation without it.
763
764 @item
765 Except in scientific notation, a decimal point is included only when
766 it is followed by a digit.  If the integer part of the number being
767 output is 0, and a decimal point is included, then the zero before the
768 decimal point is dropped.
769
770 In scientific notation, the number always includes a decimal point,
771 even if it is not followed by a digit.
772
773 @item
774 A negative number includes a minus sign only in the presence of a
775 nonzero digit: -0.01 is output as @samp{-.01} in F4.2 format but as
776 @samp{@tie{}@tie{}.0} in F4.1 format.  Thus, a ``negative zero'' never
777 includes a minus sign.
778
779 @item
780 In negative numbers output in DOLLAR format, the dollar sign follows the
781 negative sign.  Thus, -9.99 in DOLLAR6.2 format is output as
782 @code{-$9.99}.
783
784 @item
785 In scientific notation, the exponent is output as @samp{E} followed by
786 @samp{+} or @samp{-} and exactly three digits.  Numbers with magnitude
787 less than 10**-999 or larger than 10**999 are not supported by most
788 computers, but if they are supported then their output is considered
789 to overflow the field and will be output as asterisks.
790
791 @item
792 On most computers, no more than 15 decimal digits are significant in
793 output, even if more are printed.  In any case, output precision cannot
794 be any higher than input precision; few data sets are accurate to 15
795 digits of precision.  Unavoidable loss of precision in intermediate
796 calculations may also reduce precision of output.
797
798 @item
799 Special values such as infinities and ``not a number'' values are
800 usually converted to the system-missing value before printing.  In a few
801 circumstances, these values are output directly.  In fields of width 3
802 or greater, special values are output as however many characters will
803 fit from @code{+Infinity} or @code{-Infinity} for infinities, from
804 @code{NaN} for ``not a number,'' or from @code{Unknown} for other values
805 (if any are supported by the system).  In fields under 3 columns wide,
806 special values are output as asterisks.
807 @end itemize
808
809 @node Custom Currency Formats
810 @subsubsection Custom Currency Formats
811
812 @cindex currency formats
813 The custom currency formats are closely related to the basic numeric
814 formats, but they allow users to customize the output format.  The
815 SET command configures custom currency formats, using the syntax
816 @display
817 SET CC@var{x}=@t{"}@var{string}@t{"}.
818 @end display
819 @noindent 
820 where @var{x} is A, B, C, D, or E, and @var{string} is no more than 16
821 characters long.
822
823 @var{string} must contain exactly three commas or exactly three periods
824 (but not both), except that a single quote character may be used to
825 ``escape'' a following comma, period, or single quote.  If three commas
826 are used, commas will be used for grouping in output, and a period will
827 be used as the decimal point.  Uses of periods reverses these roles.
828
829 The commas or periods divide @var{string} into four fields, called the
830 @dfn{negative prefix}, @dfn{prefix}, @dfn{suffix}, and @dfn{negative
831 suffix}, respectively.  The prefix and suffix are added to output
832 whenever space is available.  The negative prefix and negative suffix
833 are always added to a negative number when the output includes a nonzero
834 digit.
835
836 The following syntax shows how custom currency formats could be used to
837 reproduce basic numeric formats:
838
839 @example
840 @group
841 SET CCA="-,,,".  /* Same as COMMA.
842 SET CCB="-...".  /* Same as DOT.
843 SET CCC="-,$,,". /* Same as DOLLAR.
844 SET CCD="-,,%,". /* Like PCT, but groups with commas.
845 @end group
846 @end example
847
848 Here are some more examples of custom currency formats.  The final
849 example shows how to use a single quote to escape a delimiter:
850
851 @example
852 @group
853 SET CCA=",EUR,,-".   /* Euro.
854 SET CCB="(,USD ,,)". /* US dollar.
855 SET CCC="-.R$..".    /* Brazilian real.
856 SET CCD="-,, NIS,".  /* Israel shekel.
857 SET CCE="-.Rp'. ..". /* Indonesia Rupiah.
858 @end group
859 @end example
860
861 @noindent These formats would yield the following output:
862
863 @float
864 @multitable {CCD13.2} {@code{@tie{}@tie{}USD 3,145.59}} {@code{(USD 3,145.59)}}
865 @headitem Format @tab @code{@tie{}3145.59}         @tab @code{-3145.59}
866 @item CCA12.2 @tab @code{@tie{}EUR3,145.59}        @tab @code{EUR3,145.59-}
867 @item CCB14.2 @tab @code{@tie{}@tie{}USD 3,145.59} @tab @code{(USD 3,145.59)}
868 @item CCC11.2 @tab @code{@tie{}R$3.145,59}         @tab @code{-R$3.145,59}
869 @item CCD13.2 @tab @code{@tie{}3,145.59 NIS}       @tab @code{-3,145.59 NIS}
870 @item CCE10.0 @tab @code{@tie{}Rp. 3.146}          @tab @code{-Rp. 3.146}
871 @end multitable
872 @end float
873
874 The default for all the custom currency formats is @samp{-,,,},
875 equivalent to COMMA format.
876
877 @node Legacy Numeric Formats
878 @subsubsection Legacy Numeric Formats
879
880 The N and Z numeric formats provide compatibility with legacy file
881 formats.  They have much in common:
882
883 @itemize @bullet
884 @item
885 Output is rounded to the nearest representable value, with ties rounded
886 away from zero.
887
888 @item
889 Numbers too large to display are output as a field filled with asterisks
890 (@samp{*}).
891
892 @item
893 The decimal point is always implicitly the specified number of digits
894 from the right edge of the field, except that Z format input allows an
895 explicit decimal point.
896
897 @item
898 Scientific notation may not be used.
899
900 @item
901 The system-missing value is output as a period in a field of spaces.
902 The period is placed just to the right of the implied decimal point in
903 Z format, or at the right end in N format or in Z format if no decimal
904 places are requested.  A period is used even if the decimal point
905 character is a comma.
906
907 @item
908 Field width may range from 1 to 40.  Decimal places may range from 0 up
909 to the field width, to a maximum of 16.
910
911 @item
912 When a legacy numeric format used for input is converted to an output
913 format, it is changed into the equivalent F format.  The field width is
914 increased by 1 if any decimal places are specified, to make room for a
915 decimal point.  For Z format, the field width is increased by 1 more
916 column, to make room for a negative sign.  The output field width is
917 capped at 40 columns.
918 @end itemize
919
920 @subsubheading N Format
921
922 The N format supports input and output of fields that contain only
923 digits.  On input, leading or trailing spaces, a decimal point, or any
924 other non-digit character causes the field to be read as the
925 system-missing value.  As a special exception, an N format used on
926 @cmd{DATA LIST FREE} or @cmd{DATA LIST LIST} is treated as the
927 equivalent F format.
928
929 On output, N pads the field on the left with zeros.  Negative numbers
930 are output like the system-missing value.
931
932 @subsubheading Z Format
933
934 The Z format is a ``zoned decimal'' format used on IBM mainframes.  Z
935 format encodes the sign as part of the final digit, which must be one of
936 the following:
937 @example
938 0123456789
939 @{ABCDEFGHI
940 @}JKLMNOPQR
941 @end example
942 @noindent
943 where the characters in each row represent digits 0 through 9 in order.
944 Characters in the first two rows indicate a positive sign; those in the
945 third indicate a negative sign.
946
947 On output, Z fields are padded on the left with spaces.  On input,
948 leading and trailing spaces are ignored.  Any character in an input
949 field other than spaces, the digit characters above, and @samp{.} causes
950 the field to be read as system-missing.
951
952 The decimal point character for input and output is always @samp{.},
953 even if the decimal point character is a comma (@pxref{SET DECIMAL}).
954
955 Nonzero, negative values output in Z format are marked as negative even
956 when no nonzero digits are output.  For example, -0.2 is output in Z1.0
957 format as @samp{J}.  The ``negative zero'' value supported by most
958 machines is output as positive.
959
960 @node Binary and Hexadecimal Numeric Formats
961 @subsubsection Binary and Hexadecimal Numeric Formats
962
963 @cindex binary formats
964 @cindex hexadecimal formats
965 The binary and hexadecimal formats are primarily designed for
966 compatibility with existing machine formats, not for human readability.
967 All of them therefore have a F format as default output format.  Some of
968 these formats are only portable between machines with compatible byte
969 ordering (endianness) or floating-point format.
970
971 Binary formats use byte values that in text files are interpreted as
972 special control functions, such as carriage return and line feed.  Thus,
973 data in binary formats should not be included in syntax files or read
974 from data files with variable-length records, such as ordinary text
975 files.  They may be read from or written to data files with fixed-length
976 records.  @xref{FILE HANDLE}, for information on working with
977 fixed-length records.
978
979 @subsubheading P and PK Formats
980
981 These are binary-coded decimal formats, in which every byte (except the
982 last, in P format) represents two decimal digits.  The most-significant
983 4 bits of the first byte is the most-significant decimal digit, the
984 least-significant 4 bits of the first byte is the next decimal digit,
985 and so on.
986
987 In P format, the most-significant 4 bits of the last byte are the
988 least-significant decimal digit.  The least-significant 4 bits represent
989 the sign: decimal 15 indicates a negative value, decimal 13 indicates a
990 positive value.
991
992 Numbers are rounded downward on output.  The system-missing value and
993 numbers outside representable range are output as zero.
994
995 The maximum field width is 16.  Decimal places may range from 0 up to
996 the number of decimal digits represented by the field.
997
998 The default output format is an F format with twice the input field
999 width, plus one column for a decimal point (if decimal places were
1000 requested).
1001
1002 @subsubheading IB and PIB Formats
1003
1004 These are integer binary formats.  IB reads and writes 2's complement
1005 binary integers, and PIB reads and writes unsigned binary integers.  The
1006 byte ordering is by default the host machine's, but SET RIB may be used
1007 to select a specific byte ordering for reading (@pxref{SET RIB}) and
1008 SET WIB, similarly, for writing (@pxref{SET WIB}).
1009
1010 The maximum field width is 8.  Decimal places may range from 0 up to the
1011 number of decimal digits in the largest value representable in the field
1012 width.
1013
1014 The default output format is an F format whose width is the number of
1015 decimal digits in the largest value representable in the field width,
1016 plus 1 if the format has decimal places.
1017
1018 @subsubheading RB Format
1019
1020 This is a binary format for real numbers.  By default it reads and
1021 writes the host machine's floating-point format, but SET RRB may be
1022 used to select an alternate floating-point format for reading
1023 (@pxref{SET RRB}) and SET WRB, similarly, for writing (@pxref{SET
1024 WRB}).
1025
1026 The recommended field width depends on the floating-point format.
1027 NATIVE (the default format), IDL, IDB, VD, VG, and ZL formats should use
1028 a field width of 8.  ISL, ISB, VF, and ZS formats should use a field
1029 width of 4.  Other field widths will not produce useful results.  The
1030 maximum field width is 8.  No decimal places may be specified.
1031
1032 The default output format is F8.2.
1033
1034 @subsubheading PIBHEX and RBHEX Formats
1035
1036 These are hexadecimal formats, for reading and writing binary formats
1037 where each byte has been recoded as a pair of hexadecimal digits.
1038
1039 A hexadecimal field consists solely of hexadecimal digits
1040 @samp{0}@dots{}@samp{9} and @samp{A}@dots{}@samp{F}.  Uppercase and
1041 lowercase are accepted on input; output is in uppercase.
1042
1043 Other than the hexadecimal representation, these formats are equivalent
1044 to PIB and RB formats, respectively.  However, bytes in PIBHEX format
1045 are always ordered with the most-significant byte first (big-endian
1046 order), regardless of the host machine's native byte order or PSPP
1047 settings.
1048
1049 Field widths must be even and between 2 and 16.  RBHEX format allows no
1050 decimal places; PIBHEX allows as many decimal places as a PIB format
1051 with half the given width.
1052
1053 @node Time and Date Formats
1054 @subsubsection Time and Date Formats
1055
1056 @cindex time formats
1057 @cindex date formats
1058 In PSPP, a @dfn{time} is an interval.  The time formats translate
1059 between human-friendly descriptions of time intervals and PSPP's
1060 internal representation of time intervals, which is simply the number of
1061 seconds in the interval.  PSPP has two time formats:
1062
1063 @float
1064 @multitable {Time Format} {@code{dd-mmm-yyyy HH:MM:SS.ss}} {@code{01-OCT-1978 04:31:17.01}}
1065 @headitem Time Format @tab Template                  @tab Example
1066 @item TIME     @tab @code{hh:MM:SS.ss}          @tab @code{04:31:17.01}
1067 @item DTIME    @tab @code{DD HH:MM:SS.ss}       @tab @code{00 04:31:17.01}
1068 @end multitable
1069 @end float
1070
1071 A @dfn{date} is a moment in the past or the future.  Internally, PSPP
1072 represents a date as the number of seconds since the @dfn{epoch},
1073 midnight, Oct. 14, 1582.  The date formats translate between
1074 human-readable dates and PSPP's numeric representation of dates and
1075 times.  PSPP has several date formats:
1076
1077 @float
1078 @multitable {Date Format} {@code{dd-mmm-yyyy HH:MM:SS.ss}} {@code{01-OCT-1978 04:31:17.01}}
1079 @headitem Date Format @tab Template                  @tab Example
1080 @item DATE     @tab @code{dd-mmm-yyyy}          @tab @code{01-OCT-1978}
1081 @item ADATE    @tab @code{mm/dd/yyyy}           @tab @code{10/01/1978}
1082 @item EDATE    @tab @code{dd.mm.yyyy}           @tab @code{01.10.1978}
1083 @item JDATE    @tab @code{yyyyjjj}              @tab @code{1978274}
1084 @item SDATE    @tab @code{yyyy/mm/dd}           @tab @code{1978/10/01}
1085 @item QYR      @tab @code{q Q yyyy}             @tab @code{3 Q 1978}
1086 @item MOYR     @tab @code{mmm yyyy}             @tab @code{OCT 1978}
1087 @item WKYR     @tab @code{ww WK yyyy}           @tab @code{40 WK 1978}
1088 @item DATETIME @tab @code{dd-mmm-yyyy HH:MM:SS.ss} @tab @code{01-OCT-1978 04:31:17.01}
1089 @end multitable
1090 @end float
1091
1092 The templates in the preceding tables describe how the time and date
1093 formats are input and output:
1094
1095 @table @code
1096 @item dd
1097 Day of month, from 1 to 31.  Always output as two digits.
1098
1099 @item mm
1100 @itemx mmm
1101 Month.  In output, @code{mm} is output as two digits, @code{mmm} as the
1102 first three letters of an English month name (January, February,
1103 @dots{}).  In input, both of these formats, plus Roman numerals, are
1104 accepted.
1105
1106 @item yyyy
1107 Year.  In output, DATETIME always produces a 4-digit year; other
1108 formats can produce a 2- or 4-digit year.  The century assumed for
1109 2-digit years depends on the EPOCH setting (@pxref{SET EPOCH}).  In
1110 output, a year outside the epoch causes the whole field to be filled
1111 with asterisks (@samp{*}).
1112
1113 @item jjj
1114 Day of year (Julian day), from 1 to 366.  This is exactly three digits
1115 giving the count of days from the start of the year.  January 1 is
1116 considered day 1.
1117
1118 @item q
1119 Quarter of year, from 1 to 4.  Quarters start on January 1, April 1,
1120 July 1, and October 1.
1121
1122 @item ww
1123 Week of year, from 1 to 53.  Output as exactly two digits.  January 1 is
1124 the first day of week 1.
1125
1126 @item DD
1127 Count of days, which may be positive or negative.  Output as at least
1128 two digits.
1129
1130 @item hh
1131 Count of hours, which may be positive or negative.  Output as at least
1132 two digits.
1133
1134 @item HH
1135 Hour of day, from 0 to 23.  Output as exactly two digits.
1136
1137 @item MM
1138 Minute of hour, from 0 to 59.  Output as exactly two digits.
1139
1140 @item SS.ss
1141 Seconds within minute, from 0 to 59.  The integer part is output as
1142 exactly two digits.  On output, seconds and fractional seconds may or
1143 may not be included, depending on field width and decimal places.  On
1144 input, seconds and fractional seconds are optional.  The DECIMAL setting
1145 controls the character accepted and displayed as the decimal point
1146 (@pxref{SET DECIMAL}).
1147 @end table
1148
1149 For output, the date and time formats use the delimiters indicated in
1150 the table.  For input, date components may be separated by spaces or by
1151 one of the characters @samp{-}, @samp{/}, @samp{.}, or @samp{,}, and
1152 time components may be separated by spaces, @samp{:}, or @samp{.}.  On
1153 input, the @samp{Q} separating quarter from year and the @samp{WK}
1154 separating week from year may be uppercase or lowercase, and the spaces
1155 around them are optional.
1156
1157 On input, all time and date formats accept any amount of leading and
1158 trailing white space.
1159
1160 The maximum width for time and date formats is 40 columns.  Minimum
1161 input and output width for each of the time and date formats is shown
1162 below:
1163
1164 @float
1165 @multitable {DATETIME} {Min. Input Width} {Min. Output Width} {4-digit year}
1166 @headitem Format @tab Min. Input Width @tab Min. Output Width @tab Option 
1167 @item DATE @tab 8 @tab 9 @tab 4-digit year
1168 @item ADATE @tab 8 @tab 8 @tab 4-digit year
1169 @item EDATE @tab 8 @tab 8 @tab 4-digit year
1170 @item JDATE @tab 5 @tab 5 @tab 4-digit year
1171 @item SDATE @tab 8 @tab 8 @tab 4-digit year
1172 @item QYR @tab 4 @tab 6 @tab 4-digit year
1173 @item MOYR @tab 6 @tab 6 @tab 4-digit year
1174 @item WKYR @tab 6 @tab 8 @tab 4-digit year
1175 @item DATETIME @tab 17 @tab 17 @tab seconds
1176 @item TIME @tab 5 @tab 5 @tab seconds
1177 @item DTIME @tab 8 @tab 8 @tab seconds
1178 @end multitable
1179 @end float
1180 @noindent 
1181 In the table, ``Option'' describes what increased output width enables:
1182
1183 @table @asis
1184 @item 4-digit year
1185 A field 2 columns wider than minimum will include a 4-digit year.
1186 (DATETIME format always includes a 4-digit year.)
1187
1188 @item seconds
1189 A field 3 columns wider than minimum will include seconds as well as
1190 minutes.  A field 5 columns wider than minimum, or more, can also
1191 include a decimal point and fractional seconds (but no more than allowed
1192 by the format's decimal places).
1193 @end table
1194
1195 For the time and date formats, the default output format is the same as
1196 the input format, except that PSPP increases the field width, if
1197 necessary, to the minimum allowed for output.
1198
1199 Time or dates narrower than the field width are right-justified within
1200 the field.
1201
1202 When a time or date exceeds the field width, characters are trimmed from
1203 the end until it fits.  This can occur in an unusual situation, e.g.@:
1204 with a year greater than 9999 (which adds an extra digit), or for a
1205 negative value on TIME or DTIME (which adds a leading minus sign).
1206
1207 @c What about out-of-range values?
1208
1209 The system-missing value is output as a period at the right end of the
1210 field.  
1211
1212 @node Date Component Formats
1213 @subsubsection Date Component Formats
1214
1215 The WKDAY and MONTH formats provide input and output for the names of
1216 weekdays and months, respectively.
1217
1218 On output, these formats convert a number between 1 and 7, for WKDAY, or
1219 between 1 and 12, for MONTH, into the English name of a day or month,
1220 respectively.  If the name is longer than the field, it is trimmed to
1221 fit.  If the name is shorter than the field, it is padded on the right
1222 with spaces.  Values outside the valid range, and the system-missing
1223 value, are output as all spaces.
1224
1225 On input, English weekday or month names (in uppercase or lowercase) are
1226 converted back to their corresponding numbers.  Weekday and month names
1227 may be abbreviated to their first 2 or 3 letters, respectively.
1228
1229 The field width may range from 2 to 40, for WKDAY, or from 3 to 40, for
1230 MONTH.  No decimal places are allowed.
1231
1232 The default output format is the same as the input format.
1233
1234 @node String Formats
1235 @subsubsection String Formats
1236
1237 @cindex string formats
1238 The A and AHEX formats are the only ones that may be assigned to string
1239 variables.  Neither format allows any decimal places.
1240
1241 In A format, the entire field is treated as a string value.  The field
1242 width may range from 1 to 32,767, the maximum string width.  The default
1243 output format is the same as the input format.
1244
1245 In AHEX format, the field is composed of characters in a string encoded
1246 as hex digit pairs.  On output, hex digits are output in uppercase; on
1247 input, uppercase and lowercase are both accepted.  The default output
1248 format is A format with half the input width.
1249
1250 @node Scratch Variables
1251 @subsection Scratch Variables
1252
1253 @cindex scratch variables
1254 Most of the time, variables don't retain their values between cases.
1255 Instead, either they're being read from a data file or the active file,
1256 in which case they assume the value read, or, if created with
1257 @cmd{COMPUTE} or
1258 another transformation, they're initialized to the system-missing value
1259 or to blanks, depending on type.
1260
1261 However, sometimes it's useful to have a variable that keeps its value
1262 between cases.  You can do this with @cmd{LEAVE} (@pxref{LEAVE}), or you can
1263 use a @dfn{scratch variable}.  Scratch variables are variables whose
1264 names begin with an octothorpe (@samp{#}).  
1265
1266 Scratch variables have the same properties as variables left with
1267 @cmd{LEAVE}: they retain their values between cases, and for the first
1268 case they are initialized to 0 or blanks.  They have the additional
1269 property that they are deleted before the execution of any procedure.
1270 For this reason, scratch variables can't be used for analysis.  To use
1271 a scratch variable in an analysis, use @cmd{COMPUTE} (@pxref{COMPUTE})
1272 to copy its value into an ordinary variable, then use that ordinary
1273 variable in the analysis.
1274
1275 @node Files
1276 @section Files Used by PSPP
1277
1278 PSPP makes use of many files each time it runs.  Some of these it
1279 reads, some it writes, some it creates.  Here is a table listing the
1280 most important of these files:
1281
1282 @table @strong
1283 @cindex file, command
1284 @cindex file, syntax file
1285 @cindex command file
1286 @cindex syntax file
1287 @item command file
1288 @itemx syntax file
1289 These names (synonyms) refer to the file that contains instructions
1290 that tell PSPP what to do.  The syntax file's name is specified on
1291 the PSPP command line.  Syntax files can also be read with
1292 @cmd{INCLUDE} (@pxref{INCLUDE}).
1293
1294 @cindex file, data
1295 @cindex data file
1296 @item data file
1297 Data files contain raw data in text or binary format.  Data can also
1298 be embedded in a syntax file with @cmd{BEGIN DATA} and @cmd{END DATA}.
1299
1300 @cindex file, output
1301 @cindex output file
1302 @item listing file
1303 One or more output files are created by PSPP each time it is
1304 run.  The output files receive the tables and charts produced by
1305 statistical procedures.  The output files may be in any number of formats,
1306 depending on how PSPP is configured.
1307
1308 @cindex active file
1309 @cindex file, active
1310 @item active file
1311 The active file is the ``file'' on which all PSPP procedures are
1312 performed.  The active file consists of a dictionary and a set of cases.
1313 The active file is not necessarily a disk file: it is stored in memory
1314 if there is room.
1315
1316 @cindex system file
1317 @cindex file, system
1318 @item system file
1319 System files are binary files that store a dictionary and a set of
1320 cases.  @cmd{GET} and @cmd{SAVE} read and write system files.
1321
1322 @cindex portable file
1323 @cindex file, portable
1324 @item portable file
1325 Portable files are files in a text-based format that store a dictionary
1326 and a set of cases.  @cmd{IMPORT} and @cmd{EXPORT} read and write
1327 portable files.
1328
1329 @cindex scratch file
1330 @cindex file, scratch
1331 @item scratch file
1332 Scratch files consist of a dictionary and cases and may be stored in
1333 memory or on disk.  Most procedures that act on a system file or
1334 portable file can use a scratch file instead.  The contents of scratch
1335 files persist within a single PSPP session only.  @cmd{GET} and
1336 @cmd{SAVE} can be used to read and write scratch files.  Scratch files
1337 are a PSPP extension.
1338 @end table
1339
1340 @node File Handles
1341 @section File Handles
1342 @cindex file handles
1343
1344 A @dfn{file handle} is a reference to a data file, system file, portable
1345 file, or scratch file.  Most often, a file handle is specified as the
1346 name of a file as a string, that is, enclosed within @samp{'} or
1347 @samp{"}.
1348
1349 A file name string that begins or ends with @samp{|} is treated as the
1350 name of a command to pipe data to or from.  You can use this feature
1351 to read data over the network using a program such as @samp{curl}
1352 (e.g.@: @code{GET '|curl -s -S http://example.com/mydata.sav'}), to
1353 read compressed data from a file using a program such as @samp{zcat}
1354 (e.g.@: @code{GET '|zcat mydata.sav.gz'}), and for many other
1355 purposes.
1356
1357 PSPP also supports declaring named file handles with the @cmd{FILE
1358 HANDLE} command.  This command associates an identifier of your choice
1359 (the file handle's name) with a file.  Later, the file handle name can
1360 be substituted for the name of the file.  When PSPP syntax accesses a
1361 file multiple times, declaring a named file handle simplifies updating
1362 the syntax later to use a different file.  Use of @cmd{FILE HANDLE} is
1363 also required to read data files in binary formats.  @xref{FILE HANDLE},
1364 for more information.
1365
1366 PSPP assumes that a file handle name that begins with @samp{#} refers to
1367 a scratch file, unless the name has already been declared on @cmd{FILE
1368 HANDLE} to refer to another kind of file.  A scratch file is similar to
1369 a system file, except that it persists only for the duration of a given
1370 PSPP session.  Most commands that read or write a system or portable
1371 file, such as @cmd{GET} and @cmd{SAVE}, also accept scratch file
1372 handles.  Scratch file handles may also be declared explicitly with
1373 @cmd{FILE HANDLE}.  Scratch files are a PSPP extension.
1374
1375 In some circumstances, PSPP must distinguish whether a file handle
1376 refers to a system file or a portable file.  When this is necessary to
1377 read a file, e.g.@: as an input file for @cmd{GET} or @cmd{MATCH FILES},
1378 PSPP uses the file's contents to decide.  In the context of writing a
1379 file, e.g.@: as an output file for @cmd{SAVE} or @cmd{AGGREGATE}, PSPP
1380 decides based on the file's name: if it ends in @samp{.por} (with any
1381 capitalization), then PSPP writes a portable file; otherwise, PSPP
1382 writes a system file.
1383
1384 INLINE is reserved as a file handle name.  It refers to the ``data
1385 file'' embedded into the syntax file between @cmd{BEGIN DATA} and
1386 @cmd{END DATA}.  @xref{BEGIN DATA}, for more information.
1387
1388 The file to which a file handle refers may be reassigned on a later
1389 @cmd{FILE HANDLE} command if it is first closed using @cmd{CLOSE FILE
1390 HANDLE}.  The @cmd{CLOSE FILE HANDLE} command is also useful to free the
1391 storage associated with a scratch file.  @xref{CLOSE FILE HANDLE}, for
1392 more information.
1393
1394 @node BNF
1395 @section Backus-Naur Form
1396 @cindex BNF
1397 @cindex Backus-Naur Form
1398 @cindex command syntax, description of
1399 @cindex description of command syntax
1400
1401 The syntax of some parts of the PSPP language is presented in this
1402 manual using the formalism known as @dfn{Backus-Naur Form}, or BNF. The
1403 following table describes BNF:
1404
1405 @itemize @bullet
1406 @cindex keywords
1407 @cindex terminals
1408 @item
1409 Words in all-uppercase are PSPP keyword tokens.  In BNF, these are
1410 often called @dfn{terminals}.  There are some special terminals, which
1411 are written in lowercase for clarity:
1412
1413 @table @asis
1414 @cindex @code{number}
1415 @item @code{number}
1416 A real number.
1417
1418 @cindex @code{integer}
1419 @item @code{integer}
1420 An integer number.
1421
1422 @cindex @code{string}
1423 @item @code{string}
1424 A string.
1425
1426 @cindex @code{var-name}
1427 @item @code{var-name}
1428 A single variable name.
1429
1430 @cindex operators
1431 @cindex punctuators
1432 @item @code{=}, @code{/}, @code{+}, @code{-}, etc.
1433 Operators and punctuators.
1434
1435 @cindex @code{.}
1436 @item @code{.}
1437 The end of the command.  This is not necessarily an actual dot in the
1438 syntax file: @xref{Commands}, for more details.
1439 @end table
1440
1441 @item
1442 @cindex productions
1443 @cindex nonterminals
1444 Other words in all lowercase refer to BNF definitions, called
1445 @dfn{productions}.  These productions are also known as
1446 @dfn{nonterminals}.  Some nonterminals are very common, so they are
1447 defined here in English for clarity:
1448
1449 @table @code
1450 @cindex @code{var-list}
1451 @item var-list
1452 A list of one or more variable names or the keyword @code{ALL}.
1453
1454 @cindex @code{expression}
1455 @item expression
1456 An expression.  @xref{Expressions}, for details.
1457 @end table
1458
1459 @item
1460 @cindex ``is defined as''
1461 @cindex productions
1462 @samp{::=} means ``is defined as''.  The left side of @samp{::=} gives
1463 the name of the nonterminal being defined.  The right side of @samp{::=}
1464 gives the definition of that nonterminal.  If the right side is empty,
1465 then one possible expansion of that nonterminal is nothing.  A BNF
1466 definition is called a @dfn{production}.
1467
1468 @item
1469 @cindex terminals and nonterminals, differences
1470 So, the key difference between a terminal and a nonterminal is that a
1471 terminal cannot be broken into smaller parts---in fact, every terminal
1472 is a single token (@pxref{Tokens}).  On the other hand, nonterminals are
1473 composed of a (possibly empty) sequence of terminals and nonterminals.
1474 Thus, terminals indicate the deepest level of syntax description.  (In
1475 parsing theory, terminals are the leaves of the parse tree; nonterminals
1476 form the branches.)
1477
1478 @item
1479 @cindex start symbol
1480 @cindex symbol, start
1481 The first nonterminal defined in a set of productions is called the
1482 @dfn{start symbol}.  The start symbol defines the entire syntax for
1483 that command.
1484 @end itemize