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