The user does not have to specify the number of decimals to store in the new variable. If the 'decimals=' keyword is missing, the new variable is stored with as many decimals as necessary.
To run this program in batch mode it is necessary to prepare a command file, which specifies how the new variable is to be created and the options to use. The name of this batch command file is specified to the program after the '-b' option flag. This document explains how to prepare such a file.
The general layout is as follows:
(Algebraic expression)
*
(Input and output specifications)
CATEGORIES= [optional]
(Category text and labels)
*
TEXT= [optional]
(Descriptive text for the new variable)
*
A line with two asterisks (**) on a line by itself can be added,
in order to separate sets of COMPUTE commands in the same batch
file. This is how you include
multiple computes
in the same file.
A complete list of operators and functions that can be used in expressions is given later in this document. A few examples of expressions are given next in this document. However, many more examples can be found in the section on 'expressions' in the online help document.
newvar = var1 + var2 newvar = sqrt(var1) newvar = mean.2(var1,var2,var3) if (var1 eq 1) newvar = var2
The 'ELSE IF' part can be repeated; 'ELSE' can be used only once; both parts are optional.if (var1 eq 1) newvar = var3 else if (var1 eq 2) newvar = var4 else newvar = -1 endif
The words 'IF', 'ELSE IF', 'ELSE', and 'ENDIF' should begin on a new line. Note that they can be either in upper or in lower case. (A space after 'else' is optional: 'elseif' also works.)
If no 'ELSE' part is used, it is possible that some cases will not meet any of the conditions; the new variable will then be set to the specified missing data code for those cases.
Each 'IF', 'ELSE IF' or 'ELSE' part includes every line after it, up to the next 'ELSE IF', 'ELSE' or 'ENDIF' -- not just the rest of its own line. So if a line after an IF / ELSE expression should apply to every case, put 'ENDIF' before it:
Without the 'ENDIF', the last line would be part of the 'ELSE' part, and newvar would be missing for every case where var1 is 5 or less. There is an implied 'ENDIF' at the end of the expression. Only one IF-statement is allowed at the top level; others must be nested inside it, and a nested IF-statement needs its own 'ENDIF' unless nothing follows it.if (var1 le 5) $temp1 = 1 else $temp1 = 2 endif newvar = $temp1 * 10
If a condition cannot be evaluated for a case (because a variable in it has missing data), the new variable is set to missing for that case, and the remaining ELSE IF and ELSE parts are not tried. Use the MISSING() function to handle missing data explicitly. For details, see the online help document.
Each expression using a temporary variable must be on a separate line, before the final line that gives the name of the new variable to be saved. Temporary variables can only be used in assignment statements. They cannot be used in the test portion of an IF-statement. A temporary variable must be given a value before it is used: a line can use a temporary variable only if an earlier line assigns a value to it. Otherwise COMPUTE reports an error and does not create the new variable. Upper and lower case are different in the names of temporary variables: '$Temp1' and '$temp1' are two different variables.
The following is an example of the use of temporary variables.
$temp1 = var1 + var2 $temp2 = var1 * var2 newvar = $temp1 / $temp2
The operators must have a space on each side ('x eq 1', not 'x eq(1)'). The symbols =, <, >, <=, >=, <> and != are not accepted in a condition. AND is applied before OR, so 'a OR b AND c' means 'a OR (b AND c)'; use parentheses to make the order clear. The arguments 'x' or 'y' stand for either an existing SDA variable, a constant, or another expression.
Operator / Meaning / Example
The arguments 'x' or 'y' stand for either an existing SDA
variable, a temporary variable, a constant, or another
expression. Only the range ends in 'COUNT' ('a' and 'b') must be
constants. If an argument has a missing-data value, the result
is a missing-data value, except for the functions listed under
"Summaries of Variables" and "Other Summaries".
For example, 'mean(var1,var2,var3)' will generate the mean of the three variables, even if only one of the three has a valid code. On the other hand 'mean.2(var1,var2,var3)' will generate a mean for a specific case only if at least two of the variables have valid codes.
Keyword Possible Specification Default (if no keyword)
_____________________________________________________________________
STudies= path of source dataset(s) Look for input variables
only in current directory
MISSing= Valid Exclude input missing data,
or out of range values.
(Note that system-missing
or character missing-data
values are never made valid.)
SEED= seed for random numbers Use system clock and
process ID.
(Note: a specified seed
must be a whole number.)
Keyword Possible Specification Default (if no keyword)
_____________________________________________________________________
OUTSTudy= path of study for new variable Current directory
DECimals= number of decimals Indefinite number of
to store (0 to 6) decimal places
CATlabels= (precedes lines of category No category text
labels - see details below) or labels
LABEL= long label for new variable No long label
OVERwrite= Yes or No Do not overwrite new var
if it already exists.
(Note: a variable in an input
study can never be replaced,
only a variable in an output
study.)
TEXT= (precedes lines of descriptive No descriptive text
text -- see details below)
MD= list of invalid codes, ranges No defined MD codes
(also used for output value
if input vars have MD
-- see below)
MIN= minimum valid value No defined minimum
MAX= maximum valid value No defined maximum
Keyword Possible Specification Default (if no keyword)
_____________________________________________________________________
DIAGnostics= yes No diagnostic summary of
the new variable
COLorcoding= yes No colored headings in the
diagnostic output
GVARCase= LOWER or UPPER Do not convert all variable
names to lower/upper case
LAnguagefile= Name of file with non-English English labels on
labels and messages output
SAVebatch= name of directory No file preserved with batch
commands to create new var
(for interactive version)
The batch file name is the
name of the new variable,
with the suffix '.cmp'
catlabels=
0 Lowest value [Low]
5 Medium
10 Highest value [High]
*
Note: multiple computes can only be used when running COMPUTE from the command line. When run interactively in SDAWEB, only one computed variable can be created at a time.
newvar = spend + spend2 * study = /archive/nes96 label=Sum of spend and spend2 catlabels= 2 Lowest 6 Medium 10 Highest *
newvar1 = count(spend, spend2, spend3, spend4 (1) ) * study = /sda/demostudy label=Number of 'spend too much' in spend - spend4 overwrite=yes text = This variable counts the number of times that the code '1' (for govt. spends too much on this) is recorded. * **
newvar2 = mean.2(spend, spend2, spend3) * label=Average of spend, spend2, and spend3 md=9 **
newvar3=normal(0,10) * label=Random numbers with mean 0,sd 10 seed= 12121