fbuf: New data structure for buffered file I/O.
[pspp] / doc / variables.texi
index f19581ac1a88098e093995a49d52dbfa96ea4e56..7f6d89bee25767996f904f29fbc32dcb0c9c7366 100644 (file)
@@ -1,3 +1,12 @@
+@c PSPP - a program for statistical analysis.
+@c Copyright (C) 2017 Free Software Foundation, Inc.
+@c Permission is granted to copy, distribute and/or modify this document
+@c under the terms of the GNU Free Documentation License, Version 1.3
+@c or any later version published by the Free Software Foundation;
+@c with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
+@c A copy of the license is included in the section entitled "GNU
+@c Free Documentation License".
+@c
 @node Variable Attributes
 @chapter Manipulating variables
 
@@ -16,6 +25,7 @@ several utility functions for examining and adjusting them.
 * NUMERIC::                     Create new numeric variables.
 * PRINT FORMATS::               Set variable print formats.
 * RENAME VARIABLES::            Rename variables.
+* SORT VARIABLES::              Reorder variables.
 * VALUE LABELS::                Set value labels for variables.
 * STRING::                      Create new string variables.
 * VARIABLE ATTRIBUTE::          Set custom attributes on variables.
@@ -23,6 +33,7 @@ several utility functions for examining and adjusting them.
 * VARIABLE ALIGNMENT::          Set the alignment for display.
 * VARIABLE WIDTH::              Set the display width.
 * VARIABLE LEVEL::              Set the measurement level.
+* VARIABLE ROLE::               Set the role that a variable fills in analysis.
 * VECTOR::                      Declare an array of variables.
 * WRITE FORMATS::               Set variable write formats.
 @end menu
@@ -210,8 +221,8 @@ where @var{missing_values} takes one of the following forms:
         @var{string1}
         @var{string1}, @var{string2}
         @var{string1}, @var{string2}, @var{string3}
-As part of a range, LO or LOWEST may take the place of @var{num1};
-HI or HIGHEST may take the place of @var{num2}.
+As part of a range, @subcmd{LO} or @subcmd{LOWEST} may take the place of @var{num1};
+@subcmd{HI} or @subcmd{HIGHEST} may take the place of @var{num2}.
 @end display
 
 @cmd{MISSING VALUES} sets user-missing values for numeric and string
@@ -223,7 +234,8 @@ Specify a list of variables, followed by a list of their user-missing
 values in parentheses.  Up to three discrete values may be given, or,
 for numeric variables only, a range of values optionally accompanied by
 a single discrete value.  Ranges may be open-ended on one end, indicated
-through the use of the keyword LO or LOWEST or HI or HIGHEST.
+through the use of the 
+keyword @subcmd{LO} or @subcmd{LOWEST} or @subcmd{HI} or @subcmd{HIGHEST}.
 
 The @cmd{MISSING VALUES} command takes effect immediately.  It is not
 affected by conditional and looping constructs such as @cmd{DO IF} or
@@ -432,6 +444,8 @@ variable names, separated by an equals sign (@samp{=}), within
 parentheses.  There must be the same number of old and new variable
 names.  Each old variable is renamed to the corresponding new variable
 name.  Multiple parenthesized groups of variables may be specified.
+When the old and new variable names contain only a single variable name,
+the parentheses are optional.
 
 @cmd{RENAME VARIABLES} takes effect immediately.  It does not cause the data
 to be read.
@@ -439,6 +453,82 @@ to be read.
 @cmd{RENAME VARIABLES} may not be specified following @cmd{TEMPORARY}
 (@pxref{TEMPORARY}).
 
