An expression can be one of
numeric expressions to perform calculations that use numeric constants
(integer or decimal) and fields. For example, you can write an expression
to compute the bonus for each employee by multiplying the current
salary by the desired percentage as follows:
COMPUTE BONUS/D12.2 = CURR_SAL * 0.05 ;
numeric expression returns a numeric value. For details, see Creating a Numeric Expression.
date expressions to perform numeric calculations on dates. For example,
you can write an expression to determine when a customer can expect
to receive an order by adding the number of days in transit to the
date on which you shipped the order as follows:
COMPUTE DELIVERY/MDY = SHIPDATE + 5 ;
There are two types of date expressions:
- Date expressions,
which return a date, a component of a date, or an integer that represents
the number of days, months, quarters, or years between two dates.
For details, see Creating a Date Expression.
- Date-time expressions,
which you can create using a variety of specialized date-time functions,
each of which returns a different kind of value. For details on these
functions, see the Using Functions manual.
character expressions to manipulate alphanumeric constants or fields.
For example, you can write an expression to extract the first initial from
an alphanumeric field as follows:
COMPUTE FIRST_INIT/A1 = EDIT (FIRST_NAME, '9$$$$$$$$$') ;
character expression returns an alphanumeric value. For details,
see Creating a Character Expression.
fields can be assigned to alphanumeric fields and receive assignment
from alphanumeric fields. Text fields can also participate in expressions using
the operators CONTAINS and OMITS.
logical expressions to evaluate the relationship between two values.
A logical expression returns TRUE or FALSE. For details, see Creating a Logical Expression.
conditional expressions to assign values based on the result of
logical expressions. A conditional expression (IF ... THEN ... ELSE)
returns a numeric or alphanumeric value. For details, see Creating a Conditional Expression.
Expressions and Field Formats
When you use an expression to assign a value to a field,
make sure that you give the field a format that is consistent with
the value returned by the expression. For example, if you use a
character expression to concatenate a first name and last name and assign
it to the field FULL_NAME, make sure you define the field as character.
Example: Assigning a Field Format of Sufficient Length
The following example contains a character
expression that concatenates a first name and last name to derive
the full name. It assigns the field FULL_NAME an alphanumeric format
of sufficient length to accommodate the concatenated name:
DEFINE FILE EMPLOYEE
FULL_NAME/A25 = FIRST_NAME | LAST_NAME;
TABLE FILE EMPLOYEE
WHERE LAST_NAME IS 'BLACKWOOD'
The output is: