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