+@node SORT VARIABLES
+@section SORT VARIABLES
+@vindex SORT VARIABLES
+
+@display
+SORT VARIABLES [BY]
+    (NAME | TYPE | FORMAT | LABEL | VALUES | MISSING | MEASURE
+     | ROLE | COLUMNS | ALIGNMENT | ATTRIBUTE @var{name})
+    [(D)].
+@end display
+
+@cmd{SORT VARIABLES} reorders the variables in the active dataset.
+The main specification is one of the following identifiers, which
+determines how the variables are sorted:
+
+@table @asis
+@item NAME
+Sorts the variables according to their names, in a case-insensitive
+fashion.  However, when variable names differ only in a number at the
+end, they are sorted numerically.  For example, @code{VAR5} is sorted
+before @code{VAR400} even though @samp{4} precedes @samp{5}.
+
+@item TYPE
+Sorts numeric variables before string variables, and shorter string
+variables before longer ones.
+
+@item FORMAT
+Groups variables by print format; within a format, sorts narrower
+formats before wider ones; with the same format and width, sorts fewer
+decimal places before more decimal places.
+@xref{FORMATS}.
+
+@item LABEL
+Sorts variables without a variable label before those with one.
+@xref{VARIABLE LABELS}.
+
+@item VALUES
+Sorts variables without value labels before those with some.
+@xref{VALUE LABELS}.
+
+@item MISSING
+Sorts variables without missing values before those with some.
+@xref{MISSING VALUES}.
+
+@item MEASURE
+Sorts nominal variables first, followed by ordinal variables, followed
+by scale variables.  @xref{VARIABLE LEVEL}.
+
+@item ROLE
+Groups variables according to their role.  @xref{VARIABLE ROLE}.
+
+@item COLUMNS
+Sorts variables in ascending display width.  @xref{VARIABLE WIDTH}.
+
+@item ALIGNMENT
+Sorts variables according to their alignment, first left-aligned, then
+right-aligned, then centered.  @xref{VARIABLE ALIGNMENT}.
+
+@item ATTRIBUTE @var{name}
+Sorts variables according to the first value of their @var{name}
+attribute.  Variables without attribute are sorted first.
+@xref{VARIABLE ATTRIBUTE}.
+@end table
+
+Only one sort criterion can be specified.  The sort is ``stable,'' so
+to sort on multiple criteria one may perform multiple sorts.  For
+example, the following will sort primarily based on alignment, with
+variables that have the same alignment ordered based on display width:
+
+@example
+SORT VARIABLES BY COLUMNS.
+SORT VARIABLES BY ALIGNMENT.
+@end example
+
+Specify @code{(D)} to reverse the sort order.
+
 @node VALUE LABELS
 @section VALUE LABELS
 @vindex VALUE LABELS
@@ -448,11 +538,16 @@ VALUE LABELS
         /@var{var_list} @var{value} '@var{label}' [@var{value} '@var{label}']@dots{}
 @end display
 
-@cmd{VALUE LABELS} allows values of numeric and short string
+@cmd{VALUE LABELS} allows values of
 variables to be associated with labels.  In this way, a short value can
-stand for a long value.
+stand for a longer, more descriptive label.
 
-To set up value labels for a set of variables, specify the
+Both numeric and string variables can be given labels.  For string
+variables, the values are case-sensitive, so that, for example, a
+capitalized value and its lowercase variant would have to be labeled
+separately if both are present in the data.
+
+To set up value labels for one or more variables, specify the
 variable names after a slash (@samp{/}), followed by a list of values
 and their associated labels, separated by spaces.
 
@@ -470,18 +565,45 @@ already present.
 @vindex STRING
 
 @display
-STRING /@var{var_list} (@var{fmt_spec}).
+STRING @var{var_list} (@var{fmt_spec}) [/@var{var_list} (@var{fmt_spec})] [@dots{}].
 @end display
 
 @cmd{STRING} creates new string variables for use in
 transformations.
 
-Specify a slash (@samp{/}), followed by the names of the string
-variables to create and the desired output format specification in
-parentheses (@pxref{Input and Output Formats}).  Variable widths are
+Specify a list of names for the variable you want to create,
+followed by the desired output format specification in
+parentheses (@pxref{Input and Output Formats}).  
+Variable widths are
 implicitly derived from the specified output formats.
+The created variables will be initialized to spaces.
+
+If you want to create several variables with  distinct
+output formats, you can either use two or more separate @cmd{STRING} commands,
+or you can specify further variable list and format specification pairs, each separated
+from the previous by a slash (@samp{/}).
+
+The following example is one way to create three string variables; Two of the
+variables have format A24 and the other A80:
+@example
+STRING firstname lastname (A24) / address (A80).
+@end example
+
+@noindent Here is another way to achieve the same result:
+@example
+STRING firstname lastname (A24).
+STRING address (A80).
+@end example
+
+@noindent @dots{} and here is yet another way:
+
+@example
+STRING firstname (A24).
+STRING lastname (A24).
+STRING address (A80).
+@end example
+
 
-Created variables are initialized to spaces.
 
 
 @node VARIABLE ATTRIBUTE
@@ -618,6 +740,42 @@ VARIABLE LEVEL
 Currently, this has no effect except for certain third party software.
 
 
+@node VARIABLE ROLE
+@section VARIABLE ROLE
+@vindex VARIABLE ROLE
+@display
+VARIABLE ROLE
+        /@var{role} @var{var_list}
+        [/@var{role} @var{var_list}]@dots{}
+@end display
+
+@cmd{VARIABLE ROLE} sets the intended role of a variable for use in
+dialog boxes in graphical user interfaces.  Each @var{role} specifies
+one of the following roles for the variables that follow it:
+
+@table @code
+@item INPUT
+An input variable, such as an independent variable.
+
+@item TARGET
+An output variable, such as an dependent variable.
+
+@item BOTH
+A variable used for input and output.
+
+@item NONE
+No role assigned.  (This is a variable's default role.)
+
+@item PARTITION
+Used to break the data into groups for testing.
+
+@item SPLIT
+No meaning except for certain third party software.  (This role's
+meaning is unrelated to @cmd{SPLIT FILE}.)
+@end table
+
+The PSPPIRE GUI does not yet use variable roles as intended.
+
 @node VECTOR
 @section VECTOR
 @vindex VECTOR
@@ -633,18 +791,20 @@ were consecutive members of an array with a vector(index) notation.
 
 To make a vector out of a set of existing variables, specify a name
 for the vector followed by an equals sign (@samp{=}) and the variables
-to put in the vector.  All the variables in the vector must be the same
-type.  String variables in a vector must all have the same width.
+to put in the vector.  The variables must be all numeric or all
+string, and string variables must have the same width.
 
 To make a vector and create variables at the same time, specify one or
-more vector names followed by a count in parentheses.  This will cause
-variables named @code{@var{vec}1} through @code{@var{vec}@var{count}}
-to be created as numeric variables.  By default, the new variables
-have print and write format F8.2, but an alternate format may be
-specified inside the parentheses before or after the count and
-separated from it by white space or a comma.  Variable names including
-numeric suffixes may not exceed 64 characters in length, and none of
-the variables may exist prior to @cmd{VECTOR}.
+more vector names followed by a count in parentheses.  This will
+create variables named @code{@var{vec}1} through
+@code{@var{vec}@var{count}}.  By default, the new variables are
+numeric with format F8.2, but an alternate format may be specified
+inside the parentheses before or after the count and separated from it
+by white space or a comma.  With a string format such as A8, the
+variables will be string variables; with a numeric format, they will
+be numeric.  Variable names including the suffixes may not exceed 64
+characters in length, and none of the variables may exist prior to
+@cmd{VECTOR}.
 
 Vectors created with @cmd{VECTOR} disappear after any procedure or
 procedure-like command is executed.  The variables contained in the
@@ -664,5 +824,5 @@ WRITE FORMATS @var{var_list} (@var{fmt_spec}) [@var{var_list} (@var{fmt_spec})]@
 
 @cmd{WRITE FORMATS} sets the write formats for the specified variables
 to the specified format specification.  Its syntax is identical to
-that of FORMATS (@pxref{FORMATS}), but @cmd{WRITE FORMATS} sets only
+that of @cmd{FORMATS} (@pxref{FORMATS}), but @cmd{WRITE FORMATS} sets only
 write formats, not print formats.