<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Modulus 10 check in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Modulus-10-check/m-p/62120#M17656</link>
    <description>Hi sas-learner2&lt;BR /&gt;
&lt;BR /&gt;
I was honestly too lazy in trying to understand your code to the last bit.&lt;BR /&gt;
&lt;BR /&gt;
May be the following is anyway of some help to you as it implements a modulo10 check as described in &lt;A href="http://en.wikipedia.org/wiki/Luhn_algorithm" target="_blank"&gt;http://en.wikipedia.org/wiki/Luhn_algorithm&lt;/A&gt; for any string with digits only.&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  input id $ 1-30;&lt;BR /&gt;
  length AddIt $2;&lt;BR /&gt;
  ChkStr=left(reverse(id));&lt;BR /&gt;
  do pos=1 to length(ChkStr);&lt;BR /&gt;
    if mod(pos,2) then /* odd positions */&lt;BR /&gt;
    do;&lt;BR /&gt;
      AddIt=substr(ChkStr,pos,1);&lt;BR /&gt;
    end;&lt;BR /&gt;
    else /* even positions: digit*2 */&lt;BR /&gt;
    do;&lt;BR /&gt;
      AddIt=put(2*input(substr(ChkStr,pos,1),2.),2.);&lt;BR /&gt;
    end;&lt;BR /&gt;
&lt;BR /&gt;
    /* add digits */&lt;BR /&gt;
    do i=1 to length(AddIt);&lt;BR /&gt;
      ChkSum+input(substr(AddIt,i,1),2.);&lt;BR /&gt;
    end;&lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
  /* Check if ID is valid or not (if ChkSum ends with Zero) */&lt;BR /&gt;
  if mod(ChkSum,10)=0 then&lt;BR /&gt;
  do;&lt;BR /&gt;
    put 'This is a valid ID: ' ID= ChkSum=;&lt;BR /&gt;
  end;&lt;BR /&gt;
  else &lt;BR /&gt;
  if mod(ChkSum,10) ne 0 then&lt;BR /&gt;
  do;&lt;BR /&gt;
    put 'This is a invalid ID: ' ID= ChkSum=;&lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
  datalines;&lt;BR /&gt;
123456789&lt;BR /&gt;
3847592&lt;BR /&gt;
 48573726264859560&lt;BR /&gt;
  2843759&lt;BR /&gt;
00028434305834&lt;BR /&gt;
 442308239586&lt;BR /&gt;
;&lt;BR /&gt;
run;</description>
    <pubDate>Wed, 19 Nov 2008 10:16:35 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2008-11-19T10:16:35Z</dc:date>
    <item>
      <title>Modulus 10 check</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Modulus-10-check/m-p/62119#M17655</link>
      <description>Problem Description:&lt;BR /&gt;
   Problem occurs when doing a modulus 10 check on ID Numbers.&lt;BR /&gt;
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. &lt;BR /&gt;
I have inserted a step: If sum (EvenTot + OddTot) &amp;gt;= 99 Then IdAlgoX = -1; this is to say it is invalid, however the error message still appears??&lt;BR /&gt;
&lt;BR /&gt;
Can anyone help pls...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 /*Fields for valid date testing*/&lt;BR /&gt;
	        month = input(substr(temp,3,2),2.);&lt;BR /&gt;
	        day = input(substr(temp,5,2),2.);&lt;BR /&gt;
&lt;BR /&gt;
	        /*Fields for Modulus 10 check*/;&lt;BR /&gt;
	        OddTot= Sum(input(Substr(temp, 1,1),1.),&lt;BR /&gt;
	                    input(Substr(temp, 3,1),1.),&lt;BR /&gt;
	                    input(Substr(temp, 5,1),1.),&lt;BR /&gt;
	                    input(Substr(temp, 7,1),1.),&lt;BR /&gt;
	                    input(Substr(temp, 9,1),1.),&lt;BR /&gt;
	                    input(Substr(temp,11,1),1.));&lt;BR /&gt;
