1 @node Variable Attributes, Data Manipulation, System and Portable Files, Top
2 @chapter Manipulating variables
4 The variables in the active file dictionary are important. There are
5 several utility functions for examining and adjusting them.
8 * ADD VALUE LABELS:: Add value labels to variables.
9 * DISPLAY:: Display variable names & descriptions.
10 * DISPLAY VECTORS:: Display a list of vectors.
11 * FORMATS:: Set print and write formats.
12 * LEAVE:: Don't clear variables between cases.
13 * MISSING VALUES:: Set missing values for variables.
14 * MODIFY VARS:: Rename, reorder, and drop variables.
15 * NUMERIC:: Create new numeric variables.
16 * PRINT FORMATS:: Set variable print formats.
17 * RENAME VARIABLES:: Rename variables.
18 * VALUE LABELS:: Set value labels for variables.
19 * STRING:: Create new string variables.
20 * VARIABLE LABELS:: Set variable labels for variables.
21 * VECTOR:: Declare an array of variables.
22 * WRITE FORMATS:: Set variable write formats.
25 @node ADD VALUE LABELS, DISPLAY, Variable Attributes, Variable Attributes
26 @section ADD VALUE LABELS
27 @vindex ADD VALUE LABELS
31 /var_list value 'label' [value 'label']@dots{}
34 @cmd{ADD VALUE LABELS} has the same syntax and purpose as @cmd{VALUE
35 LABELS} (@pxref{VALUE LABELS}), but it does not clear value
36 labels from the variables before adding the ones specified.
38 @node DISPLAY, DISPLAY VECTORS, ADD VALUE LABELS, Variable Attributes
43 DISPLAY @{NAMES,INDEX,LABELS,VARIABLES,DICTIONARY,SCRATCH@}
47 @cmd{DISPLAY} displays requested information on variables. Variables can
48 optionally be sorted alphabetically. The entire dictionary or just
49 specified variables can be described.
51 One of the following keywords can be present:
55 The variables' names are displayed.
58 The variables' names are displayed along with a value describing their
59 position within the active file dictionary.
62 Variable names, positions, and variable labels are displayed.
65 Variable names, positions, print and write formats, and missing values
69 Variable names, positions, print and write formats, missing values,
70 variable labels, and value labels are displayed.
73 Varible names are displayed, for scratch variables only (@pxref{Scratch
77 If SORTED is specified, then the variables are displayed in ascending
78 order based on their names; otherwise, they are displayed in the order
79 that they occur in the active file dictionary.
81 @node DISPLAY VECTORS, FORMATS, DISPLAY, Variable Attributes
82 @section DISPLAY VECTORS
83 @vindex DISPLAY VECTORS
89 @cmd{DISPLAY VECTORS} lists all the currently declared vectors.
91 @node FORMATS, LEAVE, DISPLAY VECTORS, Variable Attributes
96 FORMATS var_list (fmt_spec).
99 @cmd{FORMATS} set both print and write formats for the specified
100 numeric variables to the specified format specification.
101 @xref{Input/Output Formats}.
103 Specify a list of variables followed by a format specification in
104 parentheses. The print and write formats of the specified variables
107 Additional lists of variables and formats may be included if they are
108 delimited by a slash (@samp{/}).
110 @cmd{FORMATS} takes effect immediately. It is not affected by
111 conditional and looping structures such as @cmd{DO IF} or @cmd{LOOP}.
113 @node LEAVE, MISSING VALUES, FORMATS, Variable Attributes
121 @cmd{LEAVE} prevents the specified variables from being
122 reinitialized whenever a new case is processed.
124 Normally, when a data file is processed, every variable in the active
125 file is initialized to the system-missing value or spaces at the
126 beginning of processing for each case. When a variable has been
127 specified on @cmd{LEAVE}, this is not the case. Instead, that variable is
128 initialized to 0 (not system-missing) or spaces for the first case.
129 After that, it retains its value between cases.
131 This becomes useful for counters. For instance, in the example below
132 the variable SUM maintains a running total of the values in the ITEM
137 COMPUTE SUM=SUM+ITEM.
148 @noindent Partial output from this example:
157 It is best to use @cmd{LEAVE} command immediately before invoking a
158 procedure command, because the left status of variables is reset by
159 certain transformations---for instance, @cmd{COMPUTE} and @cmd{IF}.
160 Left status is also reset by all procedure invocations.
162 @node MISSING VALUES, MODIFY VARS, LEAVE, Variable Attributes
163 @section MISSING VALUES
164 @vindex MISSING VALUES
167 MISSING VALUES var_list (missing_values).
169 missing_values takes one of the following forms:
177 string1, string2, string3
178 As part of a range, LO or LOWEST may take the place of num1;
179 HI or HIGHEST may take the place of num2.
182 @cmd{MISSING VALUES} sets user-missing values for numeric and
183 short string variables. Long string variables may not have missing
186 Specify a list of variables, followed by a list of their user-missing
187 values in parentheses. Up to three discrete values may be given, or,
188 for numeric variables only, a range of values optionally accompanied by
189 a single discrete value. Ranges may be open-ended on one end, indicated
190 through the use of the keyword LO or LOWEST or HI or HIGHEST.
192 The @cmd{MISSING VALUES} command takes effect immediately. It is not
193 affected by conditional and looping constructs such as @cmd{DO IF} or
196 @node MODIFY VARS, NUMERIC, MISSING VALUES, Variable Attributes
202 /REORDER=@{FORWARD,BACKWARD@} @{POSITIONAL,ALPHA@} (var_list)@dots{}
203 /RENAME=(old_names=new_names)@dots{}
204 /@{DROP,KEEP@}=var_list
208 @cmd{MODIFY VARS} reorders, renames, and deletes variables in the
211 At least one subcommand must be specified, and no subcommand may be
212 specified more than once. DROP and KEEP may not both be specified.
214 The REORDER subcommand changes the order of variables in the active
215 file. Specify one or more lists of variable names in parentheses. By
216 default, each list of variables is rearranged into the specified order.
217 To put the variables into the reverse of the specified order, put
218 keyword BACKWARD before the parentheses. To put them into alphabetical
219 order in the dictionary, specify keyword ALPHA before the parentheses.
220 BACKWARD and ALPHA may also be combined.
222 To rename variables in the active file, specify RENAME, an equals sign
223 (@samp{=}), and lists of the old variable names and new variable names
224 separated by another equals sign within parentheses. There must be the
225 same number of old and new variable names. Each old variable is renamed to
226 the corresponding new variable name. Multiple parenthesized groups of
227 variables may be specified.
229 The DROP subcommand deletes a specified list of variables from the
232 The KEEP subcommand keeps the specified list of variables in the active
233 file. Any unlisted variables are deleted from the active file.
235 MAP is currently ignored.
237 If either DROP or KEEP is specified, the data is read; otherwise it is
240 @cmd{MODIFY VARS} may not be specified following @cmd{TEMPORARY}
243 @node NUMERIC, PRINT FORMATS, MODIFY VARS, Variable Attributes
248 NUMERIC /var_list [(fmt_spec)].
251 @cmd{NUMERIC} explicitly declares new numeric variables, optionally
252 setting their output formats.
254 Specify a slash (@samp{/}), followed by the names of the new numeric
255 variables. If you wish to set their output formats, follow their names
256 by an output format specification in parentheses (@pxref{Input/Output
257 Formats}); otherwise, the default is F8.2.
259 Variables created with @cmd{NUMERIC} are initialized to the
260 system-missing value.
262 @node PRINT FORMATS, RENAME VARIABLES, NUMERIC, Variable Attributes
263 @section PRINT FORMATS
264 @vindex PRINT FORMATS
267 PRINT FORMATS var_list (fmt_spec).
270 @cmd{PRINT FORMATS} sets the print formats for the specified
271 numeric variables to the specified format specification.
273 Its syntax is identical to that of @cmd{FORMATS} (@pxref{FORMATS}),
274 but @cmd{PRINT FORMATS} sets only print formats, not write formats.
276 @node RENAME VARIABLES, VALUE LABELS, PRINT FORMATS, Variable Attributes
277 @section RENAME VARIABLES
278 @vindex RENAME VARIABLES
281 RENAME VARIABLES (old_names=new_names)@dots{} .
284 @cmd{RENAME VARIABLES} changes the names of variables in the active
285 file. Specify lists of the old variable names and new
286 variable names, separated by an equals sign (@samp{=}), within
287 parentheses. There must be the same number of old and new variable
288 names. Each old variable is renamed to the corresponding new variable
289 name. Multiple parenthesized groups of variables may be specified.
291 @cmd{RENAME VARIABLES} takes effect immediately. It does not cause the data
294 @cmd{RENAME VARIABLES} may not be specified following @cmd{TEMPORARY}
297 @node VALUE LABELS, STRING, RENAME VARIABLES, Variable Attributes
298 @section VALUE LABELS
303 /var_list value 'label' [value 'label']@dots{}
306 @cmd{VALUE LABELS} allows values of numeric and short string
307 variables to be associated with labels. In this way, a short value can
308 stand for a long value.
310 To set up value labels for a set of variables, specify the
311 variable names after a slash (@samp{/}), followed by a list of values
312 and their associated labels, separated by spaces. Long string
313 variables may not be specified.
315 Before @cmd{VALUE LABELS} is executed, any existing value labels
316 are cleared from the variables specified. Use @cmd{ADD VALUE LABELS}
317 (@pxref{ADD VALUE LABELS}) to add value labels without clearing those
320 @node STRING, VARIABLE LABELS, VALUE LABELS, Variable Attributes
325 STRING /var_list (fmt_spec).
328 @cmd{STRING} creates new string variables for use in
331 Specify a slash (@samp{/}), followed by the names of the string
332 variables to create and the desired output format specification in
333 parentheses (@pxref{Input/Output Formats}). Variable widths are
334 implicitly derived from the specified output formats.
336 Created variables are initialized to spaces.
338 @node VARIABLE LABELS, VECTOR, STRING, Variable Attributes
339 @section VARIABLE LABELS
340 @vindex VARIABLE LABELS
344 /var_list 'var_label'.
347 @cmd{VARIABLE LABELS} associates explanatory names
348 with variables. This name, called a @dfn{variable label}, is displayed by
349 statistical procedures.
351 To assign a variable label to a group of variables, specify a slash
352 (@samp{/}), followed by the list of variable names and the variable
355 @node VECTOR, WRITE FORMATS, VARIABLE LABELS, Variable Attributes
360 Two possible syntaxes:
361 VECTOR vec_name=var_list.
362 VECTOR vec_name_list(count).
365 @cmd{VECTOR} allows a group of variables to be accessed as if they
366 were consecutive members of an array with a vector(index) notation.
368 To make a vector out of a set of existing variables, specify a name for
369 the vector followed by an equals sign (@samp{=}) and the variables that
370 belong in the vector.
372 To make a vector and create variables at the same time, specify one or
373 more vector names followed by a count in parentheses. This will cause
374 variables named @code{@var{vec}1} through @code{@var{vec}@var{count}}
375 to be created as numeric variables with print and write format F8.2.
376 Variable names including numeric suffixes may not exceed 8 characters
377 in length, and none of the variables may exist prior to @cmd{VECTOR}.
379 All the variables in a vector must be the same type.
381 Vectors created with @cmd{VECTOR} disappear after any procedure or
382 procedure-like command is executed. The variables contained in the
383 vectors remain, unless they are scratch variables (@pxref{Scratch
386 Variables within a vector may be referenced in expressions using
387 @code{vector(index)} syntax.
389 @node WRITE FORMATS, , VECTOR, Variable Attributes
390 @section WRITE FORMATS
391 @vindex WRITE FORMATS
394 WRITE FORMATS var_list (fmt_spec).
397 @cmd{WRITE FORMATS} sets the write formats for the specified numeric
399 to the specified format specification. Its syntax is identical to
400 that of FORMATS (@pxref{FORMATS}), but @cmd{WRITE FORMATS} sets only
401 write formats, not print formats.