New user trying to implement a check algorithm
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
To fix this, define prn1 etc as an integer rather than _ ( _ means string). You cannot do the arithmetic on prn as a string.These temporary variables should be defined as global so that they don't appear in the data.
define checksum ## global define prn1 # global
Then you can extract the digits thus:
prn1 = integer(copy(preQ2a,1,1))
I think you need to include the first digit in the algorithm as well. My reading of the validation algorithm means you just need to check that the total for all digits is a multiple of 10, so:
checkSum=prn1+pnr3+pnr4+pnr5+pnr6+pnr7+pnr8+pnr9+pnr10+pnr11+prn12 IF (checkSum mod 10) <> 0 THEN HELP "felaktigt PersonNummer" TYPE=ERROR GOTO preQ2 ENDIF
Jamie
Gustaf wrote:
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).
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
participants (1)
-
epidata-list@lists.umanitoba.ca