Method for determining transposition when comparing two numeric values (more information)

Merol Newman merol.newman@ramesys.com
Mon, 20 Nov 2000 21:43:49 -0000


Hello George

I hope this will get you a bit nearer your goal - this is how to compare the
counts of each digit. I must admit the feasibility of this method depends mainly
on what sort of editor is available - you probably thought of it yourself, but
couldn't face typing it in!

This is quiz code for testing the defined items - I think you said you were
doing this bit in quiz anyway. I did the whole lot (ssn2 as well as ssn1) just
in case you have a useless editor, so you can just cut-and-paste and substitute
the item names (ssn1 and ssn2), if it's any use to you. I had fun, anyway!

def ssn1 cha*9 = parm
def ssn2 cha*9 = parm

def a0 num*2 = index("0",ssn1[1:1])
def b0 num*2 = index("0",ssn1[2:1])
def c0 num*2 = index("0",ssn1[3:1])
def d0 num*2 = index("0",ssn1[4:1])
def e0 num*2 = index("0",ssn1[5:1])
def f0 num*2 = index("0",ssn1[6:1])
def g0 num*2 = index("0",ssn1[7:1])
def h0 num*2 = index("0",ssn1[8:1])
def i0 num*2 = index("0",ssn1[9:1])

def a1 num*2 = index("1",ssn1[1:1])
def b1 num*2 = index("1",ssn1[2:1])
def c1 num*2 = index("1",ssn1[3:1])
def d1 num*2 = index("1",ssn1[4:1])
def e1 num*2 = index("1",ssn1[5:1])
def f1 num*2 = index("1",ssn1[6:1])
def g1 num*2 = index("1",ssn1[7:1])
def h1 num*2 = index("1",ssn1[8:1])
def i1 num*2 = index("1",ssn1[9:1])

def a2 num*2 = index("2",ssn1[1:1])
def b2 num*2 = index("2",ssn1[2:1])
def c2 num*2 = index("2",ssn1[3:1])
def d2 num*2 = index("2",ssn1[4:1])
def e2 num*2 = index("2",ssn1[5:1])
def f2 num*2 = index("2",ssn1[6:1])
def g2 num*2 = index("2",ssn1[7:1])
def h2 num*2 = index("2",ssn1[8:1])
def i2 num*2 = index("2",ssn1[9:1])

def a3 num*2 = index("3",ssn1[1:1])
def b3 num*2 = index("3",ssn1[2:1])
def c3 num*2 = index("3",ssn1[3:1])
def d3 num*2 = index("3",ssn1[4:1])
def e3 num*2 = index("3",ssn1[5:1])
def f3 num*2 = index("3",ssn1[6:1])
def g3 num*2 = index("3",ssn1[7:1])
def h3 num*2 = index("3",ssn1[8:1])
def i3 num*2 = index("3",ssn1[9:1])

def a4 num*2 = index("4",ssn1[1:1])
def b4 num*2 = index("4",ssn1[2:1])
def c4 num*2 = index("4",ssn1[3:1])
def d4 num*2 = index("4",ssn1[4:1])
def e4 num*2 = index("4",ssn1[5:1])
def f4 num*2 = index("4",ssn1[6:1])
def g4 num*2 = index("4",ssn1[7:1])
def h4 num*2 = index("4",ssn1[8:1])
def i4 num*2 = index("4",ssn1[9:1])

def a5 num*2 = index("5",ssn1[1:1])
def b5 num*2 = index("5",ssn1[2:1])
def c5 num*2 = index("5",ssn1[3:1])
def d5 num*2 = index("5",ssn1[4:1])
def e5 num*2 = index("5",ssn1[5:1])
def f5 num*2 = index("5",ssn1[6:1])
def g5 num*2 = index("5",ssn1[7:1])
def h5 num*2 = index("5",ssn1[8:1])
def i5 num*2 = index("5",ssn1[9:1])

def a6 num*2 = index("6",ssn1[1:1])
def b6 num*2 = index("6",ssn1[2:1])
def c6 num*2 = index("6",ssn1[3:1])
def d6 num*2 = index("6",ssn1[4:1])
def e6 num*2 = index("6",ssn1[5:1])
def f6 num*2 = index("6",ssn1[6:1])
def g6 num*2 = index("6",ssn1[7:1])
def h6 num*2 = index("6",ssn1[8:1])
def i6 num*2 = index("6",ssn1[9:1])

