SSN indexing
Posted in 1994
Based on the recent post suggesting SSN as an index, I thought of the following method to turn a known-format character string into an integer key to make it faster. It's also a reason to use MOD which somebody (not here) recently claimed was a useless appendage to any data processing language: MAIN DEFINE ssn CHAR(11), i_ssn INTEGER, c_ssn CHAR(11) PROMPT "Enter ssn " for ssn LET i_ssn=char_to_int(ssn) LET c_ssn=int_to_char(i_ssn) DISPLAY "Integer : ", i_ssn DISPLAY "Character : ", c_ssn END MAIN FUNCTION int_to_char(i_ssn) DEFINE i_ssn INTEGER, int1 INTEGER, c_ssn CHAR(11) # I go to integer here first - otherwise it gets rounded. # it could have been built as one long string, which MIGHT have saved a # micro second or two, but I try to make clarity my watchword. LET int1 = i_ssn / 1000000 # XXX________ LET c_ssn[1,3] = int1 LET int1 = (i_ssn/10000) MOD 100 # XXX_XX_____ LET c_ssn[5,6] = int1 LET int1 = i_ssn MOD 10000 # XXX_XX_XXXX LET c_ssn[8,11] = int1 LET c_ssn[4,4]="-" # XXX-XX_XXXX LET c_ssn[7,7]="-" # XXX-XX-XXXX RETURN c_ssn END FUNCTION FUNCTION char_to_int(c_ssn) DEFINE i_ssn INTEGER, c_ssn CHAR(11) # I haven't checked RETURN c_ssn might work just as well. LET c_ssn=c_ssn[1,3], c_ssn[5,6], c_ssn[8,11] # lose the "-" LET i_ssn = c_ssn RETURN i_ssn END FUNCTION cheers j. _____________________________________________________________________________ Jack Parker | Hewlett Packard, BSMC Boise, Idaho, USA| He who talks most, talks least. jparker@hpbs3645.boi.hp.com | _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________