BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Problem Description:
Problem occurs when doing a modulus 10 check on ID Numbers.
I have ID numbers (eg: 1999999999999 and 9999999999999), and the month and day is calculated as 99 and 99 respectively. The problem occurs in the alogrithm.
I have inserted a step: If sum (EvenTot + OddTot) >= 99 Then IdAlgoX = -1; this is to say it is invalid, however the error message still appears??

Can anyone help pls...


/*Fields for valid date testing*/
month = input(substr(temp,3,2),2.);
day = input(substr(temp,5,2),2.);

/*Fields for Modulus 10 check*/;
OddTot= Sum(input(Substr(temp, 1,1),1.),
input(Substr(temp, 3,1),1.),
input(Substr(temp, 5,1),1.),
input(Substr(temp, 7,1),1.),
input(Substr(temp, 9,1),1.),
input(Substr(temp,11,1),1.));

EvenTot=Sum(input(Substr(Put(input(Substr(temp, 2,1),1.)*2,z2.),1,1),1.), /* Two1 */
input(Substr(Put(input(Substr(temp, 2,1),1.)*2,z2.),2,1),1.), /* Two2 */
input(Substr(Put(input(Substr(temp, 4,1),1.)*2,z2.),1,1),1.), /* Fou1 */
input(Substr(Put(input(Substr(temp, 4,1),1.)*2,z2.),2,1),1.), /* Fou2 */
input(Substr(Put(input(Substr(temp, 6,1),1.)*2,z2.),1,1),1.), /* Six1 */
input(Substr(Put(input(Substr(temp, 6,1),1.)*2,z2.),2,1),1.), /* Six2 */
input(Substr(Put(input(Substr(temp, 8,1),1.)*2,z2.),1,1),1.), /* Eig1 */
input(Substr(Put(input(Substr(temp, 8,1),1.)*2,z2.),2,1),1.), /* Eig2 */
input(Substr(Put(input(Substr(temp,10,1),1.)*2,z2.),1,1),1.), /* Ten1 */
input(Substr(Put(input(Substr(temp,10,1),1.)*2,z2.),2,1),1.), /* Ten2 */
input(Substr(Put(input(Substr(temp,12,1),1.)*2,z2.),1,1),1.), /* Twe1 */
input(Substr(Put(input(Substr(temp,12,1),1.)*2,z2.),2,1),1.)); /* Twe2 */

IdAlgoX=10-input(Substr(Put(Sum(EvenTot,OddTot),z2.),2,1),1.);
If sum (EvenTot + OddTot) >= 99 Then IdAlgoX = -1;
IdAlgoY=input(Substr(temp,13,1),1.);
If IdAlgoX = 10 then IdAlgoX = 0;
1 REPLY 1
Patrick
Opal | Level 21
Hi sas-learner2

I was honestly too lazy in trying to understand your code to the last bit.

May be the following is anyway of some help to you as it implements a modulo10 check as described in http://en.wikipedia.org/wiki/Luhn_algorithm for any string with digits only.

There might be more elaborate ways to do it and I'm almost sure this wheel is already invented in the SAS world. The code below is what I can come up with right now.

HTH
Patrick

data _null_;
input id $ 1-30;
length AddIt $2;
ChkStr=left(reverse(id));
do pos=1 to length(ChkStr);
if mod(pos,2) then /* odd positions */
do;
AddIt=substr(ChkStr,pos,1);
end;
else /* even positions: digit*2 */
do;
AddIt=put(2*input(substr(ChkStr,pos,1),2.),2.);
end;

/* add digits */
do i=1 to length(AddIt);
ChkSum+input(substr(AddIt,i,1),2.);
end;
end;

/* Check if ID is valid or not (if ChkSum ends with Zero) */
if mod(ChkSum,10)=0 then
do;
put 'This is a valid ID: ' ID= ChkSum=;
end;
else
if mod(ChkSum,10) ne 0 then
do;
put 'This is a invalid ID: ' ID= ChkSum=;
end;

datalines;
123456789
3847592
48573726264859560
2843759
00028434305834
442308239586
;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1179 views
  • 0 likes
  • 2 in conversation