Table of Contents ***************** GNU PSPP 1 Introduction 2 Your rights and obligations 3 Invoking PSPP 3.1 Non-option Arguments 3.2 Configuration Options 3.3 Input and output options 3.4 Language control options 3.5 Informational options 4 The PSPP language 4.1 Tokens 4.2 Forming commands of tokens 4.3 Types of Commands 4.4 Order of Commands 4.5 Handling missing observations 4.6 Variables 4.6.1 Attributes of Variables 4.6.2 Variables Automatically Defined by PSPP 4.6.3 Lists of variable names 4.6.4 Input and Output Formats 4.6.4.1 Basic Numeric Formats 4.6.4.2 Custom Currency Formats 4.6.4.3 Legacy Numeric Formats 4.6.4.4 Binary and Hexadecimal Numeric Formats 4.6.4.5 Time and Date Formats 4.6.4.6 Date Component Formats 4.6.4.7 String Formats 4.6.5 Scratch Variables 4.7 Files Used by PSPP 4.8 File Handles 4.9 Backus-Naur Form 5 Mathematical Expressions 5.1 Boolean Values 5.2 Missing Values in Expressions 5.3 Grouping Operators 5.4 Arithmetic Operators 5.5 Logical Operators 5.6 Relational Operators 5.7 Functions 5.7.1 Mathematical Functions 5.7.2 Miscellaneous Mathematical Functions 5.7.3 Trigonometric Functions 5.7.4 Missing-Value Functions 5.7.5 Set-Membership Functions 5.7.6 Statistical Functions 5.7.7 String Functions 5.7.8 Time & Date Functions 5.7.8.1 How times & dates are defined and represented 5.7.8.2 Functions that Produce Times 5.7.8.3 Functions that Examine Times 5.7.8.4 Functions that Produce Dates 5.7.8.5 Functions that Examine Dates 5.7.8.6 Time and Date Arithmetic 5.7.9 Miscellaneous Functions 5.7.10 Statistical Distribution Functions 5.7.10.1 Continuous Distributions 5.7.10.2 Discrete Distributions 5.8 Operator Precedence 6 Data Input and Output 6.1 BEGIN DATA 6.2 CLEAR TRANSFORMATIONS 6.3 CLOSE FILE HANDLE 6.4 DATA LIST 6.4.1 DATA LIST FIXED Examples 6.4.2 DATA LIST FREE 6.4.3 DATA LIST LIST 6.5 END CASE 6.6 END FILE 6.7 FILE HANDLE 6.8 INPUT PROGRAM 6.9 LIST 6.10 NEW FILE 6.11 PRINT 6.12 PRINT EJECT 6.13 PRINT SPACE 6.14 REREAD 6.15 REPEATING DATA 6.16 WRITE 7 System Files and Portable Files 7.1 APPLY DICTIONARY 7.2 EXPORT 7.3 GET 7.4 IMPORT 7.5 MATCH FILES 7.6 SAVE 7.7 SYSFILE INFO 7.8 XEXPORT 7.9 XSAVE 8 Manipulating variables 8.1 ADD VALUE LABELS 8.2 DELETE VARIABLES 8.3 DISPLAY 8.4 DISPLAY VECTORS 8.5 FORMATS 8.6 LEAVE 8.7 MISSING VALUES 8.8 MODIFY VARS 8.9 NUMERIC 8.10 PRINT FORMATS 8.11 RENAME VARIABLES 8.12 VALUE LABELS 8.13 STRING 8.14 VARIABLE LABELS 8.15 VARIABLE ALIGNMENT 8.16 VARIABLE WIDTH 8.17 VARIABLE LEVEL 8.18 VECTOR 8.19 WRITE FORMATS 9 Data transformations 9.1 AGGREGATE 9.2 AUTORECODE 9.3 COMPUTE 9.4 COUNT 9.5 FLIP 9.6 IF 9.7 RECODE 9.8 SORT CASES 10 Selecting data for analysis 10.1 FILTER 10.2 N OF CASES 10.3 SAMPLE 10.4 SELECT IF 10.5 SPLIT FILE 10.6 TEMPORARY 10.7 WEIGHT 11 Conditional and Looping Constructs 11.1 BREAK 11.2 DO IF 11.3 DO REPEAT 11.4 LOOP 12 Statistics 12.1 DESCRIPTIVES 12.2 FREQUENCIES 12.3 EXAMINE 12.4 CROSSTABS 12.5 NPAR TESTS 12.5.1 Binomial test 12.5.2 Chisquare test 12.6 T-TEST 12.6.1 One Sample Mode 12.6.2 Independent Samples Mode 12.6.3 Paired Samples Mode 12.7 ONEWAY 12.8 RANK 12.9 REGRESSION 12.9.1 Syntax 12.9.2 Examples 13 Utilities 13.1 ADD DOCUMENT 13.2 CD 13.3 COMMENT 13.4 DOCUMENT 13.5 DISPLAY DOCUMENTS 13.6 DISPLAY FILE LABEL 13.7 DROP DOCUMENTS 13.8 ECHO 13.9 ERASE 13.10 EXECUTE 13.11 FILE LABEL 13.12 FINISH 13.13 HOST 13.14 INCLUDE 13.15 PERMISSIONS 13.16 SET 13.17 SHOW 13.18 SUBTITLE 13.19 TITLE 14 Not Implemented 15 Bugs 16 Function Index 17 Command Index 18 Concept Index Appendix A Configuring PSPP A.1 Locating configuration files A.2 Configuration techniques A.3 Configuration files A.4 Environment variables A.4.1 Environment substitutions A.4.2 Predefined environment variables A.5 Output devices A.5.1 Driver categories A.5.2 Macro definitions A.5.3 Driver definitions A.5.4 Dimensions A.5.5 Paper sizes A.5.6 How lines are divided into types A.5.7 How lines are divided into tokens A.6 The PostScript driver class A.7 The ASCII driver class A.8 The HTML driver class A.9 Miscellaneous configuration Appendix B Portable File Format B.1 Portable File Characters B.2 Portable File Structure B.3 Portable File Header B.4 Version and Date Info Record B.5 Identification Records B.6 Variable Count Record B.7 Case Weight Variable Record B.8 Variable Records B.9 Value Label Records B.10 Document Record B.11 Portable File Data Appendix C System File Format C.1 File Header Record C.2 Variable Record C.3 Value Labels Records C.4 Document Record C.5 Machine Integer Info Record C.6 Machine Floating-Point Info Record C.7 Variable Display Parameter Record C.8 Long Variable Names Record C.9 Very Long String Record C.10 Miscellaneous Informational Records C.11 Dictionary Termination Record C.12 Data Record Appendix D `q2c' Input Format D.1 Invoking q2c D.2 `q2c' Input Structure D.3 Grammar Rules Appendix E GNU Free Documentation License E.1 ADDENDUM: How to use this License for your documents GNU PSPP ******** This manual is for GNU PSPP version 0.4.3, software for statistical analysis. Copyright (C) 1997, 1998, 2004, 2005 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being "A GNU Manual," and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled "GNU Free Documentation License." (a) The FSF's Back-Cover Text is: "You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development." 1 Introduction ************** PSPP is a tool for statistical analysis of sampled data. It reads a syntax file and a data file, analyzes the data, and writes the results to a listing file or to standard output. The language accepted by PSPP is similar to those accepted by SPSS statistical products. The details of PSPP's language are given later in this manual. PSPP produces output in two forms: tables and charts. Both of these can be written in several formats; currently, ASCII, PostScript, and HTML are supported. In the future, more drivers, such as PCL and X Window System drivers, may be developed. For now, Ghostscript, available from the Free Software Foundation, may be used to convert PostScript chart output to other formats. The current version of PSPP, 0.4.3, is woefully incomplete in terms of its statistical procedure support. PSPP is a work in progress. The author hopes to support fully support all features in the products that PSPP replaces, eventually. The author welcomes questions, comments, donations, and code submissions. *Note Submitting Bug Reports: Bugs, for instructions on contacting the author. 2 Your rights and obligations ***************************** PSPP is not in the public domain. It is copyrighted and there are restrictions on its distribution, but these restrictions are designed to permit everything that a good cooperating citizen would want to do. What is not allowed is to try to prevent others from further sharing any version of this program that they might get from you. Specifically, we want to make sure that you have the right to give away copies of PSPP, that you receive source code or else can get it if you want it, that you can change these programs or use pieces of them in new free programs, and that you know you can do these things. To make sure that everyone has such rights, we have to forbid you to deprive anyone else of these rights. For example, if you distribute copies of PSPP, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. Also, for our own protection, we must make certain that everyone finds out that there is no warranty for PSPP. If these programs are modified by someone else and passed on, we want their recipients to know that what they have is not what we distributed, so that any problems introduced by others will not reflect on our reputation. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise conditions of the license for PSPP are found in the GNU General Public License. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. This manual specifically is covered by the GNU Free Documentation License (*note GNU Free Documentation License::). 3 Invoking PSPP *************** pspp [ -B DIR | --config-dir=DIR ] [ -o DEVICE | --device=DEVICE ] [ -d VAR[=VALUE] | --define=VAR[=VALUE] ] [-u VAR | --undef=VAR ] [ -f FILE | --out-file=FILE ] [ -p | --pipe ] [ -I- | --no-include ] [ -I DIR | --include=DIR ] [ -i | --interactive ] [ -n | --edit | --dry-run | --just-print | --recon ] [ -r | --no-statrc ] [ -h | --help ] [ -l | --list ] [ -c COMMAND | --command COMMAND ] [ -s | --safer ] [ --testing-mode ] [ -V | --version ] [ -v | --verbose ] [ KEY=VALUE ] FILE.... 3.1 Non-option Arguments ======================== Syntax files and output device substitutions can be specified on PSPP's command line: `FILE' A file by itself on the command line will be executed as a syntax file. If multiple files may be specified, they are executed in order, as if their contents had been given in a single file. PSPP terminates after the syntax files run, unless the `-i' or `--interactive' option is given (*note Language control options::). `KEY=VALUE' Defines an output device macro KEY to expand to VALUE, overriding any macro having the same KEY defined in the device configuration file. *Note Macro definitions::. There is one other way to specify a syntax file, if your operating system supports it. If you have a syntax file `foobar.stat', put the notation #! /usr/local/bin/pspp at the top, and mark the file as executable with `chmod +x foobar.stat'. (If PSPP is not installed in `/usr/local/bin', then insert its actual installation directory into the syntax file instead.) Now you should be able to invoke the syntax file just by typing its name. You can include any options on the command line as usual. PSPP entirely ignores any lines beginning with `#!'. 3.2 Configuration Options ========================= Configuration options are used to change PSPP's configuration for the current run. The configuration options are: `-a {compatible|enhanced}' `--algorithm={compatible|enhanced}' If you chose `compatible', then PSPP will use the same algorithms as used by some proprietary statistical analysis packages. This is not recommended, as these algorithms are inferior and in some cases compeletely broken. The default setting is `enhanced'. Certain commands have subcommands which allow you to override this setting on a per command basis. `-B DIR' `--config-dir=DIR' Sets the configuration directory to DIR. *Note File locations::. `-o DEVICE' `--device=DEVICE' Selects the output device with name DEVICE. If this option is given more than once, then all devices mentioned are selected. This option disables all devices besides those mentioned on the command line. 3.3 Input and output options ============================ Input and output options affect how PSPP reads input and writes output. These are the input and output options: `-f FILE' `--out-file=FILE' This overrides the output file name for devices designated as listing devices. If a file named FILE already exists, it is overwritten. `-p' `--pipe' Allows PSPP to be used as a filter by causing the syntax file to be read from stdin and output to be written to stdout. Conflicts with the `-f FILE' and `--file=FILE' options. `-I-' `--no-include' Clears all directories from the include path. This includes all directories put in the include path by default. *Note Miscellaneous configuring::. `-I DIR' `--include=DIR' Appends directory DIR to the path that is searched for include files in PSPP syntax files. `-c COMMAND' `--command=COMMAND' Execute literal command COMMAND. The command is executed before startup syntax files, if any. `--testing-mode' Invoke heuristics to assist with testing PSPP. For use by `make check' and similar scripts. 3.4 Language control options ============================ Language control options control how PSPP syntax files are parsed and interpreted. The available language control options are: `-i' `--interactive' When a syntax file is specified on the command line, PSPP normally terminates after processing it. Giving this option will cause PSPP to bring up a command prompt after processing the syntax file. In addition, this forces syntax files to be interpreted in interactive mode, rather than the default batch mode. *Note Tokenizing lines::, for information on the differences between batch mode and interactive mode command interpretation. `-n' `--edit' `--dry-run' `--just-print' `--recon' Only the syntax of any syntax file specified or of commands entered at the command line is checked. Transformations are not performed and procedures are not executed. Not yet implemented. `-r' `--no-statrc' Prevents the execution of the PSPP startup syntax file. `-s' `--safer' Disables certain unsafe operations. This includes the ERASE and HOST commands, as well as use of pipes as input and output files. 3.5 Informational options ========================= Informational options cause information about PSPP to be written to the terminal. Here are the available options: `-h' `--help' Prints a message describing PSPP command-line syntax and the available device driver classes, then terminates. `-l' `--list' Lists the available device driver classes, then terminates. `-x {compatible|enhanced}' `--syntax={compatible|enhanced}' If you chose `compatible', then PSPP will only accept command syntax that is compatible with the proprietary program SPSS. If you choose `enhanced' then additional syntax will be available. The default is `enhanced'. `-V' `--version' Prints a brief message listing PSPP's version, warranties you don't have, copying conditions and copyright, and e-mail address for bug reports, then terminates. `-v' `--verbose' Increments PSPP's verbosity level. Higher verbosity levels cause PSPP to display greater amounts of information about what it is doing. Often useful for debugging PSPP's configuration. This option can be given multiple times to set the verbosity level to that value. The default verbosity level is 0, in which no informational messages will be displayed. Higher verbosity levels cause messages to be displayed when the corresponding events take place. 1 Driver and subsystem initializations. 2 Completion of driver initializations. Beginning of driver closings. 3 Completion of driver closings. 4 Files searched for; success of searches. 5 Individual directories included in file searches. Each verbosity level also includes messages from lower verbosity levels. 4 The PSPP language ******************* *Please note:* PSPP is not even close to completion. Only a few statistical procedures are implemented. PSPP is a work in progress. This chapter discusses elements common to many PSPP commands. Later chapters will describe individual commands in detail. 4.1 Tokens ========== PSPP divides most syntax file lines into series of short chunks called "tokens". Tokens are then grouped to form commands, each of which tells PSPP to take some action--read in data, write out data, perform a statistical procedure, etc. Each type of token is described below. *Identifiers* Identifiers are names that typically specify variables, commands, or subcommands. The first character in an identifier must be a letter, `#', or `@'. The remaining characters in the identifier must be letters, digits, or one of the following special characters: . _ $ # @ Identifiers may be any length, but only the first 64 bytes are significant. Identifiers are not case-sensitive: `foobar', `Foobar', `FooBar', `FOOBAR', and `FoObaR' are different representations of the same identifier. Some identifiers are reserved. Reserved identifiers may not be used in any context besides those explicitly described in this manual. The reserved identifiers are: ALL AND BY EQ GE GT LE LT NE NOT OR TO WITH *Keywords* Keywords are a subclass of identifiers that form a fixed part of command syntax. For example, command and subcommand names are keywords. Keywords may be abbreviated to their first 3 characters if this abbreviation is unambiguous. (Unique abbreviations of 3 or more characters are also accepted: `FRE', `FREQ', and `FREQUENCIES' are equivalent when the last is a keyword.) Reserved identifiers are always used as keywords. Other identifiers may be used both as keywords and as user-defined identifiers, such as variable names. *Numbers* Numbers are expressed in decimal. A decimal point is optional. Numbers may be expressed in scientific notation by adding `e' and a base-10 exponent, so that `1.234e3' has the value 1234. Here are some more examples of valid numbers: -5 3.14159265359 1e100 -.707 8945. Negative numbers are expressed with a `-' prefix. However, in situations where a literal `-' token is expected, what appears to be a negative number is treated as `-' followed by a positive number. No white space is allowed within a number token, except for horizontal white space between `-' and the rest of the number. The last example above, `8945.' will be interpreted as two tokens, `8945' and `.', if it is the last token on a line. *Note Forming commands of tokens: Commands. *Strings* Strings are literal sequences of characters enclosed in pairs of single quotes (`'') or double quotes (`"'). To include the character used for quoting in the string, double it, e.g. `'it''s an apostrophe''. White space and case of letters are significant inside strings. Strings can be concatenated using `+', so that `"a" + 'b' + 'c'' is equivalent to `'abc''. Concatenation is useful for splitting a single string across multiple source lines. The maximum length of a string, after concatenation, is 255 characters. Strings may also be expressed as hexadecimal, octal, or binary character values by prefixing the initial quote character by `X', `O', or `B' or their lowercase equivalents. Each pair, triplet, or octet of characters, according to the radix, is transformed into a single character with the given value. If there is an incomplete group of characters, the missing final digits are assumed to be `0'. These forms of strings are nonportable because numeric values are associated with different characters by different operating systems. Therefore, their use should be confined to syntax files that will not be widely distributed. The character with value 00 is reserved for internal use by PSPP. Its use in strings causes an error and replacement by a space character. *Punctuators and Operators* These tokens are the punctuators and operators: , / = ( ) + - * / ** < <= <> > >= ~= & | . Most of these appear within the syntax of commands, but the period (`.') punctuator is used only at the end of a command. It is a punctuator only as the last character on a line (except white space). When it is the last non-space character on a line, a period is not treated as part of another token, even if it would otherwise be part of, e.g., an identifier or a floating-point number. Actually, the character that ends a command can be changed with SET's ENDCMD subcommand (*note SET::), but we do not recommend doing so. Throughout the remainder of this manual we will assume that the default setting is in effect. 4.2 Forming commands of tokens ============================== Most PSPP commands share a common structure. A command begins with a command name, such as FREQUENCIES, DATA LIST, or N OF CASES. The command name may be abbreviated to its first word, and each word in the command name may be abbreviated to its first three or more characters, where these abbreviations are unambiguous. The command name may be followed by one or more "subcommands". Each subcommand begins with a subcommand name, which may be abbreviated to its first three letters. Some subcommands accept a series of one or more specifications, which follow the subcommand name, optionally separated from it by an equals sign (`='). Specifications may be separated from each other by commas or spaces. Each subcommand must be separated from the next (if any) by a forward slash (`/'). There are multiple ways to mark the end of a command. The most common way is to end the last line of the command with a period (`.') as described in the previous section (*note Tokens::). A blank line, or one that consists only of white space or comments, also ends a command by default, although you can use the NULLINE subcommand of SET to disable this feature (*note SET::). In batch mode only, that is, when reading commands from a file instead of an interactive user, any line that contains a non-space character in the leftmost column begins a new command. Thus, each command consists of a flush-left line followed by any number of lines indented from the left margin. In this mode, a plus or minus sign (`+', `-') as the first character in a line is ignored and causes that line to begin a new command, which allows for visual indentation of a command without that command being considered part of the previous command. 4.3 Types of Commands ===================== Commands in PSPP are divided roughly into six categories: *Utility commands* Set or display various global options that affect PSPP operations. May appear anywhere in a syntax file. *Note Utility commands: Utilities. *File definition commands* Give instructions for reading data from text files or from special binary "system files". Most of these commands replace any previous data or variables with new data or variables. At least one file definition command must appear before the first command in any of the categories below. *Note Data Input and Output::. *Input program commands* Though rarely used, these provide tools for reading data files in arbitrary textual or binary formats. *Note INPUT PROGRAM::. *Transformations* Perform operations on data and write data to output files. Transformations are not carried out until a procedure is executed. *Restricted transformations* Transformations that cannot appear in certain contexts. *Note Order of Commands::, for details. *Procedures* Analyze data, writing results of analyses to the listing file. Cause transformations specified earlier in the file to be performed. In a more general sense, a "procedure" is any command that causes the active file (the data) to be read. 4.4 Order of Commands ===================== PSPP does not place many restrictions on ordering of commands. The main restriction is that variables must be defined before they are otherwise referenced. This section describes the details of command ordering, but most users will have no need to refer to them. PSPP possesses five internal states, called initial, INPUT PROGRAM, FILE TYPE, transformation, and procedure states. (Please note the distinction between the INPUT PROGRAM and FILE TYPE _commands_ and the INPUT PROGRAM and FILE TYPE _states_.) PSPP starts in the initial state. Each successful completion of a command may cause a state transition. Each type of command has its own rules for state transitions: *Utility commands* * Valid in any state. * Do not cause state transitions. Exception: when N OF CASES is executed in the procedure state, it causes a transition to the transformation state. *DATA LIST* * Valid in any state. * When executed in the initial or procedure state, causes a transition to the transformation state. * Clears the active file if executed in the procedure or transformation state. *INPUT PROGRAM* * Invalid in INPUT PROGRAM and FILE TYPE states. * Causes a transition to the INPUT PROGRAM state. * Clears the active file. *FILE TYPE* * Invalid in INPUT PROGRAM and FILE TYPE states. * Causes a transition to the FILE TYPE state. * Clears the active file. *Other file definition commands* * Invalid in INPUT PROGRAM and FILE TYPE states. * Cause a transition to the transformation state. * Clear the active file, except for ADD FILES, MATCH FILES, and UPDATE. *Transformations* * Invalid in initial and FILE TYPE states. * Cause a transition to the transformation state. *Restricted transformations* * Invalid in initial, INPUT PROGRAM, and FILE TYPE states. * Cause a transition to the transformation state. *Procedures* * Invalid in initial, INPUT PROGRAM, and FILE TYPE states. * Cause a transition to the procedure state. 4.5 Handling missing observations ================================= PSPP includes special support for unknown numeric data values. Missing observations are assigned a special value, called the "system-missing value". This "value" actually indicates the absence of a value; it means that the actual value is unknown. Procedures automatically exclude from analyses those observations or cases that have missing values. Details of missing value exclusion depend on the procedure and can often be controlled by the user; refer to descriptions of individual procedures for details. The system-missing value exists only for numeric variables. String variables always have a defined value, even if it is only a string of spaces. Variables, whether numeric or string, can have designated "user-missing values". Every user-missing value is an actual value for that variable. However, most of the time user-missing values are treated in the same way as the system-missing value. String variables that are wider than a certain width, usually 8 characters (depending on computer architecture), cannot have user-missing values. For more information on missing values, see the following sections: *Note Variables::, *Note MISSING VALUES::, *Note Expressions::. See also the documentation on individual procedures for information on how they handle missing values. 4.6 Variables ============= Variables are the basic unit of data storage in PSPP. All the variables in a file taken together, apart from any associated data, are said to form a "dictionary". Some details of variables are described in the sections below. 4.6.1 Attributes of Variables ----------------------------- Each variable has a number of attributes, including: *Name* An identifier, up to 64 bytes long. Each variable must have a different name. *Note Tokens::. Some system variable names begin with `$', but user-defined variables' names may not begin with `$'. The final character in a variable name should not be `.', because such an identifier will be misinterpreted when it is the final token on a line: `FOO.' will be divided into two separate tokens, `FOO' and `.', indicating end-of-command. *Note Tokens::. The final character in a variable name should not be `_', because some such identifiers are used for special purposes by PSPP procedures. As with all PSPP identifiers, variable names are not case-sensitive. PSPP capitalizes variable names on output the same way they were capitalized at their point of definition in the input. *Type* Numeric or string. *Width* (string variables only) String variables with a width of 8 characters or fewer are called "short string variables". Short string variables can be used in many procedures where "long string variables" (those with widths greater than 8) are not allowed. Certain systems may consider strings longer than 8 characters to be short strings. Eight characters represents a minimum figure for the maximum length of a short string. *Position* Variables in the dictionary are arranged in a specific order. DISPLAY can be used to show this order: see *Note DISPLAY::. *Initialization* Either reinitialized to 0 or spaces for each case, or left at its existing value. *Note LEAVE::. *Missing values* Optionally, up to three values, or a range of values, or a specific value plus a range, can be specified as "user-missing values". There is also a "system-missing value" that is assigned to an observation when there is no other obvious value for that observation. Observations with missing values are automatically excluded from analyses. User-missing values are actual data values, while the system-missing value is not a value at all. *Note Missing Observations::. *Variable label* A string that describes the variable. *Note VARIABLE LABELS::. *Value label* Optionally, these associate each possible value of the variable with a string. *Note VALUE LABELS::. *Print format* Display width, format, and (for numeric variables) number of decimal places. This attribute does not affect how data are stored, just how they are displayed. Example: a width of 8, with 2 decimal places. *Note Input and Output Formats::. *Write format* Similar to print format, but used by the WRITE command (*note WRITE::). 4.6.2 Variables Automatically Defined by PSPP --------------------------------------------- There are seven system variables. These are not like ordinary variables because system variables are not always stored. They can be used only in expressions. These system variables, whose values and output formats cannot be modified, are described below. `$CASENUM' Case number of the case at the moment. This changes as cases are shuffled around. `$DATE' Date the PSPP process was started, in format A9, following the pattern `DD MMM YY'. `$JDATE' Number of days between 15 Oct 1582 and the time the PSPP process was started. `$LENGTH' Page length, in lines, in format F11. `$SYSMIS' System missing value, in format F1. `$TIME' Number of seconds between midnight 14 Oct 1582 and the time the active file was read, in format F20. `$WIDTH' Page width, in characters, in format F3. 4.6.3 Lists of variable names ----------------------------- To refer to a set of variables, list their names one after another. Optionally, their names may be separated by commas. To include a range of variables from the dictionary in the list, write the name of the first and last variable in the range, separated by `TO'. For instance, if the dictionary contains six variables with the names `ID', `X1', `X2', `GOAL', `MET', and `NEXTGOAL', in that order, then `X2 TO MET' would include variables `X2', `GOAL', and `MET'. Commands that define variables, such as DATA LIST, give `TO' an alternate meaning. With these commands, `TO' define sequences of variables whose names end in consecutive integers. The syntax is two identifiers that begin with the same root and end with numbers, separated by `TO'. The syntax `X1 TO X5' defines 5 variables, named `X1', `X2', `X3', `X4', and `X5'. The syntax `ITEM0008 TO ITEM0013' defines 6 variables, named `ITEM0008', `ITEM0009', `ITEM0010', `ITEM0011', `ITEM0012', and `ITEM00013'. The syntaxes `QUES001 TO QUES9' and `QUES6 TO QUES3' are invalid. After a set of variables has been defined with DATA LIST or another command with this method, the same set can be referenced on later commands using the same syntax. 4.6.4 Input and Output Formats ------------------------------ An "input format" describes how to interpret the contents of an input field as a number or a string. It might specify that the field contains an ordinary decimal number, a time or date, a number in binary or hexadecimal notation, or one of several other notations. Input formats are used by commands such as DATA LIST that read data or syntax files into the PSPP active file. Every input format corresponds to a default "output format" that specifies the formatting used when the value is output later. It is always possible to explicitly specify an output format that resembles the input format. Usually, this is the default, but in cases where the input format is unfriendly to human readability, such as binary or hexadecimal formats, the default output format is an easier-to-read decimal format. Every variable has two output formats, called its "print format" and "write format". Print formats are used in most output contexts; write formats are used only by WRITE (*note WRITE::). Newly created variables have identical print and write formats, and FORMATS, the most commonly used command for changing formats (*note FORMATS::), sets both of them to the same value as well. Thus, most of the time, the distinction between print and write formats is unimportant. Input and output formats are specified to PSPP with a "format specification" of the form `TYPEw' or `TYPEw.d', where `TYPE' is one of the format types described later, `w' is a field width measured in columns, and `d' is an optional number of decimal places. If `d' is omitted, a value of 0 is assumed. Some formats do not allow a nonzero `d' to be specified. The following sections describe the input and output formats supported by PSPP. 4.6.4.1 Basic Numeric Formats ............................. The basic numeric formats are used for input and output of real numbers in standard or scientific notation. The following table shows an example of how each format displays positive and negative numbers with the default decimal point setting: Format ` 3141.59' `-3141.59' ------------------------------------------- F8.2 ` 3141.59' `-3141.59' COMMA9.2 ` 3,141.59' `-3,141.59' DOT9.2 ` 3.141,59' `-3.141,59' DOLLAR10.2 ` $3,141.59' `-$3,141.59' PCT9.2 ` 3141.59%' `-3141.59%' E8.1 ` 3.1E+003' `-3.1E+003' On output, numbers in F format are expressed in standard decimal notation with the requested number of decimal places. The other formats output some variation on this style: * Numbers in COMMA format are additionally grouped every three digits by inserting a grouping character. The grouping character is ordinarily a comma, but it can be changed to a period (*note SET DECIMAL::). * DOT format is like COMMA format, but it interchanges the role of the decimal point and grouping characters. That is, the current grouping character is used as a decimal point and vice versa. * DOLLAR format is like COMMA format, but it prefixes the number with `$'. * PCT format is like F format, but adds `%' after the number. * The E format always produces output in scientific notation. On input, the basic numeric formats accept positive and numbers in standard decimal notation or scientific notation. Leading and trailing spaces are allowed. An empty or all-spaces field, or one that contains only a single period, is treated as the system missing value. In scientific notation, the exponent may be introduced by a sign (`+' or `-'), or by one of the letters `e' or `d' (in uppercase or lowercase), or by a letter followed by a sign. A single space may follow the letter or the sign or both. On fixed-format DATA LIST (*note DATA LIST FIXED::) and in a few other contexts, decimals are implied when the field does not contain a decimal point. In F6.5 format, for example, the field `314159' is taken as the value 3.14159 with implied decimals. Decimals are never implied if an explicit decimal point is present or if scientific notation is used. E and F formats accept the basic syntax already described. The other formats allow some additional variations: * COMMA, DOLLAR, and DOT formats ignore grouping characters within the integer part of the input field. The identity of the grouping character depends on the format. * DOLLAR format allows a dollar sign to precede the number. In a negative number, the dollar sign may precede or follow the minus sign. * PCT format allows a percent sign to follow the number. All of the basic number formats have a maximum field width of 40 and accept no more than 16 decimal places, on both input and output. Some additional restrictions apply: * As input formats, the basic numeric formats allow no more decimal places than the field width. As output formats, the field width must be greater than the number of decimal places; that is, large enough to allow for a decimal point and the number of requested decimal places. DOLLAR and PCT formats must allow an additional column for `$' or `%'. * The default output format for a given input format increases the field width enough to make room for optional input characters. If an input format calls for decimal places, the width is increased by 1 to make room for an implied decimal point. COMMA, DOT, and DOLLAR formats also increase the output width to make room for grouping characters. DOLLAR and PCT further increase the output field width by 1 to make room for `$' or `%'. The increased output width is capped at 40, the maximum field width. * The E format is exceptional. For output, E format has a minimum width of 7 plus the number of decimal places. The default output format for an E input format is an E format with at least 3 decimal places and thus a minimum width of 10. More details of basic numeric output formatting are given below: * Output rounds to nearest, with ties rounded away from zero. Thus, 2.5 is output as `3' in F1.0 format, and -1.125 as `-1.13' in F5.1 format. * The system-missing value is output as a period in a field of spaces, placed in the decimal point's position, or in the rightmost column if no decimal places are requested. A period is used even if the decimal point character is a comma. * A number that does not fill its field is right-justified within the field. * A number is too large for its field causes decimal places to be dropped to make room. If dropping decimals does not make enough room, scientific notation is used if the field is wide enough. If a number does not fit in the field, even in scientific notation, the overflow is indicated by filling the field with asterisks (`*'). * COMMA, DOT, and DOLLAR formats insert grouping characters only if space is available for all of them. Grouping characters are never inserted when all decimal places must be dropped. Thus, 1234.56 in COMMA5.2 format is output as ` 1235' without a comma, even though there is room for one, because all decimal places were dropped. * DOLLAR or PCT format drop the `$' or `%' only if the number would not fit at all without it. Scientific notation with `$' or `%' is preferred to ordinary decimal notation without it. * Except in scientific notation, a decimal point is included only when it is followed by a digit. If the integer part of the number being output is 0, and a decimal point is included, then the zero before the decimal point is dropped. In scientific notation, the number always includes a decimal point, even if it is not followed by a digit. * A negative number includes a minus sign only in the presence of a nonzero digit: -0.01 is output as `-.01' in F4.2 format but as ` .0' in F4.1 format. Thus, a "negative zero" never includes a minus sign. * In negative numbers output in DOLLAR format, the dollar sign follows the negative sign. Thus, -9.99 in DOLLAR6.2 format is output as `-$9.99'. * In scientific notation, the exponent is output as `E' followed by `+' or `-' and exactly three digits. Numbers with magnitude less than 10**-999 or larger than 10**999 are not supported by most computers, but if they are supported then their output is considered to overflow the field and will be output as asterisks. * On most computers, no more than 15 decimal digits are significant in output, even if more are printed. In any case, output precision cannot be any higher than input precision; few data sets are accurate to 15 digits of precision. Unavoidable loss of precision in intermediate calculations may also reduce precision of output. * Special values such as infinities and "not a number" values are usually converted to the system-missing value before printing. In a few circumstances, these values are output directly. In fields of width 3 or greater, special values are output as however many characters will fit from `+Infinity' or `-Infinity' for infinities, from `NaN' for "not a number," or from `Unknown' for other values (if any are supported by the system). In fields under 3 columns wide, special values are output as asterisks. 4.6.4.2 Custom Currency Formats ............................... The custom currency formats are closely related to the basic numeric formats, but they allow users to customize the output format. The SET command configures custom currency formats, using the syntax SET CCX="STRING". where X is A, B, C, D, or E, and STRING is no more than 16 characters long. STRING must contain exactly three commas or exactly three periods (but not both), except that a single quote character may be used to "escape" a following comma, period, or single quote. If three commas are used, commas will be used for grouping in output, and a period will be used as the decimal point. Uses of periods reverses these roles. The commas or periods divide STRING into four fields, called the "negative prefix", "prefix", "suffix", and "negative suffix", respectively. The prefix and suffix are added to output whenever space is available. The negative prefix and negative suffix are always added to a negative number when the output includes a nonzero digit. The following syntax shows how custom currency formats could be used to reproduce basic numeric formats: SET CCA="-,,,". /* Same as COMMA. SET CCB="-...". /* Same as DOT. SET CCC="-,$,,". /* Same as DOLLAR. SET CCD="-,,%,". /* Like PCT, but groups with commas. Here are some more examples of custom currency formats. The final example shows how to use a single quote to escape a delimiter: SET CCA=",EUR,,-". /* Euro. SET CCB="(,USD ,,)". /* US dollar. SET CCC="-.R$..". /* Brazilian real. SET CCD="-,, NIS,". /* Israel shekel. SET CCE="-.Rp'. ..". /* Indonesia Rupiah. These formats would yield the following output: Format ` 3145.59' `-3145.59' ------------------------------------------------ CCA12.2 ` EUR3,145.59' `EUR3,145.59-' CCB14.2 ` USD 3,145.59' `(USD 3,145.59)' CCC11.2 ` R$3.145,59' `-R$3.145,59' CCD13.2 ` 3,145.59 NIS' `-3,145.59 NIS' CCE10.0 ` Rp. 3.146' `-Rp. 3.146' The default for all the custom currency formats is `-,,,', equivalent to COMMA format. 4.6.4.3 Legacy Numeric Formats .............................. The N and Z numeric formats provide compatibility with legacy file formats. They have much in common: * Output is rounded to the nearest representable value, with ties rounded away from zero. * Numbers too large to display are output as a field filled with asterisks (`*'). * The decimal point is always implicitly the specified number of digits from the right edge of the field, except that Z format input allows an explicit decimal point. * Scientific notation may not be used. * The system-missing value is output as a period in a field of spaces. The period is placed just to the right of the implied decimal point in Z format, or at the right end in N format or in Z format if no decimal places are requested. A period is used even if the decimal point character is a comma. * Field width may range from 1 to 40. Decimal places may range from 0 up to the field width, to a maximum of 16. * When a legacy numeric format used for input is converted to an output format, it is changed into the equivalent F format. The field width is increased by 1 if any decimal places are specified, to make room for a decimal point. For Z format, the field width is increased by 1 more column, to make room for a negative sign. The output field width is capped at 40 columns. N Format ........ The N format supports input and output of fields that contain only digits. On input, leading or trailing spaces, a decimal point, or any other non-digit character causes the field to be read as the system-missing value. As a special exception, an N format used on DATA LIST FREE or DATA LIST LIST is treated as the equivalent F format. On output, N pads the field on the left with zeros. Negative numbers are output like the system-missing value. Z Format ........ The Z format is a "zoned decimal" format used on IBM mainframes. Z format encodes the sign as part of the final digit, which must be one of the following: 0123456789 {ABCDEFGHI }JKLMNOPQR where the characters in each row represent digits 0 through 9 in order. Characters in the first two rows indicate a positive sign; those in the third indicate a negative sign. On output, Z fields are padded on the left with spaces. On input, leading and trailing spaces are ignored. Any character in an input field other than spaces, the digit characters above, and `.' causes the field to be read as system-missing. The decimal point character for input and output is always `.', even if the decimal point character is a comma (*note SET DECIMAL::). Nonzero, negative values output in Z format are marked as negative even when no nonzero digits are output. For example, -0.2 is output in Z1.0 format as `J'. The "negative zero" value supported by most machines is output as positive. 4.6.4.4 Binary and Hexadecimal Numeric Formats .............................................. The binary and hexadecimal formats are primarily designed for compatibility with existing machine formats, not for human readability. All of them therefore have a F format as default output format. Some of these formats are only portable between machines with compatible byte ordering (endianness) or floating-point format. Binary formats use byte values that in text files are interpreted as special control functions, such as carriage return and line feed. Thus, data in binary formats should not be included in syntax files or read from data files with variable-length records, such as ordinary text files. They may be read from or written to data files with fixed-length records. *Note FILE HANDLE::, for information on working with fixed-length records. P and PK Formats ................ These are binary-coded decimal formats, in which every byte (except the last, in P format) represents two decimal digits. The most-significant 4 bits of the first byte is the most-significant decimal digit, the least-significant 4 bits of the first byte is the next decimal digit, and so on. In P format, the most-significant 4 bits of the last byte are the least-significant decimal digit. The least-significant 4 bits represent the sign: decimal 15 indicates a negative value, decimal 13 indicates a positive value. Numbers are rounded downward on output. The system-missing value and numbers outside representable range are output as zero. The maximum field width is 16. Decimal places may range from 0 up to the number of decimal digits represented by the field. The default output format is an F format with twice the input field width, plus one column for a decimal point (if decimal places were requested). IB and PIB Formats .................. These are integer binary formats. IB reads and writes 2's complement binary integers, and PIB reads and writes unsigned binary integers. The byte ordering is by default the host machine's, but SET RIB may be used to select a specific byte ordering for reading (*note SET RIB::) and SET WIB, similarly, for writing (*note SET WIB::). The maximum field width is 8. Decimal places may range from 0 up to the number of decimal digits in the largest value representable in the field width. The default output format is an F format whose width is the number of decimal digits in the largest value representable in the field width, plus 1 if the format has decimal places. RB Format ......... This is a binary format for real numbers. By default it reads and writes the host machine's floating-point format, but SET RRB may be used to select an alternate floating-point format for reading (*note SET RRB::) and SET WRB, similarly, for writing (*note SET WRB::). The recommended field width depends on the floating-point format. NATIVE (the default format), IDL, IDB, VD, VG, and ZL formats should use a field width of 8. ISL, ISB, VF, and ZS formats should use a field width of 4. Other field widths will not produce useful results. The maximum field width is 8. No decimal places may be specified. The default output format is F8.2. PIBHEX and RBHEX Formats ........................ These are hexadecimal formats, for reading and writing binary formats where each byte has been recoded as a pair of hexadecimal digits. A hexadecimal field consists solely of hexadecimal digits `0'...`9' and `A'...`F'. Uppercase and lowercase are accepted on input; output is in uppercase. Other than the hexadecimal representation, these formats are equivalent to PIB and RB formats, respectively. However, bytes in PIBHEX format are always ordered with the most-significant byte first (big-endian order), regardless of the host machine's native byte order or PSPP settings. Field widths must be even and between 2 and 16. RBHEX format allows no decimal places; PIBHEX allows as many decimal places as a PIB format with half the given width. 4.6.4.5 Time and Date Formats ............................. In PSPP, a "time" is an interval. The time formats translate between human-friendly descriptions of time intervals and PSPP's internal representation of time intervals, which is simply the number of seconds in the interval. PSPP has two time formats: Time Format Template Example ---------------------------------------------------------------------- TIME `hh:MM:SS.ss' `04:31:17.01' DTIME `DD HH:MM:SS.ss' `00 04:31:17.01' A "date" is a moment in the past or the future. Internally, PSPP represents a date as the number of seconds since the "epoch", midnight, Oct. 14, 1582. The date formats translate between human-readable dates and PSPP's numeric representation of dates and times. PSPP has several date formats: Date Format Template Example ---------------------------------------------------------------------- DATE `dd-mmm-yyyy' `01-OCT-1978' ADATE `mm/dd/yyyy' `10/01/1978' EDATE `dd.mm.yyyy' `01.10.1978' JDATE `yyyyjjj' `1978274' SDATE `yyyy/mm/dd' `1978/10/01' QYR `q Q yyyy' `3 Q 1978' MOYR `mmm yyyy' `OCT 1978' WKYR `ww WK yyyy' `40 WK 1978' DATETIME `dd-mmm-yyyy HH:MM:SS.ss' `01-OCT-1978 04:31:17.01' The templates in the preceding tables describe how the time and date formats are input and output: `dd' Day of month, from 1 to 31. Always output as two digits. `mm' `mmm' Month. In output, `mm' is output as two digits, `mmm' as the first three letters of an English month name (January, February, ...). In input, both of these formats, plus Roman numerals, are accepted. `yyyy' Year. In output, DATETIME always produces a 4-digit year; other formats can produce a 2- or 4-digit year. The century assumed for 2-digit years depends on the EPOCH setting (*note SET EPOCH::). In output, a year outside the epoch causes the whole field to be filled with asterisks (`*'). `jjj' Day of year (Julian day), from 1 to 366. This is exactly three digits giving the count of days from the start of the year. January 1 is considered day 1. `q' Quarter of year, from 1 to 4. Quarters start on January 1, April 1, July 1, and October 1. `ww' Week of year, from 1 to 53. Output as exactly two digits. January 1 is the first day of week 1. `DD' Count of days, which may be positive or negative. Output as at least two digits. `hh' Count of hours, which may be positive or negative. Output as at least two digits. `HH' Hour of day, from 0 to 23. Output as exactly two digits. `MM' Minute of hour, from 0 to 59. Output as exactly two digits. `SS.ss' Seconds within minute, from 0 to 59. The integer part is output as exactly two digits. On output, seconds and fractional seconds may or may not be included, depending on field width and decimal places. On input, seconds and fractional seconds are optional. The DECIMAL setting controls the character accepted and displayed as the decimal point (*note SET DECIMAL::). For output, the date and time formats use the delimiters indicated in the table. For input, date components may be separated by spaces or by one of the characters `-', `/', `.', or `,', and time components may be separated by spaces, `:', or `.'. On input, the `Q' separating quarter from year and the `WK' separating week from year may be uppercase or lowercase, and the spaces around them are optional. On input, all time and date formats accept any amount of leading and trailing white space. The maximum width for time and date formats is 40 columns. Minimum input and output width for each of the time and date formats is shown below: Format Min. Input Width Min. Output Width Option ----------------------------------------------------------------- DATE 8 9 4-digit year ADATE 8 8 4-digit year EDATE 8 8 4-digit year JDATE 5 5 4-digit year SDATE 8 8 4-digit year QYR 4 6 4-digit year MOYR 6 6 4-digit year WKYR 6 8 4-digit year DATETIME 17 17 seconds TIME 5 5 seconds DTIME 8 8 seconds In the table, "Option" describes what increased output width enables: 4-digit year A field 2 columns wider than minimum will include a 4-digit year. (DATETIME format always includes a 4-digit year.) seconds A field 3 columns wider than minimum will include seconds as well as minutes. A field 5 columns wider than minimum, or more, can also include a decimal point and fractional seconds (but no more than allowed by the format's decimal places). For the time and date formats, the default output format is the same as the input format, except that PSPP increases the field width, if necessary, to the minimum allowed for output. Time or dates narrower than the field width are right-justified within the field. When a time or date exceeds the field width, characters are trimmed from the end until it fits. This can occur in an unusual situation, e.g. with a year greater than 9999 (which adds an extra digit), or for a negative value on TIME or DTIME (which adds a leading minus sign). The system-missing value is output as a period at the right end of the field. 4.6.4.6 Date Component Formats .............................. The WKDAY and MONTH formats provide input and output for the names of weekdays and months, respectively. On output, these formats convert a number between 1 and 7, for WKDAY, or between 1 and 12, for MONTH, into the English name of a day or month, respectively. If the name is longer than the field, it is trimmed to fit. If the name is shorter than the field, it is padded on the right with spaces. Values outside the valid range, and the system-missing value, are output as all spaces. On input, English weekday or month names (in uppercase or lowercase) are converted back to their corresponding numbers. Weekday and month names may be abbreviated to their first 2 or 3 letters, respectively. The field width may range from 2 to 40, for WKDAY, or from 3 to 40, for MONTH. No decimal places are allowed. The default output format is the same as the input format. 4.6.4.7 String Formats ...................... The A and AHEX formats are the only ones that may be assigned to string variables. Neither format allows any decimal places. In A format, the entire field is treated as a string value. The field width may range from 1 to 32,767, the maximum string width. The default output format is the same as the input format. In AHEX format, the field is composed of characters in a string encoded as hex digit pairs. On output, hex digits are output in uppercase; on input, uppercase and lowercase are both accepted. The default output format is A format with half the input width. 4.6.5 Scratch Variables ----------------------- Most of the time, variables don't retain their values between cases. Instead, either they're being read from a data file or the active file, in which case they assume the value read, or, if created with COMPUTE or another transformation, they're initialized to the system-missing value or to blanks, depending on type. However, sometimes it's useful to have a variable that keeps its value between cases. You can do this with LEAVE (*note LEAVE::), or you can use a "scratch variable". Scratch variables are variables whose names begin with an octothorpe (`#'). Scratch variables have the same properties as variables left with LEAVE: they retain their values between cases, and for the first case they are initialized to 0 or blanks. They have the additional property that they are deleted before the execution of any procedure. For this reason, scratch variables can't be used for analysis. To use a scratch variable in an analysis, use COMPUTE (*note COMPUTE::) to copy its value into an ordinary variable, then use that ordinary variable in the analysis. 4.7 Files Used by PSPP ====================== PSPP makes use of many files each time it runs. Some of these it reads, some it writes, some it creates. Here is a table listing the most important of these files: *command file* *syntax file* These names (synonyms) refer to the file that contains instructions that tell PSPP what to do. The syntax file's name is specified on the PSPP command line. Syntax files can also be read with INCLUDE (*note INCLUDE::). *data file* Data files contain raw data in text or binary format. Data can also be embedded in a syntax file with BEGIN DATA and END DATA. *listing file* One or more output files are created by PSPP each time it is run. The output files receive the tables and charts produced by statistical procedures. The output files may be in any number of formats, depending on how PSPP is configured. *active file* The active file is the "file" on which all PSPP procedures are performed. The active file consists of a dictionary and a set of cases. The active file is not necessarily a disk file: it is stored in memory if there is room. *system file* System files are binary files that store a dictionary and a set of cases. GET and SAVE read and write system files. *portable file* Portable files are files in a text-based format that store a dictionary and a set of cases. IMPORT and EXPORT read and write portable files. *scratch file* Scratch files consist of a dictionary and cases and may be stored in memory or on disk. Most procedures that act on a system file or portable file can use a scratch file instead. The contents of scratch files persist within a single PSPP session only. GET and SAVE can be used to read and write scratch files. Scratch files are a PSPP extension. 4.8 File Handles ================ A "file handle" is a reference to a data file, system file, portable file, or scratch file. Most often, a file handle is specified as the name of a file as a string, that is, enclosed within `'' or `"'. A file name string that begins or ends with `|' is treated as the name of a command to pipe data to or from. You can use this feature to read data over the network using a program such as `curl' (e.g. `GET '|curl -s -S http://example.com/mydata.sav''), to read compressed data from a file using a program such as `zcat' (e.g. `GET '|zcat mydata.sav.gz''), and for many other purposes. PSPP also supports declaring named file handles with the FILE HANDLE command. This command associates an identifier of your choice (the file handle's name) with a file. Later, the file handle name can be substituted for the name of the file. When PSPP syntax accesses a file multiple times, declaring a named file handle simplifies updating the syntax later to use a different file. Use of FILE HANDLE is also required to read data files in binary formats. *Note FILE HANDLE::, for more information. PSPP assumes that a file handle name that begins with `#' refers to a scratch file, unless the name has already been declared on FILE HANDLE to refer to another kind of file. A scratch file is similar to a system file, except that it persists only for the duration of a given PSPP session. Most commands that read or write a system or portable file, such as GET and SAVE, also accept scratch file handles. Scratch file handles may also be declared explicitly with FILE HANDLE. Scratch files are a PSPP extension. In some circumstances, PSPP must distinguish whether a file handle refers to a system file or a portable file. When this is necessary to read a file, e.g. as an input file for GET or MATCH FILES, PSPP uses the file's contents to decide. In the context of writing a file, e.g. as an output file for SAVE or AGGREGATE, PSPP decides based on the file's name: if it ends in `.por' (with any capitalization), then PSPP writes a portable file; otherwise, PSPP writes a system file. INLINE is reserved as a file handle name. It refers to the "data file" embedded into the syntax file between BEGIN DATA and END DATA. *Note BEGIN DATA::, for more information. The file to which a file handle refers may be reassigned on a later FILE HANDLE command if it is first closed using CLOSE FILE HANDLE. The CLOSE FILE HANDLE command is also useful to free the storage associated with a scratch file. *Note CLOSE FILE HANDLE::, for more information. 4.9 Backus-Naur Form ==================== The syntax of some parts of the PSPP language is presented in this manual using the formalism known as "Backus-Naur Form", or BNF. The following table describes BNF: * Words in all-uppercase are PSPP keyword tokens. In BNF, these are often called "terminals". There are some special terminals, which are written in lowercase for clarity: `number' A real number. `integer' An integer number. `string' A string. `var-name' A single variable name. `=', `/', `+', `-', etc. Operators and punctuators. `.' The end of the command. This is not necessarily an actual dot in the syntax file: *Note Commands::, for more details. * Other words in all lowercase refer to BNF definitions, called "productions". These productions are also known as "nonterminals". Some nonterminals are very common, so they are defined here in English for clarity: `var-list' A list of one or more variable names or the keyword `ALL'. `expression' An expression. *Note Expressions::, for details. * `::=' means "is defined as". The left side of `::=' gives the name of the nonterminal being defined. The right side of `::=' gives the definition of that nonterminal. If the right side is empty, then one possible expansion of that nonterminal is nothing. A BNF definition is called a "production". * So, the key difference between a terminal and a nonterminal is that a terminal cannot be broken into smaller parts--in fact, every terminal is a single token (*note Tokens::). On the other hand, nonterminals are composed of a (possibly empty) sequence of terminals and nonterminals. Thus, terminals indicate the deepest level of syntax description. (In parsing theory, terminals are the leaves of the parse tree; nonterminals form the branches.) * The first nonterminal defined in a set of productions is called the "start symbol". The start symbol defines the entire syntax for that command. 5 Mathematical Expressions ************************** Expressions share a common syntax each place they appear in PSPP commands. Expressions are made up of "operands", which can be numbers, strings, or variable names, separated by "operators". There are five types of operators: grouping, arithmetic, logical, relational, and functions. Every operator takes one or more operands as input and yields exactly one result as output. Depending on the operator, operands accept strings or numbers as operands. With few exceptions, operands may be full-fledged expressions in themselves. 5.1 Boolean Values ================== Some PSPP operators and expressions work with Boolean values, which represent true/false conditions. Booleans have only three possible values: 0 (false), 1 (true), and system-missing (unknown). System-missing is neither true nor false and indicates that the true value is unknown. Boolean-typed operands or function arguments must take on one of these three values. Other values are considered false, but provoke a warning when the expression is evaluated. Strings and Booleans are not compatible, and neither may be used in place of the other. 5.2 Missing Values in Expressions ================================= Most numeric operators yield system-missing when given any system-missing operand. A string operator given any system-missing operand typically results in the empty string. Exceptions are listed under particular operator descriptions. String user-missing values are not treated specially in expressions. User-missing values for numeric variables are always transformed into the system-missing value, except inside the arguments to the `VALUE' and `SYSMIS' functions. The missing-value functions can be used to precisely control how missing values are treated in expressions. *Note Missing Value Functions::, for more details. 5.3 Grouping Operators ====================== Parentheses (`()') are the grouping operators. Surround an expression with parentheses to force early evaluation. Parentheses also surround the arguments to functions, but in that situation they act as punctuators, not as operators. 5.4 Arithmetic Operators ======================== The arithmetic operators take numeric operands and produce numeric results. `A + B' Yields the sum of A and B. `A - B' Subtracts B from A and yields the difference. `A * B' Yields the product of A and B. If either A or B is 0, then the result is 0, even if the other operand is missing. `A / B' Divides A by B and yields the quotient. If A is 0, then the result is 0, even if B is missing. If B is zero, the result is system-missing. `A ** B' Yields the result of raising A to the power B. If A is negative and B is not an integer, the result is system-missing. The result of `0**0' is system-missing as well. `- A' Reverses the sign of A. 5.5 Logical Operators ===================== The logical operators take logical operands and produce logical results, meaning "true or false." Logical operators are not true Boolean operators because they may also result in a system-missing value. *Note Boolean Values::, for more information. `A AND B' `A & B' True if both A and B are true, false otherwise. If one operand is false, the result is false even if the other is missing. If both operands are missing, the result is missing. `A OR B' `A | B' True if at least one of A and B is true. If one operand is true, the result is true even if the other operand is missing. If both operands are missing, the result is missing. `NOT A' `~ A' True if A is false. If the operand is missing, then the result is missing. 5.6 Relational Operators ======================== The relational operators take numeric or string operands and produce Boolean results. Strings cannot be compared to numbers. When strings of different lengths are compared, the shorter string is right-padded with spaces to match the length of the longer string. The results of string comparisons, other than tests for equality or inequality, depend on the character set in use. String comparisons are case-sensitive. `A EQ B' `A = B' True if A is equal to B. `A LE B' `A <= B' True if A is less than or equal to B. `A LT B' `A < B' True if A is less than B. `A GE B' `A >= B' True if A is greater than or equal to B. `A GT B' `A > B' True if A is greater than B. `A NE B' `A ~= B' `A <> B' True if A is not equal to B. 5.7 Functions ============= PSPP functions provide mathematical abilities above and beyond those possible using simple operators. Functions have a common syntax: each is composed of a function name followed by a left parenthesis, one or more arguments, and a right parenthesis. Function names are not reserved. Their names are specially treated only when followed by a left parenthesis, so that `EXP(10)' refers to the constant value `e' raised to the 10th power, but `EXP' by itself refers to the value of variable EXP. The sections below describe each function in detail. 5.7.1 Mathematical Functions ---------------------------- Advanced mathematical functions take numeric arguments and produce numeric results. -- Function: EXP (EXPONENT) Returns e (approximately 2.71828) raised to power EXPONENT. -- Function: LG10 (NUMBER) Takes the base-10 logarithm of NUMBER. If NUMBER is not positive, the result is system-missing. -- Function: LN (NUMBER) Takes the base-e logarithm of NUMBER. If NUMBER is not positive, the result is system-missing. -- Function: LNGAMMA (NUMBER) Yields the base-e logarithm of the complete gamma of NUMBER. If NUMBER is a negative integer, the result is system-missing. -- Function: SQRT (NUMBER) Takes the square root of NUMBER. If NUMBER is negative, the result is system-missing. 5.7.2 Miscellaneous Mathematical Functions ------------------------------------------ Miscellaneous mathematical functions take numeric arguments and produce numeric results. -- Function: ABS (NUMBER) Results in the absolute value of NUMBER. -- Function: MOD (NUMERATOR, DENOMINATOR) Returns the remainder (modulus) of NUMERATOR divided by DENOMINATOR. If NUMERATOR is 0, then the result is 0, even if DENOMINATOR is missing. If DENOMINATOR is 0, the result is system-missing. -- Function: MOD10 (NUMBER) Returns the remainder when NUMBER is divided by 10. If NUMBER is negative, MOD10(NUMBER) is negative or zero. -- Function: RND (NUMBER) Takes the absolute value of NUMBER and rounds it to an integer. Then, if NUMBER was negative originally, negates the result. -- Function: TRUNC (NUMBER) Discards the fractional part of NUMBER; that is, rounds NUMBER towards zero. 5.7.3 Trigonometric Functions ----------------------------- Trigonometric functions take numeric arguments and produce numeric results. -- Function: ARCOS (NUMBER) -- Function: ACOS (NUMBER) Takes the arccosine, in radians, of NUMBER. Results in system-missing if NUMBER is not between -1 and 1 inclusive. This function is a PSPP extension. -- Function: ARSIN (NUMBER) -- Function: ASIN (NUMBER) Takes the arcsine, in radians, of NUMBER. Results in system-missing if NUMBER is not between -1 and 1 inclusive. -- Function: ARTAN (NUMBER) -- Function: ATAN (NUMBER) Takes the arctangent, in radians, of NUMBER. -- Function: COS (ANGLE) Takes the cosine of ANGLE which should be in radians. -- Function: SIN (ANGLE) Takes the sine of ANGLE which should be in radians. -- Function: TAN (ANGLE) Takes the tangent of ANGLE which should be in radians. Results in system-missing at values of ANGLE that are too close to odd multiples of pi/2. Portability: none. 5.7.4 Missing-Value Functions ----------------------------- Missing-value functions take various numeric arguments and yield various types of results. Except where otherwise stated below, the normal rules of evaluation apply within expression arguments to these functions. In particular, user-missing values for numeric variables are converted to system-missing values. -- Function: MISSING (EXPR) Returns 1 if EXPR has the system-missing value, 0 otherwise. -- Function: NMISS (EXPR [, EXPR]...) Each argument must be a numeric expression. Returns the number of system-missing values in the list, which may include variable ranges using the `VAR1 TO VAR2' syntax. -- Function: NVALID (EXPR [, EXPR]...) Each argument must be a numeric expression. Returns the number of values in the list that are not system-missing. The list may include variable ranges using the `VAR1 TO VAR2' syntax. -- Function: SYSMIS (EXPR) When EXPR is simply the name of a numeric variable, returns 1 if the variable has the system-missing value, 0 if it is user-missing or not missing. If given EXPR takes another form, results in 1 if the value is system-missing, 0 otherwise. -- Function: VALUE (VARIABLE) Prevents the user-missing values of VARIABLE from being transformed into system-missing values, and always results in the actual value of VARIABLE, whether it is valid, user-missing, or system-missing. 5.7.5 Set-Membership Functions ------------------------------ Set membership functions determine whether a value is a member of a set. They take a set of numeric arguments or a set of string arguments, and produce Boolean results. String comparisons are performed according to the rules given in *Note Relational Operators::. -- Function: ANY (VALUE, SET [, SET]...) Results in true if VALUE is equal to any of the SET values. Otherwise, results in false. If VALUE is system-missing, returns system-missing. System-missing values in SET do not cause ANY to return system-missing. -- Function: RANGE (VALUE, LOW, HIGH [, LOW, HIGH]...) Results in true if VALUE is in any of the intervals bounded by LOW and HIGH inclusive. Otherwise, results in false. Each LOW must be less than or equal to its corresponding HIGH value. LOW and HIGH must be given in pairs. If VALUE is system-missing, returns system-missing. System-missing values in SET do not cause RANGE to return system-missing. 5.7.6 Statistical Functions --------------------------- Statistical functions compute descriptive statistics on a list of values. Some statistics can be computed on numeric or string values; other can only be computed on numeric values. Their results have the same type as their arguments. The current case's weighting factor (*note WEIGHT::) has no effect on statistical functions. These functions' argument lists may include entire ranges of variables using the `VAR1 TO VAR2' syntax. Unlike most functions, statistical functions can return non-missing values even when some of their arguments are missing. Most statistical functions, by default, require only 1 non-missing value to have a non-missing return, but CFVAR, SD, and VARIANCE require 2. These defaults can be increased (but not decreased) by appending a dot and the minimum number of valid arguments to the function name. For example, `MEAN.3(X, Y, Z)' would only return non-missing if all of `X', `Y', and `Z' were valid. -- Function: CFVAR (NUMBER, NUMBER[, ...]) Results in the coefficient of variation of the values of NUMBER. (The coefficient of variation is the standard deviation divided by the mean.) -- Function: MAX (VALUE, VALUE[, ...]) Results in the value of the greatest VALUE. The VALUEs may be numeric or string. -- Function: MEAN (NUMBER, NUMBER[, ...]) Results in the mean of the values of NUMBER. -- Function: MIN (NUMBER, NUMBER[, ...]) Results in the value of the least VALUE. The VALUEs may be numeric or string. -- Function: SD (NUMBER, NUMBER[, ...]) Results in the standard deviation of the values of NUMBER. -- Function: SUM (NUMBER, NUMBER[, ...]) Results in the sum of the values of NUMBER. -- Function: VARIANCE (NUMBER, NUMBER[, ...]) Results in the variance of the values of NUMBER. 5.7.7 String Functions ---------------------- String functions take various arguments and return various results. -- Function: CONCAT (STRING, STRING[, ...]) Returns a string consisting of each STRING in sequence. `CONCAT("abc", "def", "ghi")' has a value of `"abcdefghi"'. The resultant string is truncated to a maximum of 255 characters. -- Function: INDEX (HAYSTACK, NEEDLE) Returns a positive integer indicating the position of the first occurrence of NEEDLE in HAYSTACK. Returns 0 if HAYSTACK does not contain NEEDLE. Returns system-missing if NEEDLE is an empty string. -- Function: INDEX (HAYSTACK, NEEDLES, NEEDLE_LEN) Divides NEEDLES into one or more needles, each with length NEEDLE_LEN. Searches HAYSTACK for the first occurrence of each needle, and returns the smallest value. Returns 0 if HAYSTACK does not contain any part in NEEDLE. It is an error if NEEDLE_LEN does not evenly divide the length of NEEDLES. Returns system-missing if NEEDLES is an empty string. -- Function: LENGTH (STRING) Returns the number of characters in STRING. -- Function: LOWER (STRING) Returns a string identical to STRING except that all uppercase letters are changed to lowercase letters. The definitions of "uppercase" and "lowercase" are system-dependent. -- Function: LPAD (STRING, LENGTH) If STRING is at least LENGTH characters in length, returns STRING unchanged. Otherwise, returns STRING padded with spaces on the left side to length LENGTH. Returns an empty string if LENGTH is system-missing, negative, or greater than 255. -- Function: LPAD (STRING, LENGTH, PADDING) If STRING is at least LENGTH characters in length, returns STRING unchanged. Otherwise, returns STRING padded with PADDING on the left side to length LENGTH. Returns an empty string if LENGTH is system-missing, negative, or greater than 255, or if PADDING does not contain exactly one character. -- Function: LTRIM (STRING) Returns STRING, after removing leading spaces. Other white space, such as tabs, carriage returns, line feeds, and vertical tabs, is not removed. -- Function: LTRIM (STRING, PADDING) Returns STRING, after removing leading PADDING characters. If PADDING does not contain exactly one character, returns an empty string. -- Function: NUMBER (STRING, FORMAT) Returns the number produced when STRING is interpreted according to format specifier FORMAT. If the format width W is less than the length of STRING, then only the first W characters in STRING are used, e.g. `NUMBER("123", F3.0)' and `NUMBER("1234", F3.0)' both have value 123. If W is greater than STRING's length, then it is treated as if it were right-padded with spaces. If STRING is not in the correct format for FORMAT, system-missing is returned. -- Function: RINDEX (STRING, FORMAT) Returns a positive integer indicating the position of the last occurrence of NEEDLE in HAYSTACK. Returns 0 if HAYSTACK does not contain NEEDLE. Returns system-missing if NEEDLE is an empty string. -- Function: RINDEX (HAYSTACK, NEEDLE, NEEDLE_LEN) Divides NEEDLE into parts, each with length NEEDLE_LEN. Searches HAYSTACK for the last occurrence of each part, and returns the largest value. Returns 0 if HAYSTACK does not contain any part in NEEDLE. It is an error if NEEDLE_LEN does not evenly divide the length of NEEDLE. Returns system-missing if NEEDLE is an empty string. -- Function: RPAD (STRING, LENGTH) If STRING is at least LENGTH characters in length, returns STRING unchanged. Otherwise, returns STRING padded with spaces on the right to length LENGTH. Returns an empty string if LENGTH is system-missing, negative, or greater than 255. -- Function: RPAD (STRING, LENGTH, PADDING) If STRING is at least LENGTH characters in length, returns STRING unchanged. Otherwise, returns STRING padded with PADDING on the right to length LENGTH. Returns an empty string if LENGTH is system-missing, negative, or greater than 255, or if PADDING does not contain exactly one character. -- Function: RTRIM (STRING) Returns STRING, after removing trailing spaces. Other types of white space are not removed. -- Function: RTRIM (STRING, PADDING) Returns STRING, after removing trailing PADDING characters. If PADDING does not contain exactly one character, returns an empty string. -- Function: STRING (NUMBER, FORMAT) Returns a string corresponding to NUMBER in the format given by format specifier FORMAT. For example, `STRING(123.56, F5.1)' has the value `"123.6"'. -- Function: SUBSTR (STRING, START) Returns a string consisting of the value of STRING from position START onward. Returns an empty string if START is system-missing, less than 1, or greater than the length of STRING. -- Function: SUBSTR (STRING, START, COUNT) Returns a string consisting of the first COUNT characters from STRING beginning at position START. Returns an empty string if START or COUNT is system-missing, if START is less than 1 or greater than the number of characters in STRING, or if COUNT is less than 1. Returns a string shorter than COUNT characters if START + COUNT - 1 is greater than the number of characters in STRING. Examples: `SUBSTR("abcdefg", 3, 2)' has value `"cd"'; `SUBSTR("nonsense", 4, 10)' has the value `"sense"'. -- Function: UPCASE (STRING) Returns STRING, changing lowercase letters to uppercase letters. 5.7.8 Time & Date Functions --------------------------- For compatibility, PSPP considers dates before 15 Oct 1582 invalid. Most time and date functions will not accept earlier dates. 5.7.8.1 How times & dates are defined and represented ..................................................... Times and dates are handled by PSPP as single numbers. A "time" is an interval. PSPP measures times in seconds. Thus, the following intervals correspond with the numeric values given: 10 minutes 600 1 hour 3,600 1 day, 3 hours, 10 seconds 97,210 40 days 3,456,000 A "date", on the other hand, is a particular instant in the past or the future. PSPP represents a date as a number of seconds since midnight preceding 14 Oct 1582. Because midnight preceding the dates given below correspond with the numeric PSPP dates given: 15 Oct 1582 86,400 4 Jul 1776 6,113,318,400 1 Jan 1900 10,010,390,400 1 Oct 1978 12,495,427,200 24 Aug 1995 13,028,601,600 5.7.8.2 Functions that Produce Times .................................... These functions take numeric arguments and return numeric values that represent times. -- Function: TIME.DAYS (NDAYS) Returns a time corresponding to NDAYS days. -- Function: TIME.HMS (NHOURS, NMINS, NSECS) Returns a time corresponding to NHOURS hours, NMINS minutes, and NSECS seconds. The arguments may not have mixed signs: if any of them are positive, then none may be negative, and vice versa. 5.7.8.3 Functions that Examine Times .................................... These functions take numeric arguments in PSPP time format and give numeric results. -- Function: CTIME.DAYS (TIME) Results in the number of days and fractional days in TIME. -- Function: CTIME.HOURS (TIME) Results in the number of hours and fractional hours in TIME. -- Function: CTIME.MINUTES (TIME) Results in the number of minutes and fractional minutes in TIME. -- Function: CTIME.SECONDS (TIME) Results in the number of seconds and fractional seconds in TIME. (`CTIME.SECONDS' does nothing; `CTIME.SECONDS(X)' is equivalent to `X'.) 5.7.8.4 Functions that Produce Dates .................................... These functions take numeric arguments and give numeric results that represent dates. Arguments taken by these functions are: DAY Refers to a day of the month between 1 and 31. Day 0 is also accepted and refers to the final day of the previous month. Days 29, 30, and 31 are accepted even in months that have fewer days and refer to a day near the beginning of the following month. MONTH Refers to a month of the year between 1 and 12. Months 0 and 13 are also accepted and refer to the last month of the preceding year and the first month of the following year, respectively. QUARTER Refers to a quarter of the year between 1 and 4. The quarters of the year begin on the first day of months 1, 4, 7, and 10. WEEK Refers to a week of the year between 1 and 53. YDAY Refers to a day of the year between 1 and 366. YEAR Refers to a year, 1582 or greater. Years between 0 and 99 are treated according to the epoch set on SET EPOCH, by default beginning 69 years before the current date (*note SET EPOCH::). If these functions' arguments are out-of-range, they are correctly normalized before conversion to date format. Non-integers are rounded toward zero. -- Function: DATE.DMY (DAY, MONTH, YEAR) -- Function: DATE.MDY (MONTH, DAY, YEAR) Results in a date value corresponding to the midnight before day DAY of month MONTH of year YEAR. -- Function: DATE.MOYR (MONTH, YEAR) Results in a date value corresponding to the midnight before the first day of month MONTH of year YEAR. -- Function: DATE.QYR (QUARTER, YEAR) Results in a date value corresponding to the midnight before the first day of quarter QUARTER of year YEAR. -- Function: DATE.WKYR (WEEK, YEAR) Results in a date value corresponding to the midnight before the first day of week WEEK of year YEAR. -- Function: DATE.YRDAY (YEAR, YDAY) Results in a date value corresponding to the day YDAY of year YEAR. 5.7.8.5 Functions that Examine Dates .................................... These functions take numeric arguments in PSPP date or time format and give numeric results. These names are used for arguments: DATE A numeric value in PSPP date format. TIME A numeric value in PSPP time format. TIME-OR-DATE A numeric value in PSPP time or date format. -- Function: XDATE.DATE (TIME-OR-DATE) For a time, results in the time corresponding to the number of whole days DATE-OR-TIME includes. For a date, results in the date corresponding to the latest midnight at or before DATE-OR-TIME; that is, gives the date that DATE-OR-TIME is in. -- Function: XDATE.HOUR (TIME-OR-DATE) For a time, results in the number of whole hours beyond the number of whole days represented by DATE-OR-TIME. For a date, results in the hour (as an integer between 0 and 23) corresponding to DATE-OR-TIME. -- Function: XDATE.JDAY (DATE) Results in the day of the year (as an integer between 1 and 366) corresponding to DATE. -- Function: XDATE.MDAY (DATE) Results in the day of the month (as an integer between 1 and 31) corresponding to DATE. -- Function: XDATE.MINUTE (TIME-OR-DATE) Results in the number of minutes (as an integer between 0 and 59) after the last hour in TIME-OR-DATE. -- Function: XDATE.MONTH (DATE) Results in the month of the year (as an integer between 1 and 12) corresponding to DATE. -- Function: XDATE.QUARTER (DATE) Results in the quarter of the year (as an integer between 1 and 4) corresponding to DATE. -- Function: XDATE.SECOND (TIME-OR-DATE) Results in the number of whole seconds after the last whole minute (as an integer between 0 and 59) in TIME-OR-DATE. -- Function: XDATE.TDAY (DATE) Results in the number of whole days from 14 Oct 1582 to DATE. -- Function: XDATE.TIME (DATE) Results in the time of day at the instant corresponding to DATE, as a time value. This is the number of seconds since midnight on the day corresponding to DATE. -- Function: XDATE.WEEK (DATE) Results in the week of the year (as an integer between 1 and 53) corresponding to DATE. -- Function: XDATE.WKDAY (DATE) Results in the day of week (as an integer between 1 and 7) corresponding to DATE, where 1 represents Sunday. -- Function: XDATE.YEAR (DATE) Returns the year (as an integer 1582 or greater) corresponding to DATE. 5.7.8.6 Time and Date Arithmetic ................................ Ordinary arithmetic operations on dates and times often produce sensible results. Adding a time to, or subtracting one from, a date produces a new date that much earlier or later. The difference of two dates yields the time between those dates. Adding two times produces the combined time. Multiplying a time by a scalar produces a time that many times longer. Since times and dates are just numbers, the ordinary addition and subtraction operators are employed for these purposes. Adding two dates does not produce a useful result. Dates and times may have very large values. Thus, it is not a good idea to take powers of these values; also, the accuracy of some procedures may be affected. If necessary, convert times or dates in seconds to some other unit, like days or years, before performing analysis. PSPP supplies a few functions for date arithmetic: -- Function: DATEDIFF (DATE2, DATE1, UNIT) Returns the span of time from DATE1 to DATE2 in terms of UNIT, which must be a quoted string, one of `years', `quarters', `months', `weeks', `days', `hours', `minutes', and `seconds'. The result is an integer, truncated toward zero. One year is considered to span from a given date to the same month, day, and time of day the next year. Thus, from Jan. 1 of one year to Jan. 1 the next year is considered to be a full year, but Feb. 29 of a leap year to the following Feb. 28 is not. Similarly, one month spans from a given day of the month to the same day of the following month. Thus, there is never a full month from Jan. 31 of a given year to any day in the following February. -- Function: DATESUM (DATE, QUANTITY, UNIT[, METHOD]) Returns DATE advanced by the given QUANTITY of the specified UNIT, which must be one of the strings `years', `quarters', `months', `weeks', `days', `hours', `minutes', and `seconds'. When UNIT is `years', `quarters', or `months', only the integer part of QUANTITY is considered. Adding one of these units can cause the day of the month to exceed the number of days in the month. In this case, the METHOD comes into play: if it is omitted or specified as `closest' (as a quoted string), then the resulting day is the last day of the month; otherwise, if it is specified as `rollover', then the extra days roll over into the following month. When UNIT is `weeks', `days', `hours', `minutes', or `seconds', the QUANTITY is not rounded to an integer and METHOD, if specified, is ignored. 5.7.9 Miscellaneous Functions ----------------------------- -- Function: LAG (VARIABLE[, N]) VARIABLE must be a numeric or string variable name. `LAG' yields the value of that variable for the case N before the current one. Results in system-missing (for numeric variables) or blanks (for string variables) for the first N cases. `LAG' obtains values from the cases that become the new active file after a procedure executes. Thus, `LAG' will not return values from cases dropped by transformations such as SELECT IF, and transformations like COMPUTE that modify data will change the values returned by `LAG'. These are both the case whether these transformations precede or follow the use of `LAG'. If `LAG' is used before TEMPORARY, then the values it returns are those in cases just before TEMPORARY. `LAG' may not be used after TEMPORARY. If omitted, NCASES defaults to 1. Otherwise, NCASES must be a small positive constant integer. There is no explicit limit, but use of a large value will increase memory consumption. -- Function: YRMODA (YEAR, MONTH, DAY) YEAR is a year, either between 0 and 99 or at least 1582. Unlike other PSPP date functions, years between 0 and 99 always correspond to 1900 through 1999. MONTH is a month between 1 and 13. DAY is a day between 0 and 31. A DAY of 0 refers to the last day of the previous month, and a MONTH of 13 refers to the first month of the next year. YEAR must be in range. YEAR, MONTH, and DAY must all be integers. `YRMODA' results in the number of days between 15 Oct 1582 and the date specified, plus one. The date passed to `YRMODA' must be on or after 15 Oct 1582. 15 Oct 1582 has a value of 1. -- Function: VALUELABEL (VARIABLE) Returns a string matching the label associated with the current value of VARIABLE. If the current value of VARIABLE has no associated label, then this function returns the empty string. VARIABLE may be a numeric or string variable. 5.7.10 Statistical Distribution Functions ----------------------------------------- PSPP can calculate several functions of standard statistical distributions. These functions are named systematically based on the function and the distribution. The table below describes the statistical distribution functions in general: PDF.DIST (X[, PARAM...]) Probability density function for DIST. The domain of X depends on DIST. For continuous distributions, the result is the density of the probability function at X, and the range is nonnegative real numbers. For discrete distributions, the result is the probability of X. CDF.DIST (X[, PARAM...]) Cumulative distribution function for DIST, that is, the probability that a random variate drawn from the distribution is less than X. The domain of X depends DIST. The result is a probability. SIG.DIST (X[, PARAM...) Tail probability function for DIST, that is, the probability that a random variate drawn from the distribution is greater than X. The domain of X depends DIST. The result is a probability. Only a few distributions include an SIG function. IDF.DIST (P[, PARAM...]) Inverse distribution function for DIST, the value of X for which the CDF would yield P. The value of P is a probability. The range depends on DIST and is identical to the domain for the corresponding CDF. RV.DIST ([PARAM...]) Random variate function for DIST. The range depends on the distribution. NPDF.DIST (X[, PARAM...]) Noncentral probability density function. The result is the density of the given noncentral distribution at X. The domain of X depends on DIST. The range is nonnegative real numbers. Only a few distributions include an NPDF function. NCDF.DIST (X[, PARAM...]) Noncentral cumulative distribution function for DIST, that is, the probability that a random variate drawn from the given noncentral distribution is less than X. The domain of X depends DIST. The result is a probability. Only a few distributions include an NCDF function. The individual distributions are described individually below. 5.7.10.1 Continuous Distributions ................................. The following continuous distributions are available: -- Function: PDF.BETA (X) -- Function: CDF.BETA (X, A, B) -- Function: IDF.BETA (P, A, B) -- Function: RV.BETA (A, B) -- Function: NPDF.BETA (X, A, B, LAMBDA) -- Function: NCDF.BETA (X, A, B, LAMBDA) Beta distribution with shape parameters A and B. The noncentral distribution takes an additional parameter LAMBDA. Constraints: A > 0, B > 0, LAMBDA >= 0, 0 <= X <= 1, 0 <= P <= 1. -- Function: PDF.BVNOR (X0, X1, RHO) -- Function: CDF.VBNOR (X0, X1, RHO) Bivariate normal distribution of two standard normal variables with correlation coefficient RHO. Two variates X0 and X1 must be provided. Constraints: 0 <= RHO <= 1, 0 <= P <= 1. -- Function: PDF.CAUCHY (X, A, B) -- Function: CDF.CAUCHY (X, A, B) -- Function: IDF.CAUCHY (P, A, B) -- Function: RV.CAUCHY (A, B) Cauchy distribution with location parameter A and scale parameter B. Constraints: B > 0, 0 < P < 1. -- Function: PDF.CHISQ (X, DF) -- Function: CDF.CHISQ (X, DF) -- Function: SIG.CHISQ (X, DF) -- Function: IDF.CHISQ (P, DF) -- Function: RV.CHISQ (DF) -- Function: NPDF.CHISQ (X, DF, LAMBDA) -- Function: NCDF.CHISQ (X, DF, LAMBDA) Chi-squared distribution with DF degrees of freedom. The noncentral distribution takes an additional parameter LAMBDA. Constraints: DF > 0, LAMBDA > 0, X >= 0, 0 <= P < 1. -- Function: PDF.EXP (X, A) -- Function: CDF.EXP (X, A) -- Function: IDF.EXP (P, A) -- Function: RV.EXP (A) Exponential distribution with scale parameter A. The inverse of A represents the rate of decay. Constraints: A > 0, X >= 0, 0 <= P < 1. -- Function: PDF.XPOWER (X, A, B) -- Function: RV.XPOWER (A, B) Exponential power distribution with positive scale parameter A and nonnegative power parameter B. Constraints: A > 0, B >= 0, X >= 0, 0 <= P <= 1. This distribution is a PSPP extension. -- Function: PDF.F (X, DF1, DF2) -- Function: CDF.F (X, DF1, DF2) -- Function: SIG.F (X, DF1, DF2) -- Function: IDF.F (P, DF1, DF2) -- Function: RV.F (DF1, DF2) -- Function: NPDF.F (X, DF1, DF2, LAMBDA) -- Function: NCDF.F (X, DF1, DF2, LAMBDA) F-distribution of two chi-squared deviates with DF1 and DF2 degrees of freedom. The noncentral distribution takes an additional parameter LAMBDA. Constraints: DF1 > 0, DF2 > 0, LAMBDA >= 0, X >= 0, 0 <= P < 1. -- Function: PDF.GAMMA (X, A, B) -- Function: CDF.GAMMA (X, A, B) -- Function: IDF.GAMMA (P, A, B) -- Function: RV.GAMMA (A, B) Gamma distribution with shape parameter A and scale parameter B. Constraints: A > 0, B > 0, X >= 0, 0 <= P < 1. -- Function: PDF.HALFNRM (X, A, B) -- Function: CDF.HALFNRM (X, A, B) -- Function: IDF.HALFNRM (P, A, B) -- Function: RV.HALFNRM (A, B) Half-normal distribution with location parameter A and shape parameter B. Constraints: B > 0, 0 < P < 1. -- Function: PDF.IGAUSS (X, A, B) -- Function: CDF.IGAUSS (X, A, B) -- Function: IDF.IGAUSS (P, A, B) -- Function: RV.IGAUSS (A, B) Inverse Gaussian distribution with parameters A and B. Constraints: A > 0, B > 0, X > 0, 0 <= P < 1. -- Function: PDF.LANDAU (X) -- Function: RV.LANDAU () Landau distribution. -- Function: PDF.LAPLACE (X, A, B) -- Function: CDF.LAPLACE (X, A, B) -- Function: IDF.LAPLACE (P, A, B) -- Function: RV.LAPLACE (A, B) Laplace distribution with location parameter A and scale parameter B. Constraints: B > 0, 0 < P < 1. -- Function: RV.LEVY (C, ALPHA) Levy symmetric alpha-stable distribution with scale C and exponent ALPHA. Constraints: 0 < ALPHA <= 2. -- Function: RV.LVSKEW (C, ALPHA, BETA) Levy skew alpha-stable distribution with scale C, exponent ALPHA, and skewness parameter BETA. Constraints: 0 < ALPHA <= 2, -1 <= BETA <= 1. -- Function: PDF.LOGISTIC (X, A, B) -- Function: CDF.LOGISTIC (X, A, B) -- Function: IDF.LOGISTIC (P, A, B) -- Function: RV.LOGISTIC (A, B) Logistic distribution with location parameter A and scale parameter B. Constraints: B > 0, 0 < P < 1. -- Function: PDF.LNORMAL (X, A, B) -- Function: CDF.LNORMAL (X, A, B) -- Function: IDF.LNORMAL (P, A, B) -- Function: RV.LNORMAL (A, B) Lognormal distribution with parameters A and B. Constraints: A > 0, B > 0, X >= 0, 0 <= P < 1. -- Function: PDF.NORMAL (X, MU, SIGMA) -- Function: CDF.NORMAL (X, MU, SIGMA) -- Function: IDF.NORMAL (P, MU, SIGMA) -- Function: RV.NORMAL (MU, SIGMA) Normal distribution with mean MU and standard deviation SIGMA. Constraints: B > 0, 0 < P < 1. Three additional functions are available as shorthand: -- Function: CDFNORM (X) Equivalent to CDF.NORMAL(X, 0, 1). -- Function: PROBIT (P) Equivalent to IDF.NORMAL(P, 0, 1). -- Function: NORMAL (SIGMA) Equivalent to RV.NORMAL(0, SIGMA). -- Function: PDF.NTAIL (X, A, SIGMA) -- Function: RV.NTAIL (A, SIGMA) Normal tail distribution with lower limit A and standard deviation SIGMA. This distribution is a PSPP extension. Constraints: A > 0, X > A, 0 < P < 1. -- Function: PDF.PARETO (X, A, B) -- Function: CDF.PARETO (X, A, B) -- Function: IDF.PARETO (P, A, B) -- Function: RV.PARETO (A, B) Pareto distribution with threshold parameter A and shape parameter B. Constraints: A > 0, B > 0, X >= A, 0 <= P < 1. -- Function: PDF.RAYLEIGH (X, SIGMA) -- Function: CDF.RAYLEIGH (X, SIGMA) -- Function: IDF.RAYLEIGH (P, SIGMA) -- Function: RV.RAYLEIGH (SIGMA) Rayleigh distribution with scale parameter SIGMA. This distribution is a PSPP extension. Constraints: SIGMA > 0, X > 0. -- Function: PDF.RTAIL (X, A, SIGMA) -- Function: RV.RTAIL (A, SIGMA) Rayleigh tail distribution with lower limit A and scale parameter SIGMA. This distribution is a PSPP extension. Constraints: A > 0, SIGMA > 0, X > A. -- Function: CDF.SMOD (X, A, B) -- Function: IDF.SMOD (P, A, B) Studentized maximum modulus distribution with parameters A and B. Constraints: A > 0, B > 0, X > 0, 0 <= P < 1. -- Function: CDF.SRANGE (X, A, B) -- Function: IDF.SRANGE (P, A, B) Studentized range distribution with parameters A and B. Constraints: A >= 1, B >= 1, X > 0, 0 <= P < 1. -- Function: PDF.T (X, DF) -- Function: CDF.T (X, DF) -- Function: IDF.T (P, DF) -- Function: RV.T (DF) -- Function: NPDF.T (X, DF, LAMBDA) -- Function: NCDF.T (X, DF, LAMBDA) T-distribution with DF degrees of freedom. The noncentral distribution takes an additional parameter LAMBDA. Constraints: DF > 0, 0 < P < 1. -- Function: PDF.T1G (X, A, B) -- Function: CDF.T1G (X, A, B) -- Function: IDF.T1G (P, A, B) Type-1 Gumbel distribution with parameters A and B. This distribution is a PSPP extension. Constraints: 0 < P < 1. -- Function: PDF.T2G (X, A, B) -- Function: CDF.T2G (X, A, B) -- Function: IDF.T2G (P, A, B) Type-2 Gumbel distribution with parameters A and B. This distribution is a PSPP extension. Constraints: X > 0, 0 < P < 1. -- Function: PDF.UNIFORM (X, A, B) -- Function: CDF.UNIFORM (X, A, B) -- Function: IDF.UNIFORM (P, A, B) -- Function: RV.UNIFORM (A, B) Uniform distribution with parameters A and B. Constraints: A <= X <= B, 0 <= P <= 1. An additional function is available as shorthand: -- Function: UNIFORM (B) Equivalent to RV.UNIFORM(0, B). -- Function: PDF.WEIBULL (X, A, B) -- Function: CDF.WEIBULL (X, A, B) -- Function: IDF.WEIBULL (P, A, B) -- Function: RV.WEIBULL (A, B) Weibull distribution with parameters A and B. Constraints: A > 0, B > 0, X >= 0, 0 <= P < 1. 5.7.10.2 Discrete Distributions ............................... The following discrete distributions are available: -- Function: PDF.BERNOULLI (X) -- Function: CDF.BERNOULLI (X, P) -- Function: RV.BERNOULLI (P) Bernoulli distribution with probability of success P. Constraints: X = 0 or 1, 0 <= P <= 1. -- Function: PDF.BINOMIAL (X, N, P) -- Function: CDF.BINOMIAL (X, N, P) -- Function: RV.BINOMIAL (N, P) Binomial distribution with N trials and probability of success P. Constraints: integer N > 0, 0 <= P <= 1, integer X <= N. -- Function: PDF.GEOM (X, N, P) -- Function: CDF.GEOM (X, N, P) -- Function: RV.GEOM (N, P) Geometric distribution with probability of success P. Constraints: 0 <= P <= 1, integer X > 0. -- Function: PDF.HYPER (X, A, B, C) -- Function: CDF.HYPER (X, A, B, C) -- Function: RV.HYPER (A, B, C) Hypergeometric distribution when B objects out of A are drawn and C of the available objects are distinctive. Constraints: integer A > 0, integer B <= A, integer C <= A, integer X >= 0. -- Function: PDF.LOG (X, P) -- Function: RV.LOG (P) Logarithmic distribution with probability parameter P. Constraints: 0 <= P < 1, X >= 1. -- Function: PDF.NEGBIN (X, N, P) -- Function: CDF.NEGBIN (X, N, P) -- Function: RV.NEGBIN (N, P) Negative binomial distribution with number of successes paramter N and probability of success parameter P. Constraints: integer N >= 0, 0 < P <= 1, integer X >= 1. -- Function: PDF.POISSON (X, MU) -- Function: CDF.POISSON (X, MU) -- Function: RV.POISSON (MU) Poisson distribution with mean MU. Constraints: MU > 0, integer X >= 0. 5.8 Operator Precedence ======================= The following table describes operator precedence. Smaller-numbered levels in the table have higher precedence. Within a level, operations are always performed from left to right. The first occurrence of `-' represents unary negation, the second binary subtraction. 1. `( )' 2. `**' 3. `-' 4. `* /' 5. `+ -' 6. `EQ GE GT LE LT NE' 7. `AND NOT OR' 6 Data Input and Output *********************** Data are the focus of the PSPP language. Each datum belongs to a "case" (also called an "observation"). Each case represents an individual or "experimental unit". For example, in the results of a survey, the names of the respondents, their sex, age, etc. and their responses are all data and the data pertaining to single respondent is a case. This chapter examines the PSPP commands for defining variables and reading and writing data. Note: These commands tell PSPP how to read data, but the data will not actually be read until a procedure is executed. 6.1 BEGIN DATA ============== BEGIN DATA. ... END DATA. BEGIN DATA and END DATA can be used to embed raw ASCII data in a PSPP syntax file. DATA LIST or another input procedure must be used before BEGIN DATA (*note DATA LIST::). BEGIN DATA and END DATA must be used together. END DATA must appear by itself on a single line, with no leading white space and exactly one space between the words `END' and `DATA', like this: END DATA. 6.2 CLEAR TRANSFORMATIONS ========================= CLEAR TRANSFORMATIONS. CLEAR TRANSFORMATIONS clears out all pending transformations. It does not cancel the current input program. 6.3 CLOSE FILE HANDLE ===================== CLOSE FILE HANDLE handle_name. CLOSE FILE HANDLE disassociates the name of a file handle with a given file. The only specification is the name of the handle to close. Afterward FILE HANDLE. If the file handle name refers to a scratch file, then the storage associated with the scratch file in memory or on disk will be freed. If the scratch file is in use, e.g. it has been specified on a GET command whose execution has not completed, then freeing is delayed until it is no longer in use. The file named INLINE, which represents data entered between BEGIN DATA and END DATA, cannot be closed. Attempts to close it with CLOSE FILE HANDLE have no effect. CLOSE FILE HANDLE is a PSPP extension. 6.4 DATA LIST ============= Used to read text or binary data, DATA LIST is the most fundamental data-reading command. Even the more sophisticated input methods use DATA LIST commands as a building block. Understanding DATA LIST is important to understanding how to use PSPP to read your data files. There are two major variants of DATA LIST, which are fixed format and free format. In addition, free format has a minor variant, list format, which is discussed in terms of its differences from vanilla free format. Each form of DATA LIST is described in detail below. 6.4.1 DATA LIST FIXED --------------------- DATA LIST [FIXED] {TABLE,NOTABLE} [FILE='file-name'] [RECORDS=record_count] [END=end_var] [SKIP=record_count] /[line_no] var_spec... where each var_spec takes one of the forms var_list start-end [type_spec] var_list (fortran_spec) DATA LIST FIXED is used to read data files that have values at fixed positions on each line of single-line or multiline records. The keyword FIXED is optional. The FILE subcommand must be used if input is to be taken from an external file. It may be used to specify a file name as a string or a file handle (*note File Handles::). If the FILE subcommand is not used, then input is assumed to be specified within the command file using BEGIN DATA...END DATA (*note BEGIN DATA::). The optional RECORDS subcommand, which takes a single integer as an argument, is used to specify the number of lines per record. If RECORDS is not specified, then the number of lines per record is calculated from the list of variable specifications later in DATA LIST. The END subcommand is only useful in conjunction with INPUT PROGRAM. *Note INPUT PROGRAM::, for details. The optional SKIP subcommand specifies a number of records to skip at the beginning of an input file. It can be used to skip over a row that contains variable names, for example. DATA LIST can optionally output a table describing how the data file will be read. The TABLE subcommand enables this output, and NOTABLE disables it. The default is to output the table. The list of variables to be read from the data list must come last. Each line in the data record is introduced by a slash (`/'). Optionally, a line number may follow the slash. Following, any number of variable specifications may be present. Each variable specification consists of a list of variable names followed by a description of their location on the input line. Sets of variables may be specified using the `DATA LIST' TO convention (*note Sets of Variables::). There are two ways to specify the location of the variable on the line: columnar style and FORTRAN style. In columnar style, the starting column and ending column for the field are specified after the variable name, separated by a dash (`-'). For instance, the third through fifth columns on a line would be specified `3-5'. By default, variables are considered to be in `F' format (*note Input and Output Formats::). (This default can be changed; see *Note SET:: for more information.) In columnar style, to use a variable format other than the default, specify the format type in parentheses after the column numbers. For instance, for alphanumeric `A' format, use `(A)'. In addition, implied decimal places can be specified in parentheses after the column numbers. As an example, suppose that a data file has a field in which the characters `1234' should be interpreted as having the value 12.34. Then this field has two implied decimal places, and the corresponding specification would be `(2)'. If a field that has implied decimal places contains a decimal point, then the implied decimal places are not applied. Changing the variable format and adding implied decimal places can be done together; for instance, `(N,5)'. When using columnar style, the input and output width of each variable is computed from the field width. The field width must be evenly divisible into the number of variables specified. FORTRAN style is an altogether different approach to specifying field locations. With this approach, a list of variable input format specifications, separated by commas, are placed after the variable names inside parentheses. Each format specifier advances as many characters into the input line as it uses. Implied decimal places also exist in FORTRAN style. A format specification with D decimal places also has D implied decimal places. In addition to the standard format specifiers (*note Input and Output Formats::), FORTRAN style defines some extensions: `X' Advance the current column on this line by one character position. `T'X Set the current column on this line to column X, with column numbers considered to begin with 1 at the left margin. `NEWREC'X Skip forward X lines in the current record, resetting the active column to the left margin. Repeat count Any format specifier may be preceded by a number. This causes the action of that format specifier to be repeated the specified number of times. (SPEC1, ..., SPECN) Group the given specifiers together. This is most useful when preceded by a repeat count. Groups may be nested arbitrarily. FORTRAN and columnar styles may be freely intermixed. Columnar style leaves the active column immediately after the ending column specified. Record motion using `NEWREC' in FORTRAN style also applies to later FORTRAN and columnar specifiers. Examples ........ 1. DATA LIST TABLE /NAME 1-10 (A) INFO1 TO INFO3 12-17 (1). BEGIN DATA. John Smith 102311 Bob Arnold 122015 Bill Yates 918 6 END DATA. Defines the following variables: * `NAME', a 10-character-wide long string variable, in columns 1 through 10. * `INFO1', a numeric variable, in columns 12 through 13. * `INFO2', a numeric variable, in columns 14 through 15. * `INFO3', a numeric variable, in columns 16 through 17. The `BEGIN DATA'/`END DATA' commands cause three cases to be defined: Case NAME INFO1 INFO2 INFO3 1 John Smith 10 23 11 2 Bob Arnold 12 20 15 3 Bill Yates 9 18 6 The `TABLE' keyword causes PSPP to print out a table describing the four variables defined. 2. DAT LIS FIL="survey.dat" /ID 1-5 NAME 7-36 (A) SURNAME 38-67 (A) MINITIAL 69 (A) /Q01 TO Q50 7-56 /. Defines the following variables: * `ID', a numeric variable, in columns 1-5 of the first record. * `NAME', a 30-character long string variable, in columns 7-36 of the first record. * `SURNAME', a 30-character long string variable, in columns 38-67 of the first record. * `MINITIAL', a 1-character short string variable, in column 69 of the first record. * Fifty variables `Q01', `Q02', `Q03', ..., `Q49', `Q50', all numeric, `Q01' in column 7, `Q02' in column 8, ..., `Q49' in column 55, `Q50' in column 56, all in the second record. Cases are separated by a blank record. Data is read from file `survey.dat' in the current directory. This example shows keywords abbreviated to their first 3 letters. 6.4.2 DATA LIST FREE -------------------- DATA LIST FREE [({TAB,'c'}, ...)] [{NOTABLE,TABLE}] [FILE='file-name'] [END=end_var] [SKIP=record_cnt] /var_spec... where each var_spec takes one of the forms var_list [(type_spec)] var_list * In free format, the input data is, by default, structured as a series of fields separated by spaces, tabs, commas, or line breaks. Each field's content may be unquoted, or it may be quoted with a pairs of apostrophes (`'') or double quotes (`"'). Unquoted white space separates fields but is not part of any field. Any mix of spaces, tabs, and line breaks is equivalent to a single space for the purpose of separating fields, but consecutive commas will skip a field. Alternatively, delimiters can be specified explicitly, as a parenthesized, comma-separated list of single-character strings immediately following FREE. The word TAB may also be used to specify a tab character as a delimiter. When delimiters are specified explicitly, only the given characters, plus line breaks, separate fields. Furthermore, leading spaces at the beginnings of fields are not trimmed, consecutive delimiters define empty fields, and no form of quoting is allowed. The NOTABLE and TABLE subcommands are as in DATA LIST FIXED above. NOTABLE is the default. The FILE, END, and SKIP subcommands are as in DATA LIST FIXED above. The variables to be parsed are given as a single list of variable names. This list must be introduced by a single slash (`/'). The set of variable names may contain format specifications in parentheses (*note Input and Output Formats::). Format specifications apply to all variables back to the previous parenthesized format specification. In addition, an asterisk may be used to indicate that all variables preceding it are to have input/output format `F8.0'. Specified field widths are ignored on input, although all normal limits on field width apply, but they are honored on output. 6.4.3 DATA LIST LIST -------------------- DATA LIST LIST [({TAB,'c'}, ...)] [{NOTABLE,TABLE}] [FILE='file-name'] [END=end_var] [SKIP=record_count] /var_spec... where each var_spec takes one of the forms var_list [(type_spec)] var_list * With one exception, DATA LIST LIST is syntactically and semantically equivalent to DATA LIST FREE. The exception is that each input line is expected to correspond to exactly one input record. If more or fewer fields are found on an input line than expected, an appropriate diagnostic is issued. 6.5 END CASE ============ END CASE. END CASE is used only within INPUT PROGRAM to output the current case. *Note INPUT PROGRAM::, for details. 6.6 END FILE ============ END FILE. END FILE is used only within INPUT PROGRAM to terminate the current input program. *Note INPUT PROGRAM::. 6.7 FILE HANDLE =============== For text files: FILE HANDLE handle_name /NAME='file-name' [/MODE=CHARACTER] /TABWIDTH=tab_width For binary files with fixed-length records: FILE HANDLE handle_name /NAME='file-name' /MODE=IMAGE [/LRECL=rec_len] To explicitly declare a scratch handle: FILE HANDLE handle_name /MODE=SCRATCH Use FILE HANDLE to associate a file handle name with a file and its attributes, so that later commands can refer to the file by its handle name. Names of text files can be specified directly on commands that access files, so that FILE HANDLE is only needed when a file is not an ordinary file containing lines of text. However, FILE HANDLE may be used even for text files, and it may be easier to specify a file's name once and later refer to it by an abstract handle. Specify the file handle name as the identifier immediately following the FILE HANDLE command name. The identifier INLINE is reserved for representing data embedded in the syntax file (*note BEGIN DATA::) The file handle name must not already have been used in a previous invocation of FILE HANDLE, unless it has been closed by an intervening command (*note CLOSE FILE HANDLE::). MODE specifies a file mode. In CHARACTER mode, the default, the data file is read as a text file, according to the local system's conventions, and each text line is read as one record. In CHARACTER mode, most input programs will expand tabs to spaces (DATA LIST FREE with explicitly specified delimiters is an exception). By default, each tab is 4 characters wide, but an alternate width may be specified on TABWIDTH. A tab width of 0 suppresses tab expansion entirely. In IMAGE mode, the data file is opened in ANSI C binary mode. Record length is fixed, with output data truncated or padded with spaces to the record length. LRECL specifies the record length in bytes, with a default of 1024. Tab characters are never expanded to spaces in binary mode. Records The NAME subcommand specifies the name of the file associated with the handle. It is required in CHARACTER and IMAGE modes. The SCRATCH mode designates the file handle as a scratch file handle. Its use is usually unnecessary because file handle names that begin with `#' are assumed to refer to scratch files. *note File Handles::, for more information. 6.8 INPUT PROGRAM ================= INPUT PROGRAM. ... input commands ... END INPUT PROGRAM. INPUT PROGRAM...END INPUT PROGRAM specifies a complex input program. By placing data input commands within INPUT PROGRAM, PSPP programs can take advantage of more complex file structures than available with only DATA LIST. The first sort of extended input program is to simply put multiple DATA LIST commands within the INPUT PROGRAM. This will cause all of the data files to be read in parallel. Input will stop when end of file is reached on any of the data files. Transformations, such as conditional and looping constructs, can also be included within INPUT PROGRAM. These can be used to combine input from several data files in more complex ways. However, input will still stop when end of file is reached on any of the data files. To prevent INPUT PROGRAM from terminating at the first end of file, use the END subcommand on DATA LIST. This subcommand takes a variable name, which should be a numeric scratch variable (*note Scratch Variables::). (It need not be a scratch variable but otherwise the results can be surprising.) The value of this variable is set to 0 when reading the data file, or 1 when end of file is encountered. Two additional commands are useful in conjunction with INPUT PROGRAM. END CASE is the first. Normally each loop through the INPUT PROGRAM structure produces one case. END CASE controls exactly when cases are output. When END CASE is used, looping from the end of INPUT PROGRAM to the beginning does not cause a case to be output. END FILE is the second. When the END subcommand is used on DATA LIST, there is no way for the INPUT PROGRAM construct to stop looping, so an infinite loop results. END FILE, when executed, stops the flow of input data and passes out of the INPUT PROGRAM structure. All this is very confusing. A few examples should help to clarify. INPUT PROGRAM. DATA LIST NOTABLE FILE='a.data'/X 1-10. DATA LIST NOTABLE FILE='b.data'/Y 1-10. END INPUT PROGRAM. LIST. The example above reads variable X from file `a.data' and variable Y from file `b.data'. If one file is shorter than the other then the extra data in the longer file is ignored. INPUT PROGRAM. NUMERIC #A #B. DO IF NOT #A. DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10. END IF. DO IF NOT #B. DATA LIST NOTABLE END=#B FILE='b.data'/Y 1-10. END IF. DO IF #A AND #B. END FILE. END IF. END CASE. END INPUT PROGRAM. LIST. The above example reads variable X from `a.data' and variable Y from `b.data'. If one file is shorter than the other then the missing field is set to the system-missing value alongside the present value for the remaining length of the longer file. INPUT PROGRAM. NUMERIC #A #B. DO IF #A. DATA LIST NOTABLE END=#B FILE='b.data'/X 1-10. DO IF #B. END FILE. ELSE. END CASE. END IF. ELSE. DATA LIST NOTABLE END=#A FILE='a.data'/X 1-10. DO IF NOT #A. END CASE. END IF. END IF. END INPUT PROGRAM. LIST. The above example reads data from file `a.data', then from `b.data', and concatenates them into a single active file. INPUT PROGRAM. NUMERIC #EOF. LOOP IF NOT #EOF. DATA LIST NOTABLE END=#EOF FILE='a.data'/X 1-10. DO IF NOT #EOF. END CASE. END IF. END LOOP. COMPUTE #EOF = 0. LOOP IF NOT #EOF. DATA LIST NOTABLE END=#EOF FILE='b.data'/X 1-10. DO IF NOT #EOF. END CASE. END IF. END LOOP. END FILE. END INPUT PROGRAM. LIST. The above example does the same thing as the previous example, in a different way. INPUT PROGRAM. LOOP #I=1 TO 50. COMPUTE X=UNIFORM(10). END CASE. END LOOP. END FILE. END INPUT PROGRAM. LIST/FORMAT=NUMBERED. The above example causes an active file to be created consisting of 50 random variates between 0 and 10. 6.9 LIST ======== LIST /VARIABLES=var_list /CASES=FROM start_index TO end_index BY incr_index /FORMAT={UNNUMBERED,NUMBERED} {WRAP,SINGLE} {NOWEIGHT,WEIGHT} The LIST procedure prints the values of specified variables to the listing file. The VARIABLES subcommand specifies the variables whose values are to be printed. Keyword VARIABLES is optional. If VARIABLES subcommand is not specified then all variables in the active file are printed. The CASES subcommand can be used to specify a subset of cases to be printed. Specify FROM and the case number of the first case to print, TO and the case number of the last case to print, and BY and the number of cases to advance between printing cases, or any subset of those settings. If CASES is not specified then all cases are printed. The FORMAT subcommand can be used to change the output format. NUMBERED will print case numbers along with each case; UNNUMBERED, the default, causes the case numbers to be omitted. The WRAP and SINGLE settings are currently not used. WEIGHT will cause case weights to be printed along with variable values; NOWEIGHT, the default, cause