&lt;BR /&gt;
	        EvenTot=Sum(input(Substr(Put(input(Substr(temp, 2,1),1.)*2,z2.),1,1),1.),   /* Two1 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp, 2,1),1.)*2,z2.),2,1),1.),   /* Two2 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp, 4,1),1.)*2,z2.),1,1),1.),   /* Fou1 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp, 4,1),1.)*2,z2.),2,1),1.),   /* Fou2 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp, 6,1),1.)*2,z2.),1,1),1.),   /* Six1 */            &lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp, 6,1),1.)*2,z2.),2,1),1.),   /* Six2 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp, 8,1),1.)*2,z2.),1,1),1.),   /* Eig1 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp, 8,1),1.)*2,z2.),2,1),1.),   /* Eig2 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp,10,1),1.)*2,z2.),1,1),1.),   /* Ten1 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp,10,1),1.)*2,z2.),2,1),1.),   /* Ten2 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp,12,1),1.)*2,z2.),1,1),1.),   /* Twe1 */&lt;BR /&gt;
	                    input(Substr(Put(input(Substr(temp,12,1),1.)*2,z2.),2,1),1.));  /* Twe2 */&lt;BR /&gt;
&lt;BR /&gt;
	        IdAlgoX=10-input(Substr(Put(Sum(EvenTot,OddTot),z2.),2,1),1.);&lt;BR /&gt;
		If sum (EvenTot + OddTot) &amp;gt;= 99 Then IdAlgoX = -1; &lt;BR /&gt;
	        IdAlgoY=input(Substr(temp,13,1),1.);&lt;BR /&gt;
	        If IdAlgoX = 10 then IdAlgoX = 0;</description>
      <pubDate>Wed, 19 Nov 2008 09:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Modulus-10-check/m-p/62119#M17655</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-11-19T09:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Modulus 10 check</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Modulus-10-check/m-p/62120#M17656</link>
      <description>Hi sas-learner2&lt;BR /&gt;
&lt;BR /&gt;
I was honestly too lazy in trying to understand your code to the last bit.&lt;BR /&gt;
&lt;BR /&gt;
May be the following is anyway of some help to you as it implements a modulo10 check as described in &lt;A href="http://en.wikipedia.org/wiki/Luhn_algorithm" target="_blank"&gt;http://en.wikipedia.org/wiki/Luhn_algorithm&lt;/A&gt; for any string with digits only.&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  input id $ 1-30;&lt;BR /&gt;
  length AddIt $2;&lt;BR /&gt;
  ChkStr=left(reverse(id));&lt;BR /&gt;
  do pos=1 to length(ChkStr);&lt;BR /&gt;
    if mod(pos,2) then /* odd positions */&lt;BR /&gt;
    do;&lt;BR /&gt;
      AddIt=substr(ChkStr,pos,1);&lt;BR /&gt;
    end;&lt;BR /&gt;
    else /* even positions: digit*2 */&lt;BR /&gt;
    do;&lt;BR /&gt;
      AddIt=put(2*input(substr(ChkStr,pos,1),2.),2.);&lt;BR /&gt;
    end;&lt;BR /&gt;
&lt;BR /&gt;
    /* add digits */&lt;BR /&gt;
    do i=1 to length(AddIt);&lt;BR /&gt;
      ChkSum+input(substr(AddIt,i,1),2.);&lt;BR /&gt;
    end;&lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
  /* Check if ID is valid or not (if ChkSum ends with Zero) */&lt;BR /&gt;
  if mod(ChkSum,10)=0 then&lt;BR /&gt;
  do;&lt;BR /&gt;
    put 'This is a valid ID: ' ID= ChkSum=;&lt;BR /&gt;
  end;&lt;BR /&gt;
  else &lt;BR /&gt;
  if mod(ChkSum,10) ne 0 then&lt;BR /&gt;
  do;&lt;BR /&gt;
    put 'This is a invalid ID: ' ID= ChkSum=;&lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
  datalines;&lt;BR /&gt;
123456789&lt;BR /&gt;
3847592&lt;BR /&gt;
 48573726264859560&lt;BR /&gt;
  2843759&lt;BR /&gt;
00028434305834&lt;BR /&gt;
 442308239586&lt;BR /&gt;
;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 19 Nov 2008 10:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Modulus-10-check/m-p/62120#M17656</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-11-19T10:16:35Z</dc:date>
    </item>
  </channel>
</rss>

