Types of Expressions

This section describes the types of expressions that you can write in Maintain Data:

  • Numeric. Use a numeric expression to perform calculations that use numeric constants (integer or decimal) and 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. Use 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. 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 Writing Date Expressions.
    • Date-time expressions. Use a variety of specialized date-time functions, each of which returns a different kind of value. For details, see Writing Date-Time Expressions.
  • Character. 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 evaluate the relationship between two values. 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 (IF...THEN...ELSE) returns a numeric or character value. For details, see Writing Conditional Expressions.

Usage Notes for Expressions

  • Expressions in Maintain Data 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).