In this section: |
A character expression uses alphanumeric constants, fields, concatenation operators, IF-THEN-ELSE logic, or functions to derive an alphanumeric value.
Both text and alphanumeric fields can be assigned values stored in text fields or alphanumeric expressions in TABLE COMPUTE, MODIFY COMPUTE, and DEFINE commands. If an alphanumeric field is assigned the value of a text field that is too long for the alphanumeric field, the value is truncated before being assigned to the alphanumeric field.
A character expression can consist of:
COMPUTE STATE/A2 = 'NY';
DEFINE FILE EMPLOYEE TITLE/A19 = 'DR. ' | LAST_NAME; END
DEFINE FILE EMPLOYEE INITIAL/A1 = EDIT(FIRST_NAME, '9$$$$$$$$$$'); END
Note:
Under certain conditions, you can use quote-delimited strings containing embedded quotation marks. Within the string, you can use either one single quotation mark or two contiguous single quotation marks to represent the single quotation mark. Both are interpreted as a single quotation mark.
You can use quote-delimited strings in the following instances:
The following example illustrates the use of quotation marks for the correct interpretation of the data value O'BRIEN:
TABLE FILE VIDEOTRK PRINT LASTNAME WHERE LASTNAME IS 'O'BRIEN' END
You can write an expression that concatenates two or more alphanumeric constants and/or fields into a single character string. This concatenation operator has two forms, as shown in the following table:
Symbol |
Represents |
Description |
---|---|---|
| |
Weak concatenation |
Preserves trailing blanks. |
|| |
Strong concatenation |
Moves trailing blanks to the end of a concatenated string. |
The following example uses the EDIT function to extract the first initial from a first name. It then uses both strong and weak concatenation to produce the last name, followed by a comma, followed by the first initial, followed by a period:
DEFINE FILE EMPLOYEE FIRST_INIT/A1 = EDIT(FIRST_NAME, '9$$$$$$$$$'); NAME/A19 = LAST_NAME ||(', '| FIRST_INIT |'.'); END
TABLE FILE EMPLOYEE PRINT NAME WHERE LAST_NAME IS 'BANNING' END
The output is:
NAME ---- BANNING, J.
The request evaluates the expressions as follows:
, J.
Banning, J.
While LAST_NAME has the format A15 in the EMPLOYEE Master File, strong concatenation suppresses the trailing blanks. Regardless of the suppression or inclusion of blanks, the resulting field name, NAME, has a length of 19 characters (A19).
The following request uses IF-THEN-ELSE logic to determine what characters to concatenate to MOVIECODE in order to compute NEWCODE.
TABLE FILE MOVIES PRINT COPIES MOVIECODE COMPUTE NEWCODE/A20 = MOVIECODE |(IF MOVIECODE CONTAINS 'DIS' THEN 'NEY;' ELSE ';'); BY CATEGORY WHERE CATEGORY EQ 'CHILDREN' ON TABLE SET PAGE NOLEAD ON TABLE SET STYLE * GRID=OFF,$ ENDSTYLE END
The output is shown in the following image. If MOVIECODE contains the characters 'DIS', NEWCODE is generated by concatenating the characters 'NEY;', otherwise NEWCODE is generated by concatenating the character ';'.