MODIFY VARS: Remove.
[pspp] / doc / variables.texi
1 @c PSPP - a program for statistical analysis.
2 @c Copyright (C) 2017, 2020 Free Software Foundation, Inc.
3 @c Permission is granted to copy, distribute and/or modify this document
4 @c under the terms of the GNU Free Documentation License, Version 1.3
5 @c or any later version published by the Free Software Foundation;
6 @c with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
7 @c A copy of the license is included in the section entitled "GNU
8 @c Free Documentation License".
9 @c
10 @node Manipulating Variables
11 @chapter Manipulating Variables
12 @cindex Variables
13
14 Every value in a dataset is associated with a @dfn{variable}.
15 Variables describe what the values represent and properties of those values,
16 such as the format in which they should be displayed, whether they are numeric
17 or alphabetic and how missing values should be represented.
18 There are several utility commands for examining and adjusting variables.
19
20 @menu
21 * DISPLAY::                     Display information about the active dataset.
22 * NUMERIC::                     Create new numeric variables.
23 * STRING::                      Create new string variables.
24 * RENAME VARIABLES::            Rename variables.
25 * SORT VARIABLES::              Reorder variables.
26 * DELETE VARIABLES::            Delete variables.
27 * VARIABLE LABELS::             Set variable labels for variables.
28 * PRINT FORMATS::               Set variable print formats.
29 * WRITE FORMATS::               Set variable write formats.
30 * FORMATS::                     Set print and write formats.
31 * VALUE LABELS::                Set value labels for variables.
32 * ADD VALUE LABELS::            Add value labels to variables.
33 * MISSING VALUES::              Set missing values for variables.
34 * VARIABLE ATTRIBUTE::          Set custom attributes on variables.
35 * VARIABLE ALIGNMENT::          Set the alignment for display.
36 * VARIABLE WIDTH::              Set the display width.
37 * VARIABLE LEVEL::              Set the measurement level.
38 * VARIABLE ROLE::               Set the role that a variable fills in analysis.
39 * VECTOR::                      Declare an array of variables.
40 * MRSETS::                      Add, modify, and list multiple response sets.
41 * LEAVE::                       Don't clear variables between cases.
42 @end menu
43
44 @node DISPLAY
45 @section DISPLAY
46 @vindex DISPLAY
47
48 The @cmd{DISPLAY} command displays information about the variables in the active dataset.
49 A variety of different forms of information can be requested.
50 By default, all variables in the active dataset are displayed.  However you can select
51 variables of interest using the @subcmd{/VARIABLES} subcommand.
52
53 @display
54 DISPLAY [SORTED] NAMES [[/VARIABLES=]@var{var_list}].
55 DISPLAY [SORTED] INDEX [[/VARIABLES=]@var{var_list}].
56 DISPLAY [SORTED] LABELS [[/VARIABLES=]@var{var_list}].
57 DISPLAY [SORTED] VARIABLES [[/VARIABLES=]@var{var_list}].
58 DISPLAY [SORTED] DICTIONARY [[/VARIABLES=]@var{var_list}].
59 DISPLAY [SORTED] SCRATCH [[/VARIABLES=]@var{var_list}].
60 DISPLAY [SORTED] ATTRIBUTES [[/VARIABLES=]@var{var_list}].
61 DISPLAY [SORTED] @@ATTRIBUTES [[/VARIABLES=]@var{var_list}].
62 DISPLAY [SORTED] VECTORS.
63 @end display
64
65 The following keywords primarily cause information about variables to
66 be displayed.  With these keywords, by default information is
67 displayed about all variable in the active dataset, in the order that
68 variables occur in the active dataset dictionary.  The @subcmd{SORTED} keyword
69 causes output to be sorted alphabetically by variable name.
70
71 @table @asis
72 @item NAMES
73 The variables' names are displayed.
74
75 @item INDEX
76 The variables' names are displayed along with a value describing their
77 position within the active dataset dictionary.
78
79 @item LABELS
80 Variable names, positions, and variable labels are displayed.
81
82 @item VARIABLES
83 Variable names, positions, print and write formats, and missing values
84 are displayed.
85
86 @item DICTIONARY
87 Variable names, positions, print and write formats, missing values,
88 variable labels, and value labels are displayed.
89
90 @item SCRATCH
91 Variable names are displayed, for scratch variables only (@pxref{Scratch
92 Variables}).
93
94 @item ATTRIBUTES
95 @itemx @@ATTRIBUTES
96 Datafile and variable attributes are displayed.
97 The first form of the command omits those attributes
98 whose names begin with @code{@@} or @code{$@@}.
99 In the second for, all datafile and variable attributes are displayed.
100 @end table
101
102 With the @code{VECTOR} keyword, @cmd{DISPLAY} lists all the currently
103 declared vectors.  If the @subcmd{SORTED} keyword is given, the vectors are
104 listed in alphabetical order; otherwise, they are listed in textual
105 order of definition within the @pspp{} syntax file.
106
107 For related commands, see @ref{DISPLAY DOCUMENTS} and @ref{DISPLAY
108 FILE LABEL}.
109
110 @node NUMERIC
111 @section NUMERIC
112 @vindex NUMERIC
113
114 @cmd{NUMERIC} explicitly declares new numeric variables, optionally
115 setting their output formats.
116
117 @display
118 NUMERIC @var{var_list} [(@var{fmt_spec})] [/@var{var_list} [(@var{fmt_spec})]]@dots{}
119 @end display
120
121 Specify the names of the new numeric variables as @var{var_list}.  If
122 you wish to set the variables' output formats, follow their names by
123 an output format specification in parentheses (@pxref{Input and Output
124 Formats}); otherwise, the default is F8.2.
125
126 Variables created with @cmd{NUMERIC} are initialized to the
127 system-missing value.
128
129 @node STRING
130 @section STRING
131 @vindex STRING
132
133 @cmd{STRING} creates new string variables.
134
135 @display
136 STRING @var{var_list} (@var{fmt_spec}) [/@var{var_list} (@var{fmt_spec})] [@dots{}].
137 @end display
138
139 Specify a list of names for the variable you want to create,
140 followed by the desired output format specification in
141 parentheses (@pxref{Input and Output Formats}).
142 Variable widths are
143 implicitly derived from the specified output formats.
144 The created variables will be initialized to spaces.
145
146 If you want to create several variables with  distinct
147 output formats, you can either use two or more separate @cmd{STRING} commands,
148 or you can specify further variable list and format specification pairs, each separated
149 from the previous by a slash (@samp{/}).
150
151 The following example is one way to create three string variables; Two of the
152 variables have format A24 and the other A80:
153 @example
154 STRING firstname lastname (A24) / address (A80).
155 @end example
156
157 @noindent Here is another way to achieve the same result:
158 @example
159 STRING firstname lastname (A24).
160 STRING address (A80).
161 @end example
162
163 @noindent @dots{} and here is yet another way:
164
165 @example
166 STRING firstname (A24).
167 STRING lastname (A24).
168 STRING address (A80).
169 @end example
170
171 @node RENAME VARIABLES
172 @section RENAME VARIABLES
173 @vindex RENAME VARIABLES
174
175 @cmd{RENAME VARIABLES} changes the names of variables in the active
176 dataset.
177
178 @display
179 RENAME VARIABLES (@var{old_names}=@var{new_names})@dots{} .
180 @end display
181
182 Specify lists of the old variable names and new
183 variable names, separated by an equals sign (@samp{=}), within
184 parentheses.  There must be the same number of old and new variable
185 names.  Each old variable is renamed to the corresponding new variable
186 name.  Multiple parenthesized groups of variables may be specified.
187 When the old and new variable names contain only a single variable name,
188 the parentheses are optional.
189
190 @cmd{RENAME VARIABLES} takes effect immediately.  It does not cause the data
191 to be read.
192
193 @cmd{RENAME VARIABLES} may not be specified following @cmd{TEMPORARY}
194 (@pxref{TEMPORARY}).
195
196 @node SORT VARIABLES
197 @section SORT VARIABLES
198 @vindex SORT VARIABLES
199
200 @cmd{SORT VARIABLES} reorders the variables in the active dataset's dictionary
201 according to a chosen sort key.
202
203 @display
204 SORT VARIABLES [BY]
205     (NAME | TYPE | FORMAT | LABEL | VALUES | MISSING | MEASURE
206      | ROLE | COLUMNS | ALIGNMENT | ATTRIBUTE @var{name})
207     [(D)].
208 @end display
209
210 The main specification is one of the following identifiers, which
211 determines how the variables are sorted:
212
213 @table @asis
214 @item NAME
215 Sorts the variables according to their names, in a case-insensitive
216 fashion.  However, when variable names differ only in a number at the
217 end, they are sorted numerically.  For example, @code{VAR5} is sorted
218 before @code{VAR400} even though @samp{4} precedes @samp{5}.
219
220 @item TYPE
221 Sorts numeric variables before string variables, and shorter string
222 variables before longer ones.
223
224 @item FORMAT
225 Groups variables by print format; within a format, sorts narrower
226 formats before wider ones; with the same format and width, sorts fewer
227 decimal places before more decimal places.
228 @xref{FORMATS}.
229
230 @item LABEL
231 Sorts variables without a variable label before those with one.
232 @xref{VARIABLE LABELS}.
233
234 @item VALUES
235 Sorts variables without value labels before those with some.
236 @xref{VALUE LABELS}.
237
238 @item MISSING
239 Sorts variables without missing values before those with some.
240 @xref{MISSING VALUES}.
241
242 @item MEASURE
243 Sorts nominal variables first, followed by ordinal variables, followed
244 by scale variables.  @xref{VARIABLE LEVEL}.
245
246 @item ROLE
247 Groups variables according to their role.  @xref{VARIABLE ROLE}.
248
249 @item COLUMNS
250 Sorts variables in ascending display width.  @xref{VARIABLE WIDTH}.
251
252 @item ALIGNMENT
253 Sorts variables according to their alignment, first left-aligned, then
254 right-aligned, then centered.  @xref{VARIABLE ALIGNMENT}.
255
256 @item ATTRIBUTE @var{name}
257 Sorts variables according to the first value of their @var{name}
258 attribute.  Variables without attribute are sorted first.
259 @xref{VARIABLE ATTRIBUTE}.
260 @end table
261
262 Only one sort criterion can be specified.  The sort is ``stable,'' so
263 to sort on multiple criteria one may perform multiple sorts.  For
264 example, the following will sort primarily based on alignment, with
265 variables that have the same alignment ordered based on display width:
266
267 @example
268 SORT VARIABLES BY COLUMNS.
269 SORT VARIABLES BY ALIGNMENT.
270 @end example
271
272 Specify @code{(D)} to reverse the sort order.
273
274 @node DELETE VARIABLES
275 @section DELETE VARIABLES
276 @vindex DELETE VARIABLES
277
278 @cmd{DELETE VARIABLES} deletes the specified variables from the dictionary.
279
280 @display
281 DELETE VARIABLES @var{var_list}.
282 @end display
283
284 @cmd{DELETE VARIABLES} should not be used after defining transformations
285 but before executing a procedure.  If it is used in such a context, it
286 causes the data to be read.  If it is used while @cmd{TEMPORARY} is in
287 effect, it causes the temporary transformations to become permanent.
288
289 @cmd{DELETE VARIABLES} may not be used to delete all variables from the
290 dictionary; use @cmd{NEW FILE} to do that (@pxref{NEW FILE}).
291
292 @node VARIABLE LABELS
293 @section VARIABLE LABELS
294 @vindex VARIABLE LABELS
295
296 In addition to a variable's name, each variable can have a @dfn{label}.
297 Whereas the name is limited to certain constraints (@pxref{Attributes}) a variable's
298 label has no such constraints.
299 Typically, the names are concise, easy to type mnemonics for the variable
300 and the labels are longer, more verbose descriptions.
301
302 @display
303 VARIABLE LABELS
304         @var{var_list} '@var{var_label}'
305         [ /@var{var_list} '@var{var_label}']
306         .
307         .
308         .
309         [ /@var{var_list} '@var{var_label}']
310 @end display
311
312 @cmd{VARIABLE LABELS} associates explanatory names
313 with variables.  This name, called a @dfn{variable label}, is displayed by
314 statistical procedures.
315
316 To assign a variable label to a group of variables, specify a
317 list of variable names and the variable label as a string.
318 To assign different labels to different variables in the same command,
319 precede the subsequent variable list with a slash (@samp{/}).
320
321 @node PRINT FORMATS
322 @section PRINT FORMATS
323 @vindex PRINT FORMATS
324
325 @display
326 PRINT FORMATS @var{var_list} (@var{fmt_spec}) [@var{var_list} (@var{fmt_spec})]@dots{}.
327 @end display
328
329 @cmd{PRINT FORMATS} sets the print formats for the specified
330 variables to the specified format specification.
331
332 Its syntax is identical to that of @cmd{FORMATS} (@pxref{FORMATS}),
333 but @cmd{PRINT FORMATS} sets only print formats, not write formats.
334
335 @node WRITE FORMATS
336 @section WRITE FORMATS
337 @vindex WRITE FORMATS
338
339 @display
340 WRITE FORMATS @var{var_list} (@var{fmt_spec}) [@var{var_list} (@var{fmt_spec})]@dots{}.
341 @end display
342
343 @cmd{WRITE FORMATS} sets the write formats for the specified variables
344 to the specified format specification.  Its syntax is identical to
345 that of @cmd{FORMATS} (@pxref{FORMATS}), but @cmd{WRITE FORMATS} sets only
346 write formats, not print formats.
347
348 @node FORMATS
349 @section FORMATS
350 @vindex FORMATS
351
352 @display
353 FORMATS @var{var_list} (@var{fmt_spec}) [@var{var_list} (@var{fmt_spec})]@dots{}.
354 @end display
355
356 @cmd{FORMATS} set both print and write formats for the specified
357 variables to the specified format specification.
358 @xref{Input and Output Formats}.
359
360 Specify a list of variables followed by a format specification in
361 parentheses.  The print and write formats of the specified variables
362 will be changed.  All of the variables listed together must have
363 the same type and, for string variables, the same width.
364
365 Additional lists of variables and formats may be included following
366 the first one.
367
368 @cmd{FORMATS} takes effect immediately.  It is not affected by
369 conditional and looping structures such as @cmd{DO IF} or @cmd{LOOP}.
370
371 @node VALUE LABELS
372 @section VALUE LABELS
373 @vindex VALUE LABELS
374
375 The values of a variable can be associated with an arbitrary text string.
376 In this way, a short value can stand for a longer, more descriptive label.
377
378 Both numeric and string variables can be given labels.  For string
379 variables, the values are case-sensitive, so that, for example, a
380 capitalized value and its lowercase variant would have to be labeled
381 separately if both are present in the data.
382
383 @display
384 VALUE LABELS
385         /@var{var_list} @var{value} '@var{label}' [@var{value} '@var{label}']@dots{}
386 @end display
387
388 @cmd{VALUE LABELS} allows values of variables to be associated with labels.
389
390 To set up value labels for one or more variables, specify the
391 variable names after a slash (@samp{/}), followed by a list of values
392 and their associated labels, separated by spaces.
393
394 Value labels in output are normally broken into lines automatically.
395 Put @samp{\n} in a label string to force a line break at that point.
396 The label may still be broken into lines at additional points.
397
398 Before @cmd{VALUE LABELS} is executed, any existing value labels
399 are cleared from the variables specified.  Use @cmd{ADD VALUE LABELS}
400 (@pxref{ADD VALUE LABELS}) to add value labels without clearing those
401 already present.
402
403 @node ADD VALUE LABELS
404 @section ADD VALUE LABELS
405 @vindex ADD VALUE LABELS
406
407 @cmd{ADD VALUE LABELS} has the same syntax and purpose as @cmd{VALUE
408 LABELS} (@pxref{VALUE LABELS}), but it does not clear value
409 labels from the variables before adding the ones specified.
410
411 @display
412 ADD VALUE LABELS
413         /@var{var_list} @var{value} '@var{label}' [@var{value} '@var{label}']@dots{}
414 @end display
415
416
417 @node MISSING VALUES
418 @section MISSING VALUES
419 @vindex MISSING VALUES
420
421 In many situations the data available for analysis is incomplete and a placeholder
422 must be used in place of a value to indicate that the value is unknown.  One way
423 that missing values are represented is through the $SYSMIS variable
424 (@pxref{System Variables}).  Another, more flexible way is through
425 @dfn{user-missing values} which are determined on a per variable basis.
426
427 The @cmd{MISSING VALUES} command sets user-missing values for variables.
428
429 @display
430 MISSING VALUES @var{var_list} (@var{missing_values}).
431
432 where @var{missing_values} takes one of the following forms:
433         @var{num1}
434         @var{num1}, @var{num2}
435         @var{num1}, @var{num2}, @var{num3}
436         @var{num1} THRU @var{num2}
437         @var{num1} THRU @var{num2}, @var{num3}
438         @var{string1}
439         @var{string1}, @var{string2}
440         @var{string1}, @var{string2}, @var{string3}
441 As part of a range, @subcmd{LO} or @subcmd{LOWEST} may take the place of @var{num1};
442 @subcmd{HI} or @subcmd{HIGHEST} may take the place of @var{num2}.
443 @end display
444
445 @cmd{MISSING VALUES} sets user-missing values for numeric and string
446 variables.  Long string variables may have missing values, but
447 characters after the first 8 bytes of the missing value must be
448 spaces.
449
450 Specify a list of variables, followed by a list of their user-missing
451 values in parentheses.  Up to three discrete values may be given, or,
452 for numeric variables only, a range of values optionally accompanied by
453 a single discrete value.  Ranges may be open-ended on one end, indicated
454 through the use of the
455 keyword @subcmd{LO} or @subcmd{LOWEST} or @subcmd{HI} or @subcmd{HIGHEST}.
456
457 The @cmd{MISSING VALUES} command takes effect immediately.  It is not
458 affected by conditional and looping constructs such as @cmd{DO IF} or
459 @cmd{LOOP}.
460
461 @node VARIABLE ATTRIBUTE
462 @section VARIABLE ATTRIBUTE
463 @vindex VARIABLE ATTRIBUTE
464
465 @cmd{VARIABLE ATTRIBUTE} adds, modifies, or removes user-defined
466 attributes associated with variables in the active dataset.  Custom
467 variable attributes are not interpreted by @pspp{}, but they are saved as
468 part of system files and may be used by other software that reads
469 them.
470
471 @display
472 VARIABLE ATTRIBUTE
473          VARIABLES=@var{var_list}
474          ATTRIBUTE=@var{name}('@var{value}') [@var{name}('@var{value}')]@dots{}
475          ATTRIBUTE=@var{name}@b{[}@var{index}@b{]}('@var{value}') [@var{name}@b{[}@var{index}@b{]}('@var{value}')]@dots{}
476          DELETE=@var{name} [@var{name}]@dots{}
477          DELETE=@var{name}@b{[}@var{index}@b{]} [@var{name}@b{[}@var{index}@b{]}]@dots{}
478 @end display
479
480 The required @subcmd{VARIABLES} subcommand must come first.  Specify the
481 variables to which the following @subcmd{ATTRIBUTE} or @subcmd{DELETE} subcommand
482 should apply.
483
484 Use the @subcmd{ATTRIBUTE} subcommand to add or modify custom variable
485 attributes.  Specify the name of the attribute as an identifier
486 (@pxref{Tokens}), followed by the desired value, in parentheses, as a
487 quoted string.  The specified attributes are then added or modified in
488 the variables specified on @subcmd{VARIABLES}.  Attribute names that begin with
489 @code{$} are reserved for @pspp{}'s internal use, and attribute names
490 that begin with @code{@@} or @code{$@@} are not displayed by most @pspp{}
491 commands that display other attributes.  Other attribute names are not
492 treated specially.
493
494 Attributes may also be organized into arrays.  To assign to an array
495 element, add an integer array index enclosed in square brackets
496 (@code{[} and @code{]}) between the attribute name and value.  Array
497 indexes start at 1, not 0.  An attribute array that has a single
498 element (number 1) is not distinguished from a non-array attribute.
499
500 Use the @subcmd{DELETE} subcommand to delete an attribute from the variable
501 specified on @subcmd{VARIABLES}.  Specify an attribute name by itself to delete
502 an entire attribute, including all array elements for attribute
503 arrays.  Specify an attribute name followed by an array index in
504 square brackets to delete a single element of an attribute array.  In
505 the latter case, all the array elements numbered higher than the
506 deleted element are shifted down, filling the vacated position.
507
508 To associate custom attributes with the entire active dataset, instead of
509 with particular variables, use @cmd{DATAFILE ATTRIBUTE} (@pxref{DATAFILE ATTRIBUTE}) instead.
510
511 @cmd{VARIABLE ATTRIBUTE} takes effect immediately.  It is not affected
512 by conditional and looping structures such as @cmd{DO IF} or
513 @cmd{LOOP}.
514
515 @node VARIABLE ALIGNMENT
516 @section VARIABLE ALIGNMENT
517 @vindex VARIABLE ALIGNMENT
518
519 @cmd{VARIABLE ALIGNMENT} sets the alignment of variables for display editing
520 purposes.   It  does not affect the display of variables in the @pspp{} output.
521
522 @display
523 VARIABLE ALIGNMENT
524         @var{var_list} ( LEFT | RIGHT | CENTER )
525         [ /@var{var_list} ( LEFT | RIGHT | CENTER ) ]
526         .
527         .
528         .
529         [ /@var{var_list} ( LEFT | RIGHT | CENTER ) ]
530 @end display
531
532 @node VARIABLE WIDTH
533 @section VARIABLE WIDTH
534 @vindex VARIABLE WIDTH
535 @display
536 VARIABLE WIDTH
537         @var{var_list} (width)
538         [ /@var{var_list} (width) ]
539         .
540         .
541         .
542         [ /@var{var_list} (width) ]
543 @end display
544
545 @cmd{VARIABLE WIDTH} sets the column width of variables for display editing
546 purposes.   It does not affect the display of variables in the @pspp{} output.
547
548
549 @node VARIABLE LEVEL
550 @section VARIABLE LEVEL
551 @vindex VARIABLE LEVEL
552 @display
553 @t{VARIABLE LEVEL} @i{variables} @t{(}@{@t{SCALE} @math{|} @t{NOMINAL} @math{|} @t{ORDINAL}@}@t{)}@dots{}
554 @end display
555
556 @cmd{VARIABLE LEVEL} sets the measurement level of @var{variables} as
557 specified.  @xref{Attributes}, for the definitions of the available
558 measurement levels.
559
560 @node VARIABLE ROLE
561 @section VARIABLE ROLE
562 @vindex VARIABLE ROLE
563 @display
564 VARIABLE ROLE
565         /@var{role} @var{var_list}
566         [/@var{role} @var{var_list}]@dots{}
567 @end display
568
569 @cmd{VARIABLE ROLE} sets the intended role of a variable for use in
570 dialog boxes in graphical user interfaces.  Each @var{role} specifies
571 one of the following roles for the variables that follow it:
572
573 @table @code
574 @item INPUT
575 An input variable, such as an independent variable.
576
577 @item TARGET
578 An output variable, such as an dependent variable.
579
580 @item BOTH
581 A variable used for input and output.
582
583 @item NONE
584 No role assigned.  (This is a variable's default role.)
585
586 @item PARTITION
587 Used to break the data into groups for testing.
588
589 @item SPLIT
590 No meaning except for certain third party software.  (This role's
591 meaning is unrelated to @cmd{SPLIT FILE}.)
592 @end table
593
594 The PSPPIRE GUI does not yet use variable roles as intended.
595
596 @node VECTOR
597 @section VECTOR
598 @vindex VECTOR
599
600 @display
601 Two possible syntaxes:
602         VECTOR @var{vec_name}=@var{var_list}.
603         VECTOR @var{vec_name_list}(@var{count} [@var{format}]).
604 @end display
605
606 @cmd{VECTOR} allows a group of variables to be accessed as if they
607 were consecutive members of an array with a vector(index) notation.
608
609 To make a vector out of a set of existing variables, specify a name
610 for the vector followed by an equals sign (@samp{=}) and the variables
611 to put in the vector.  The variables must be all numeric or all
612 string, and string variables must have the same width.
613
614 To make a vector and create variables at the same time, specify one or
615 more vector names followed by a count in parentheses.  This will
616 create variables named @code{@var{vec}1} through
617 @code{@var{vec}@var{count}}.  By default, the new variables are
618 numeric with format F8.2, but an alternate format may be specified
619 inside the parentheses before or after the count and separated from it
620 by white space or a comma.  With a string format such as A8, the
621 variables will be string variables; with a numeric format, they will
622 be numeric.  Variable names including the suffixes may not exceed 64
623 characters in length, and none of the variables may exist prior to
624 @cmd{VECTOR}.
625
626 Vectors created with @cmd{VECTOR} disappear after any procedure or
627 procedure-like command is executed.  The variables contained in the
628 vectors remain, unless they are scratch variables (@pxref{Scratch
629 Variables}).
630
631 Variables within a vector may be referenced in expressions using
632 @code{vector(index)} syntax.
633
634 @node MRSETS
635 @section MRSETS
636 @vindex MRSETS
637
638 @cmd{MRSETS} creates, modifies, deletes, and displays multiple
639 response sets.  A multiple response set is a set of variables that
640 represent multiple responses to a survey question.
641
642 Multiple responses are represented in one of the two following ways:
643
644 @itemize @bullet
645 @item
646 A @dfn{multiple dichotomy set} is analogous to a survey question with
647 a set of checkboxes.  Each variable in the set is treated in a Boolean
648 fashion: one value (the "counted value") means that the box was
649 checked, and any other value means that it was not.
650
651 @item
652 A @dfn{multiple category set} represents a survey question where the
653 respondent is instructed to list up to @var{n} choices.  Each variable
654 represents one of the responses.
655 @end itemize
656
657 @display
658 MRSETS
659     /MDGROUP NAME=@var{name} VARIABLES=@var{var_list} VALUE=@var{value}
660      [CATEGORYLABELS=@{VARLABELS,COUNTEDVALUES@}]
661      [@{LABEL='@var{label}',LABELSOURCE=VARLABEL@}]
662
663     /MCGROUP NAME=@var{name} VARIABLES=@var{var_list} [LABEL='@var{label}']
664
665     /DELETE NAME=@{[@var{names}],ALL@}
666
667     /DISPLAY NAME=@{[@var{names}],ALL@}
668 @end display
669
670
671 Any number of subcommands may be specified in any order.
672
673 The @subcmd{MDGROUP} subcommand creates a new multiple dichotomy set or
674 replaces an existing multiple response set.  The @subcmd{NAME},
675 @subcmd{VARIABLES}, and
676 @subcmd{VALUE} specifications are required.  The others are optional:
677
678 @itemize @bullet
679 @item
680 @var{NAME} specifies the name used in syntax for the new multiple dichotomy
681 set.  The name must begin with @samp{$}; it must otherwise follow the
682 rules for identifiers (@pxref{Tokens}).
683
684 @item
685 @subcmd{VARIABLES} specifies the variables that belong to the set.  At least
686 two variables must be specified.  The variables must be all string or
687 all numeric.
688
689 @item
690 @subcmd{VALUE} specifies the counted value.  If the variables are numeric, the
691 value must be an integer.  If the variables are strings, then the
692 value must be a string that is no longer than the shortest of the
693 variables in the set (ignoring trailing spaces).
694
695 @item
696 @subcmd{CATEGORYLABELS} optionally specifies the source of the labels for each
697 category in the set:
698
699 @itemize @minus
700 @item
701 @subcmd{VARLABELS}, the default, uses variable labels or, for variables without
702 variable labels, variable names.  @pspp{} warns if two variables have the
703 same variable label, since these categories cannot be distinguished in
704 output.
705
706 @item
707 @subcmd{COUNTEDVALUES} instead uses each variable's value label for the counted
708 value.  @pspp{} warns if two variables have the same value label for the
709 counted value or if one of the variables lacks a value label, since
710 such categories cannot be distinguished in output.
711 @end itemize
712
713 @item
714 @subcmd{LABEL} optionally specifies a label for the multiple response set.  If
715 neither @subcmd{LABEL} nor @subcmd{LABELSOURCE=VARLABEL} is specified, the set is
716 unlabeled.
717
718 @item
719 @subcmd{LABELSOURCE=VARLABEL} draws the multiple response set's label from the
720 first variable label among the variables in the set; if none of the
721 variables has a label, the name of the first variable is used.
722 @subcmd{LABELSOURCE=VARLABEL} must be used with @subcmd{CATEGORYLABELS=COUNTEDVALUES}.
723 It is mutually exclusive with @subcmd{LABEL}.
724 @end itemize
725
726 The @subcmd{MCGROUP} subcommand creates a new multiple category set or
727 replaces an existing multiple response set.  The @subcmd{NAME} and @subcmd{VARIABLES}
728 specifications are required, and @subcmd{LABEL} is optional.  Their meanings
729 are as described above in @subcmd{MDGROUP}.  @pspp{} warns if two variables in the
730 set have different value labels for a single value, since each of the
731 variables in the set should have the same possible categories.
732
733 The @subcmd{DELETE} subcommand deletes multiple response groups.  A list of
734 groups may be named within a set of required square brackets, or ALL
735 may be used to delete all groups.
736
737 The @subcmd{DISPLAY} subcommand displays information about defined multiple
738 response sets.  Its syntax is the same as the @subcmd{DELETE} subcommand.
739
740 Multiple response sets are saved to and read from system files by,
741 @i{e.g.}, the @cmd{SAVE} and @cmd{GET} command.  Otherwise, multiple
742 response sets are currently used only by third party software.
743
744 @node LEAVE
745 @section LEAVE
746 @vindex LEAVE
747
748 @cmd{LEAVE} prevents the specified variables from being
749 reinitialized whenever a new case is processed.
750
751 @display
752 LEAVE @var{var_list}.
753 @end display
754
755 Normally, when a data file is processed, every variable in the active
756 dataset is initialized to the system-missing value or spaces at the
757 beginning of processing for each case.  When a variable has been
758 specified on @cmd{LEAVE}, this is not the case.  Instead, that variable is
759 initialized to 0 (not system-missing) or spaces for the first case.
760 After that, it retains its value between cases.
761
762 This becomes useful for counters.  For instance, in the example below
763 the variable @code{SUM} maintains a running total of the values in the @code{ITEM}
764 variable.
765
766 @example
767 DATA LIST /ITEM 1-3.
768 COMPUTE SUM=SUM+ITEM.
769 PRINT /ITEM SUM.
770 LEAVE SUM
771 BEGIN DATA.
772 123
773 404
774 555
775 999
776 END DATA.
777 @end example
778
779 @noindent Partial output from this example:
780
781 @example
782 123   123.00
783 404   527.00
784 555  1082.00
785 999  2081.00
786 @end example
787
788 It is best to use @cmd{LEAVE} command immediately before invoking a
789 procedure command, because the left status of variables is reset by
790 certain transformations---for instance, @cmd{COMPUTE} and @cmd{IF}.
791 Left status is also reset by all procedure invocations.
792