4.8 Account Code Determination Routine Coding


Account code determination routines identify cost centers.
Typical routines contain table lookup operations, such as the
following:

  If the jobname is      then the department is
  -----------------      ----------------------
         ACPxxxxx          Accounts Payable
         ACRxxxxx          Accounts Receivable
         ACTxxxxx          Actuarial
         PAYxxxxx          Payroll
         SYSxxxxx          Systems Support

  A sample implementation might be:

     IF JOB = :'ACP' THEN ACCTNO1 = 'ACCOUNTS PAYABLE';
     IF JOB = :'ACR' THEN ACCTNO1 = 'ACCOUNTS RCVBL';
     IF JOB = :'ACT' THEN ACCTNO1 = 'ACTUARIAL';
     IF JOB = :'PAY' THEN ACCTNO1 = 'PAYROLL';
     IF JOB = :'SYS' THEN ACCTNO1 = 'SYSTEMS SUPPORT';

This code structure may execute faster if ELSE statements are
used, as in the following example:

    IF JOB = :'ACP' THEN ACCTNO1 = 'ACCOUNTS PAYABLE';
--> ELSE IF JOB = :'ACR' THEN ACCTNO1 = 'ACCOUNTS RCVBL';
--> ELSE IF JOB = :'ACT' THEN ACCTNO1 = 'ACTUARIAL';
--> ELSE IF JOB = :'PAY' THEN ACCTNO1 = 'PAYROLL';
--> ELSE IF JOB = :'SYS' THEN ACCTNO1 = 'SYSTEMS SUPPORT';

IF statements after the statement that satisfies the
condition are not executed, which results in faster
execution.  That is, if the job name is ACRCFM01, the first
and second statements would be executed, but the third
through the fifth would not.  Such a structure of IF ...
ELSE IF ...  is commonly called an IF cascade.

An alternative construction uses a SELECT statement instead
of an IF cascade.  The normal use of SELECT is

   SELECT(select-expression);
    WHEN (when-expression) ... ;
    .
    .
    .
    OTHERWISE  ... ;
   END;

The advantage of the SELECT statement is that the
select-expression is evaluated once and is compared
sequentially against each when-expression until a match
occurs.  If no match occurs, the OTHERWISE statement is
executed.

In the first example, the IF cascade is comparing against the
first three characters of the job name using the special
colon modifier (=:) in the IF statement.  Since the special
colon modifier is not applicable to the SELECT statement, you
must code a SUBSTR function as illustrated in the following
example:

   SELECT(SUBSTR(JOB,1,3));
    WHEN('ACP') ACCTNO1 = 'ACCOUNTS PAYABLE';
    WHEN('ACR') ACCTNO1 = 'ACCOUNTS RCVBL ';
    WHEN('ACT') ACCTNO1 = 'ACTUARIAL    ';
    WHEN('PAY') ACCTNO1 = 'PAYROLL     ';
    WHEN('SYS') ACCTNO1 = 'SYSTEMS SUPPORT ';
    OTHERWISE ... ;
   END;

Also consider the volume of input data when designing your
code.  Assume that the following relationship exists between
jobnames and volume:

   If the jobname is   then the number of jobs per day is
   -----------------   ----------------------------------
     ACPxxxxx          1000
     ACRxxxxx          4500
     ACTxxxxx           100
     PAYxxxxx           400
     SYSxxxxx          2000

This volume distribution would mean the IF cascade would
operate even more efficiently if the conditional with the
largest number of hits were highest in the cascade.

Given our example, the IF cascade should be reordered as
follows:

   IF JOB = :'ACR' THEN ACCTNO1 = 'ACCOUNTS RCVBL';
   ELSE IF JOB = :'SYS' THEN ACCTNO1 = 'SYSTEMS SUPPORT';
   ELSE IF JOB = :'ACP' THEN ACCTNO1 = 'ACCOUNTS PAYABLE';
   ELSE IF JOB = :'PAY' THEN ACCTNO1 = 'PAYROLL';
   ELSE IF JOB = :'ACT' THEN ACCTNO1 = 'ACTUARIAL';

and the SELECT statements should be reordered as follows:

   SELECT(SUBSTR(JOB,1,3));
     WHEN('ACR') ACCTNO1 = 'ACCOUNTS RCVBL ';
     WHEN('SYS') ACCTNO1 = 'SYSTEMS SUPPORT ';
     WHEN('ACP') ACCTNO1 = 'ACCOUNTS PAYABLE';
     WHEN('PAY') ACCTNO1 = 'PAYROLL     ';
     WHEN('ACT') ACCTNO1 = 'ACTUARIAL    ';
     OTHERWISE ... ;
   END;

Another option for coding table lookup operations is to write
a user-defined SAS Format.  The advantages of using Formats
for Account Code Determination routines over other techniques
are:

   o Can reduce DATA step compile time by replacing lengthy
     inline IF/THEN/ELSE or SELECT/WHEN logic

   o Consistent response time for lookup operations, since
     Formats are constructed as a highly optimized binary
     tree

   o Account code data is separated from the code itself,
     affording easier maintenance

PROC FORMAT structure differs significantly from an IF
cascade.  PROC FORMAT causes a table to be built when the
PROC FORMAT is executed.  The table is inspected through a
SAS PUT function, similar to the PL/I ENCODE operation.  The
Format might be structured as follows:

   PROC FORMAT;
    VALUE $USRACTF
    'ACP' = 'ACCOUNTS PAYABLE'
    'PAY' = 'PAYROLL'
    'ACR' = 'ACCOUNTS RCVBL'
    'SYS' = 'SYSTEMS SUPPORT'
    'ACT' = 'ACTUARIAL'
    OTHER = 'OVERHEAD' ;

This causes the table to be built.  The Format may be built
at any time--periodically (such as every time the source
table changes) or each day in the course of the daily run.
Table lookup operations are done when the PUT function is
called.  A sample account code derivation routine that
illustrates the use of a table lookup using PUT follows.

  ACCTNO1 = PUT( SUBSTR(JOB,1,3),$USRACTF.);

The PROC FORMAT examples illustrate how to create and use a
temporary user-defined Format.  Section 4.5 of this guide
provides instructions on creating permanent user-defined
Formats.

Remember to always benchmark one coding method against
another, choosing the method that offers the best performance
for your CA MICS system.