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