def a7 num*2 = index("7",ssn1[1:1])
def b7 num*2 = index("7",ssn1[2:1])
def c7 num*2 = index("7",ssn1[3:1])
def d7 num*2 = index("7",ssn1[4:1])
def e7 num*2 = index("7",ssn1[5:1])
def f7 num*2 = index("7",ssn1[6:1])
def g7 num*2 = index("7",ssn1[7:1])
def h7 num*2 = index("7",ssn1[8:1])
def i7 num*2 = index("7",ssn1[9:1])

def a8 num*2 = index("8",ssn1[1:1])
def b8 num*2 = index("8",ssn1[2:1])
def c8 num*2 = index("8",ssn1[3:1])
def d8 num*2 = index("8",ssn1[4:1])
def e8 num*2 = index("8",ssn1[5:1])
def f8 num*2 = index("8",ssn1[6:1])
def g8 num*2 = index("8",ssn1[7:1])
def h8 num*2 = index("8",ssn1[8:1])
def i8 num*2 = index("8",ssn1[9:1])

def a9 num*2 = index("9",ssn1[1:1])
def b9 num*2 = index("9",ssn1[2:1])
def c9 num*2 = index("9",ssn1[3:1])
def d9 num*2 = index("9",ssn1[4:1])
def e9 num*2 = index("9",ssn1[5:1])
def f9 num*2 = index("9",ssn1[6:1])
def g9 num*2 = index("9",ssn1[7:1])
def h9 num*2 = index("9",ssn1[8:1])
def i9 num*2 = index("9",ssn1[9:1])

def x0 num*2 = a0 + b0 + c0 + d0 + e0 + f0 + g0 + h0 + i0  ;no of 0s in SSN
def x1 num*2 = a1 + b1 + c1 + d1 + e1 + f1 + g1 + h1 + i1  ;no of 1s in SSN
def x2 num*2 = a2 + b2 + c2 + d2 + e2 + f2 + g2 + h2 + i2  ;etc
def x3 num*2 = a3 + b3 + c3 + d3 + e3 + f3 + g3 + h3 + i3
def x4 num*2 = a4 + b4 + c4 + d4 + e4 + f4 + g4 + h4 + i4
def x5 num*2 = a5 + b5 + c5 + d5 + e5 + f5 + g5 + h5 + i5
def x6 num*2 = a6 + b6 + c6 + d6 + e6 + f6 + g6 + h6 + i6
def x7 num*2 = a7 + b7 + c7 + d7 + e7 + f7 + g7 + h7 + i7
def x8 num*2 = a8 + b8 + c8 + d8 + e8 + f8 + g8 + h8 + i8
def x9 num*2 = a9 + b9 + c9 + d9 + e9 + f9 + g9 + h9 + i9

;;Repeat the above to get y0 to y9 for ssn2.

def j0 num*2 = index("0",ssn2[1:1])
def k0 num*2 = index("0",ssn2[2:1])
def l0 num*2 = index("0",ssn2[3:1])
def m0 num*2 = index("0",ssn2[4:1])
def n0 num*2 = index("0",ssn2[5:1])
def o0 num*2 = index("0",ssn2[6:1])
def p0 num*2 = index("0",ssn2[7:1])
def q0 num*2 = index("0",ssn2[8:1])
def r0 num*2 = index("0",ssn2[9:1])

def j1 num*2 = index("1",ssn2[1:1])
def k1 num*2 = index("1",ssn2[2:1])
def l1 num*2 = index("1",ssn2[3:1])
def m1 num*2 = index("1",ssn2[4:1])
def n1 num*2 = index("1",ssn2[5:1])
def o1 num*2 = index("1",ssn2[6:1])
def p1 num*2 = index("1",ssn2[7:1])
def q1 num*2 = index("1",ssn2[8:1])
def r1 num*2 = index("1",ssn2[9:1])

def j2 num*2 = index("2",ssn2[1:1])
def k2 num*2 = index("2",ssn2[2:1])
def l2 num*2 = index("2",ssn2[3:1])
def m2 num*2 = index("2",ssn2[4:1])
def n2 num*2 = index("2",ssn2[5:1])
def o2 num*2 = index("2",ssn2[6:1])
def p2 num*2 = index("2",ssn2[7:1])
def q2 num*2 = index("2",ssn2[8:1])
def r2 num*2 = index("2",ssn2[9:1])

