DECODE USERID TO USER NAME(20)(C), CMSAED = 'ANNE D.', CMSCED = 'CRAIG D.', ELSE UNKNOWN USER
In this example a new data field is set up called USER NAME. It is formatted as 20 character bytes and assigns a value to the new field based on the charge code in each input record.
The DECODE statement is a convenient way to specify a number of tests and assignments.
The sample DECODE statement above is equivalent to the following instructions:
DEFINE USER NAME(C)(20) = BLANK COMPUTE IF USERID EQ 'CMSAED' THEN
USER NAME = 'ANNE D.',
IF USERID EQ 'CMSCED' THEN
USER NAME = 'CRAIG D.',
ELSE USER NAME = 'UNKNOWN USER'
Note: When a string used in a DECODE statement includes either a comma or period followed by a space, or a space immediately followed by any special character, then the string must be enclosed in single quotes.
Example:
DECODE USER/INFO (2,1) TO WORK/FIELD(C) (30)
A = 'APPLES & ORANGES',
B = '%BANANAS',
C = CHERRIES, CANTALOUPE, CUCUMBERS,
G = 'GRAPES, GRAPEFRUIT, AND GUAVA',
P = PEARS? PINEAPPLES?,
ELSE NO. FRUIT
CHERRIES, CANTALOUPE, CUCUMBERS, is invalid because of the commas; otherwise, A, B, C, P and ELSE statements are valid.
| Copyright © 2012 CA. All rights reserved. |
|