Deriving Category from the Student Database(SDB)

The person registry system is fed up to 3 separate records from the SDB for each person. These records can be thought of as a student record, a UW extension student record and an UW applicant record. Each of these records contain the following data elements.
    Name:            Description:                                Person Registry Field Name:
    studnum          Student Number                              sn
    ssn              Social Security Number                      ssn
    birthdate        Birth Date                                  birthdate
    pac              Private Access Code                         pac
    name             Full name of person                         lastname, firstname 
    class            Class (freshman, sophmore, etc).            sdb_class
    branch           Campus (bothell, main, tacoma)              branch
    college          College Code                                college
    department       Department Code                             department
    status           Status Code                                 sdb_status
    techfee          If the indvidual paid the student techfee   techfee
From the first record encountered for a person all of the fields except "status" and "techfee" are grabbed and updated in the personreg system. No data massaging happens except that the first name and last name are derived from the name field. Each record found for a person is ranked by "status" code as follows:
   Status:      Rank:
   E            1
   P            2
   L            3 
   A            4
   O            5
   N            6
   X            7
   [default]    8
The record with the lowest number is then used to determine the category based on the following algorithm.
 if status equals O then 
     if techfee equals Y then
         category is 18
     else 
         category is 19
 else if status equals N then
     category is 20 
 else if class greater than 0 and class less than 7 then
     category is 1
 else  
     category is 2