[EpiData-list] New user trying to implement a check algorithm

epidata-list at lists.umanitoba.ca epidata-list at lists.umanitoba.ca
Fri Apr 11 10:47:21 CDT 2008


Hi all,

I'm a new user of EpiData. At the moment, I'm making a data entry
system for a medical questionnaire.
In this questionnaire, a 12 digit personal identification number
should be entered. The first 8 digits of this number is the birthday,
the following 3 digits carry some obscure meaning (gender being one of
them), and the last digit is a control number calculated from the
previous 11 digits by the luhn algorithm
(http://en.wikipedia.org/wiki/Luhn_algorithm).

I've been trying to implement this algorithm in EpiData (see below),
but when I try to use this check file, EipData doesn't like it,
claiming the "FLOAT(copy(preQ2s,1,1))"-expressions are too wide. Any
suggestions on how to solve this in a more elegant way?

Many thanks in advance,

Gustaf

------ Algorithm. "preQ2" is the variable name for the specific
question, defined as a 12 digit number (############)------------
preQ2

    RANGE 199201010001 201801010001
    DEFINE pnr1 _
    DEFINE pnr2 _
    DEFINE pnr3 _
    DEFINE pnr4 _
    DEFINE pnr5 _
    DEFINE pnr6 _
    DEFINE pnr7 _
    DEFINE pnr8 _
    DEFINE pnr9 _
    DEFINE pnr10 _
    DEFINE pnr11 _
    DEFINE pnr12 _
    DEFINE preQ2s ____________
    DEFINE checkSum ##
    preQ2s=string(preQ2)
    pnr1=FLOAT(copy(preQ2s,1,1))
    pnr2=FLOAT(copy(preQ2s,2,2))
    pnr3=FLOAT(copy(preQ2s,3,3))
    pnr4=FLOAT(copy(preQ2s,4,4))
    pnr5=FLOAT(copy(preQ2s,5,5))
    pnr6=FLOAT(copy(preQ2s,6,6))
    pnr7=FLOAT(copy(preQ2s,7,7))
    pnr8=FLOAT(copy(preQ2s,8,8))
    pnr9=FLOAT(copy(preQ2s,9,9))
    pnr10=FLOAT(copy(preQ2s,10,10))
    pnr11=FLOAT(copy(preQ2s,11,11))
    pnr12=FLOAT(copy(preQ2s,12,12))

    IF (pnr3>4)
        THEN pnr3=pnr3*2-9
        ELSE pnr3=pnr3*2
    ENDIF
    IF (pnr5>4)
        THEN pnr5=pnr5*2-9
        ELSE pnr5=pnr5*2
    ENDIF

    IF (pnr7>4)
        THEN pnr7=pnr7*2-9
        ELSE pnr7=pnr7*2
    ENDIF

    IF (pnr9>4)
        THEN pnr9=pnr9*2-9
        ELSE pnr9=pnr9*2
    ENDIF

    IF (pnr11>4)
        THEN pnr11=pnr11*2-9
        ELSE pnr11=pnr11*2
    ENDIF
    checkSum=pnr3+pnr4+pnr5+pnr6+pnr7+pnr8+pnr9+pnr10+pnr11
    IF (checkSum=10*int(checkSum))
        THEN checkSum=checkSum/10
        ELSE checkSum=10*(TRUNC(checkSum/10)+1)-checkSum
    ENDIF
    IF (pnr12<>checkSum)
    THEN
        HELP "felaktigt PersonNummer" TYPE=ERROR
        GOTO preQ2
    ENDIF
END

-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik


More information about the EpiData-list mailing list