Use the COMPUTE command to calculate expressions or perform mathematical operations on columns.
Options
,
Indicates that this part of the command is repeatable.
ALL
Executes all of the functions relevant to the data type of the selected column.
AVG
Computes the numeric average of CURRENCY, DOUBLE, NUMERIC, REAL, INTEGER, DATE, or TIME data types. R:BASE rounds averages of integer values to the nearest integer value and currency values to their nearest unit.
colname
Specifies a 1 to 18 character column name. In a command, you can enter #c, where #c is the column number shown when the columns are listed with the LIST TABLES command. In an SQL command, a column name can be preceded by a table or correlation name and a period (tblname.colname).
COUNT
Determines how many non-null entries there are for a particular column item.
(expression)
Determines the value for the column using a text or arithmetic formula. The expression can include other columns from the table, constant values, functions, or system variables such as #date, #time, and #pi.
FROM tblview
Specifies the table or view.
MAXIMUM
Selects the maximum value in a column. For TEXT and CHARACTER data types, R:BASE evaluates the first 30 characters. This option accepts columns with any data type except BIT, VARBIT, VARCHAR, and BITNOTE.
MINIMUM
Selects the minimum value in a column. For TEXT and CHARACTER data types, R:BASE evaluates the first 30 characters. This option accepts columns with any data type except BIT, VARBIT, VARCHAR, and BITNOTE.
ROWS FROM tblname
Counts rows in a specified table.
STDEV
Computes standard deviation for CURRENCY, DOUBLE, REAL, NUMERIC, or INTEGER data types.
SUM
Computes the numeric sum of CURRENCY, DOUBLE, REAL, NUMERIC, or INTEGER data types.
VARIANCE
Determines variance for CURRENCY, DECIMAL, DOUBLE, FLOAT, REAL, NUMERIC, INTEGER, or SMALLINT data types.
varname AS
Specifies a global variable name in which to store the result of a COMPUTE command. If you use the arguments COUNT or ROWS, the variable must be an INTEGER data type.
WHERE clause
Limits rows of data. For more information, see the "WHERE" entry.
About the COMPUTE Command
R:BASE does not consider null values when it calculates averages, minimums, maximums, counts, sums, standard deviation, and variance.
The COMPUTE command can define a global variable with the data type that matches the results of the computation of a column's values.
You can also choose Calculate on the Data Browser menu in R:BASE for Windows to choose a column, then perform the mathematical operations that apply to the data type of the column.
In general we do recommend using the SELECT Function(Column) notation over the COMPUTE notation as this provides greater compliance to the SQL standard and greater portability to new versions of R:BASE.
Examples
The following command computes, then stores the minimum on-hand quantity in the vminvar variable found in the prodlocationtable.
COMPUTE vminvar AS MINIMUM onhand FROM prodlocation
The following command computes the total number of rows in the transmaster table and places the result in the vrowcountervariable.
COMPUTE vrowcounter AS ROWS FROM transmaster
The following command computes the average of an INTEGER data type (onhand) and returns the result as a DOUBLE data type.
COMPUTE AVG (onhand * 1.0) FROM prodlocation
The following command calculates your multiple computations on different columns. The command counts the number of entries in the custid column and averages the entries in the netamount column. The custid column and the netamount column are both from the transmaster table; all the specified columns must be in the same table or view.
COMPUTE COUNT custid, AVG netamount FROM transmaster
The command below shows you how to use variables to hold the results of computations.
COMPUTE v1 AS COUNT custid,v2 AS AVG netamount FROM transmaster