Types of Expressions That You Can Write
This section describes the types of expressions that you can write in Maintain:
Numeric. Use a numeric expression to perform a calculation on numeric constants or variables. 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 = Curr_Sal * 0.05 ;
A numeric expression returns a numeric value. For details, see Writing Numeric Expressions.
Date and time. Use a date and time expression to perform a calculation that involves dates and/or times. 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 and time expressions:
Use a character expression to manipulate alphanumeric or text constants or variables. For example, you can write an expression to extract the first initial from an alphanumeric field as follows:
COMPUTE First_Init/A1 = MASK (First_Name, '9$$$$$$$$$') ;
A character expression returns a character value. For details, see Writing Character Expressions.
Logical. Use a logical expression to determine whether a particular relationship between two values is true. A logical expression returns TRUE or FALSE. For details, see Writing Logical Expressions.
Conditional. Use a conditional expression to assign a value based on the result of a logical expression. A conditional expression returns a numeric or character value. For details, see Writing Conditional Expressions.
Reference: Usage Notes for Expressions
- Expressions in Maintain cannot exceed 40 lines of text or use more than 16 IF statements.
- Expressions are self-terminating. You do not use a semicolon to indicate the end of an expression. Semicolons are used only to terminate commands.
Expressions and Variable Formats
When you use an expression to assign a value to a variable, make sure that you give the variable 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 variable FullName, make sure you define the variable as character (that is, as alphanumeric or text).