@section VARIABLE LABELS
@vindex VARIABLE LABELS
-In addition to a variable's name, each variable can have a @dfn{label}.
-Whereas the name is limited to certain constraints (@pxref{Attributes}) a variable's
-label has no such constraints.
-Typically, the names are concise, easy to type mnemonics for the variable
-and the labels are longer, more verbose descriptions.
+In addition to a variable's name, each variable can have a
+@dfn{label}. Whereas a variable name is a concise, easy-to-type
+mnemonic for the variable, a label may be longer and more descriptive.
@display
VARIABLE LABELS
- @var{var_list} '@var{var_label}'
- [ /@var{var_list} '@var{var_label}']
- .
- .
- .
- [ /@var{var_list} '@var{var_label}']
+ @var{variable} '@var{label}'
+ [@var{variable} '@var{label}']@dots{}
@end display
@cmd{VARIABLE LABELS} associates explanatory names
with variables. This name, called a @dfn{variable label}, is displayed by
statistical procedures.
-To assign a variable label to a group of variables, specify a
-list of variable names and the variable label as a string.
-To assign different labels to different variables in the same command,
-precede the subsequent variable list with a slash (@samp{/}).
+Specify each variable followed by its label as a quoted string.
+Variable-label pairs may be separated by an optional slash @samp{/}.
+
+If a listed variable already has a label, the new one replaces it.
+Specifying an empty string as the label, e.g.@:@samp{''}, removes a
+label.
@node PRINT FORMATS
@section PRINT FORMATS
/* Sets V's variable label to UTF-8 encoded string LABEL, stripping off leading
and trailing white space. If LABEL is a null pointer or if LABEL is an
- empty string (after stripping white space), then V's variable label (if any)
- is removed. */
+ empty string, then V's variable label (if any) is removed. */
static void
var_set_label_quiet (struct variable *v, const char *label)
{
free (v->label);
v->label = NULL;
- if (label != NULL && label[strspn (label, CC_SPACES)])
+ if (label != NULL && label[0])
v->label = xstrdup (label);
ds_destroy (&v->name_and_label);
ds_init_empty (&v->name_and_label);
}
-
-
/* Sets V's variable label to UTF-8 encoded string LABEL, stripping off leading
and trailing white space. If LABEL is a null pointer or if LABEL is an
empty string (after stripping white space), then V's variable label (if any)
dict_var_changed (v, VAR_TRAIT_LABEL, ov);
}
-
/* Removes any variable label from V. */
void
var_clear_label (struct variable *v)
.variable = {
.type = PIVOT_VALUE_VARIABLE,
.var_name = xstrdup (name),
- .var_label = xstrdup_if_nonempty (label),
+ .var_label = xstrdup_if_nonnull (label),
},
};
return value;
tests/language/commands/title.at \
tests/language/commands/update.at \
tests/language/commands/value-labels.at \
+ tests/language/commands/variable-labels.at \
tests/language/commands/variable-display.at \
tests/language/commands/vector.at \
tests/language/commands/weight.at \
--- /dev/null
+AT_BANNER([VARIABLE LABELS])
+
+AT_SETUP([VARIABLE LABELS])
+AT_DATA([var-labels.sps], [dnl
+DATA LIST LIST NOTABLE/x y z.
+VARIABLE LABELS x 'First variable' y ' '.
+BEGIN DATA.
+1 2 3
+4 5 6
+END DATA.
+DESCRIPTIVES x y z.
+])
+AT_CHECK([pspp -O box=unicode var-labels.sps], [0], [dnl
+ Descriptive Statistics
+╭────────────────────┬─┬────┬───────┬───────┬───────╮
+│ │N│Mean│Std Dev│Minimum│Maximum│
+├────────────────────┼─┼────┼───────┼───────┼───────┤
+│First variable │2│2.50│ 2.12│ 1.00│ 4.00│
+│ │2│3.50│ 2.12│ 2.00│ 5.00│
+│z │2│4.50│ 2.12│ 3.00│ 6.00│
+│Valid N (listwise) │2│ │ │ │ │
+│Missing N (listwise)│0│ │ │ │ │
+╰────────────────────┴─┴────┴───────┴───────┴───────╯
+])
+AT_CLEANUP
\ No newline at end of file