def j3 num*2 = index("3",ssn2[1:1])
def k3 num*2 = index("3",ssn2[2:1])
def l3 num*2 = index("3",ssn2[3:1])
def m3 num*2 = index("3",ssn2[4:1])
def n3 num*2 = index("3",ssn2[5:1])
def o3 num*2 = index("3",ssn2[6:1])
def p3 num*2 = index("3",ssn2[7:1])
def q3 num*2 = index("3",ssn2[8:1])
def r3 num*2 = index("3",ssn2[9:1])

def j4 num*2 = index("4",ssn2[1:1])
def k4 num*2 = index("4",ssn2[2:1])
def l4 num*2 = index("4",ssn2[3:1])
def m4 num*2 = index("4",ssn2[4:1])
def n4 num*2 = index("4",ssn2[5:1])
def o4 num*2 = index("4",ssn2[6:1])
def p4 num*2 = index("4",ssn2[7:1])
def q4 num*2 = index("4",ssn2[8:1])
def r4 num*2 = index("4",ssn2[9:1])

def j5 num*2 = index("5",ssn2[1:1])
def k5 num*2 = index("5",ssn2[2:1])
def l5 num*2 = index("5",ssn2[3:1])
def m5 num*2 = index("5",ssn2[4:1])
def n5 num*2 = index("5",ssn2[5:1])
def o5 num*2 = index("5",ssn2[6:1])
def p5 num*2 = index("5",ssn2[7:1])
def q5 num*2 = index("5",ssn2[8:1])
def r5 num*2 = index("5",ssn2[9:1])

def j6 num*2 = index("6",ssn2[1:1])
def k6 num*2 = index("6",ssn2[2:1])
def l6 num*2 = index("6",ssn2[3:1])
def m6 num*2 = index("6",ssn2[4:1])
def n6 num*2 = index("6",ssn2[5:1])
def o6 num*2 = index("6",ssn2[6:1])
def p6 num*2 = index("6",ssn2[7:1])
def q6 num*2 = index("6",ssn2[8:1])
def r6 num*2 = index("6",ssn2[9:1])

def j7 num*2 = index("7",ssn2[1:1])
def k7 num*2 = index("7",ssn2[2:1])
def l7 num*2 = index("7",ssn2[3:1])
def m7 num*2 = index("7",ssn2[4:1])
def n7 num*2 = index("7",ssn2[5:1])
def o7 num*2 = index("7",ssn2[6:1])
def p7 num*2 = index("7",ssn2[7:1])
def q7 num*2 = index("7",ssn2[8:1])
def r7 num*2 = index("7",ssn2[9:1])

def j8 num*2 = index("8",ssn2[1:1])
def k8 num*2 = index("8",ssn2[2:1])
def l8 num*2 = index("8",ssn2[3:1])
def m8 num*2 = index("8",ssn2[4:1])
def n8 num*2 = index("8",ssn2[5:1])
def o8 num*2 = index("8",ssn2[6:1])
def p8 num*2 = index("8",ssn2[7:1])
def q8 num*2 = index("8",ssn2[8:1])
def r8 num*2 = index("8",ssn2[9:1])

def j9 num*2 = index("9",ssn2[1:1])
def k9 num*2 = index("9",ssn2[2:1])
def l9 num*2 = index("9",ssn2[3:1])
def m9 num*2 = index("9",ssn2[4:1])
def n9 num*2 = index("9",ssn2[5:1])
def o9 num*2 = index("9",ssn2[6:1])
def p9 num*2 = index("9",ssn2[7:1])
def q9 num*2 = index("9",ssn2[8:1])
def r9 num*2 = index("9",ssn2[9:1])

def y0 num*2 = j0 + k0 + l0 + m0 + n0 + o0 + p0 + q0 + r0  ;no of 0s in SSN
def y1 num*2 = j1 + k1 + l1 + m1 + n1 + o1 + p1 + q1 + r1  ;no of 1s in SSN
def y2 num*2 = j2 + k2 + l2 + m2 + n2 + o2 + p2 + q2 + r2  ;etc
def y3 num*2 = j3 + k3 + l3 + m3 + n3 + o3 + p3 + q3 + r3
def y4 num*2 = j4 + k4 + l4 + m4 + n4 + o4 + p4 + q4 + r4
def y5 num*2 = j5 + k5 + l5 + m5 + n5 + o5 + p5 + q5 + r5
def y6 num*2 = j6 + k6 + l6 + m6 + n6 + o6 + p6 + q6 + r6
def y7 num*2 = j7 + k7 + l7 + m7 + n7 + o7 + p7 + q7 + r7
def y8 num*2 = j8 + k8 + l8 + m8 + n8 + o8 + p8 + q8 + r8
def y9 num*2 = j9 + k9 + l9 + m9 + n9 + o9 + p9 + q9 + r9

