In this section: How to: |
You can call a function in WHERE or IF criteria. When you do this, the output value of the function is compared against a test value.
WHERE function relation expression
where:
Is a function.
Is an operator that determines the relationship between the function and expression, for example, EQ or LE.
Is a constant, field, or function. A literal must be enclosed in single quotation marks.
IF function relation value
where:
Is a function.
Is an operator that determines the relationship between the function and expression, for example, EQ or LE.
Is a constant. In a DEFINE or COMPUTE command, the value must be enclosed in single quotation marks.
The SUBSTR function extracts the first two characters of LAST_NAME as a substring, and the request prints an employee's name and salary if the substring is MC.
TABLE FILE EMPLOYEE PRINT FIRST_NAME LAST_NAME CURR_SAL WHERE SUBSTR(15, LAST_NAME, 1, 2, 2, 'A2') IS 'MC'; END
The output is:
FIRST_NAME LAST_NAME CURR_SAL ---------- --------- -------- JOHN MCCOY $18,480.00 ROGER MCKNIGHT $16,100.00
You must specify the format of the output value in a calculation or compound IF command. There are two ways to do this:
COMPUTE AMOUNT/D8.2 =; AMOUNT_FLAG/A5 = IF function(input1, input2, AMOUNT) GE 500 THEN 'LARGE' ELSE 'SMALL';
DEFINE AMOUNT_FLAG/A5 = IF function(input1, input2, 'D8.2') GE 500 THEN 'LARGE' ELSE 'SMALL';
Information Builders |