def xx cha*10 = asc(x0,1) + asc(x1,1) + asc(x2,1) + asc(x3,1) + asc(x4,1) &
  + asc(x5,1) + asc(x6,1) + asc(x7,1) + asc(x8,1) + asc(x9,1)

def yy cha*10 = asc(y0,1) + asc(y1,1) + asc(y2,1) + asc(y3,1) + asc(y4,1) &
  + asc(y5,1) + asc(y6,1) + asc(y7,1) + asc(y8,1) + asc(y9,1)

select if xx = yy       ;plus whatever else you want

Note that this doesn't take any account of the positions of the transposed
digits, but simply compares the counts. But together with the clever maths
(dividing by 9), it would get you nearer to what you want, maybe near enough
for practical purposes.

Here are some test results:-

> rep ssn1 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9

SSN1: 995567182

  ST          X0   X1   X2   X3   X4   X5   X6   X7   X8   X9

  995567182    0    1    1    0    0    2    1    1    1    2

> rep ssn1 xx

  SSN1       XX

  995567182  0110021112

995576182

  995576182  0110021112

955967182

  955967182  0110021112

> rep xx yy

SSN1: 995567182

SSN2: 955967182

  XX          YY

  0110021112  0110021112

regards
Merol

email  merol.newman@ramesys.com
Ramesys (Professional Services) Limited
Eldon Way, Crick, Northamptonshire, UK. NN6 7SL
phone  01788 822133/823831 fax  01788 823601


> -----Original Message-----
> From: owner-powerh-l@sphere.swau.edu
> [mailto:owner-powerh-l@sphere.swau.edu]On Behalf Of
> George_DeWolf@midhosp.org
> Sent: 20 November 2000 14:47
> To: powerh-l@sphere.swau.edu
> Cc: Ricky_Pitterman@midhosp.org
> Subject: Method for determining transposition when comparing two numeric
> values (more information)
>
>
> Thanks for the responses thus far.  Here is some more information on my
> problem.   I am writing a Quick screen which reads an indexed file (KSAM).
> The key I am reading by contains the SOUNDEX of the patient's last name (the
> screen is for a hospital).  I wish to select those records that have the
> same SOUNDEX of the last name and have similar (but not necessarily equal)
> social security numbers (9 digit number for those of you outside USA).   I
> am assuming with my "lookup" screen that the social security number (SSN)
> may have originally been entered incorrectly or has been entered incorrectly
> on my lookup screen, so I want to select those records that have SSNs
> similar to the ones entered on the lookup screen.  I am selecting those
> records that have five or more of the nine digits matching in the same
> position; that is when the entered value is "072351232", I would select
> "074341244".  I am sorting the records found by how closely they match the
> entered value and presenting to the user those that match the closest first.
> I have been able to successfully do this by passing the selection value to a
> QUIZ process from the Quick screen, comparing each digit in the entered SSN
> to the ones on file and sorting them by the number of SSN digits which
> match.  I need a way though to determine if  transposition has occurred.  If
> it has and the entered value is "072351232", I would like to report
> "072531232" (4th and 5th digits transposed) before "072661232" (4th and 5th
> digits different).
>
> As some of you have pointed out when one value is subtracted from another
> and the result is evenly divisible by 9 (no remainder) this may indicate
> transposition.  But not all differences evenly divisible by 9 indicate
> transposition.  I've thought if there is a way of counting the number of
> ones, twos, threes etc. in the two values I am trying to compare and
> determining if each value has the same number of ones, twos, threes etc.,
> and then using this along with the evenly-divisible-by-nine technique, that
> this would be a reliable indicator of transposition.  Just don't know of a
> way to get Quiz to count the number of ones, two, threes in each value.  Any
> one have any ideas on how to deal with this?
> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
> Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
> Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
> This list is closed, thus to post to the list, you must be a subscriber.
>

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.