<?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: Using Verhoeff Check Digit in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/929808#M365830</link>
    <description>&lt;P&gt;You're welcome. Only a few small changes (highlighted in bold below) to the previous code are needed to create a new function VCDVAL that returns 1 if the last digit of the argument is the correct Verhoeff check digit and 0 otherwise:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#999999"&gt;/* &lt;FONT color="#000000"&gt;&lt;STRONG&gt;Validate&lt;/STRONG&gt;&lt;/FONT&gt; a check digit from a digit string S according to the Verhoeff algorithm,
   using tables and formulas from https://en.wikipedia.org/wiki/Verhoeff_algorithm (2024-05-17) */

proc fcmp outlib=work.funcs.test;
function vcd&lt;FONT color="#000000"&gt;&lt;STRONG&gt;val&lt;/STRONG&gt;&lt;/FONT&gt;(s $);
array d[10,10] /nosymbols (0 1 2 3 4 5 6 7 8 9
                           1 2 3 4 0 6 7 8 9 5
                           2 3 4 0 1 7 8 9 5 6
                           3 4 0 1 2 8 9 5 6 7
                           4 0 1 2 3 9 5 6 7 8
                           5 9 8 7 6 0 4 3 2 1
                           6 5 9 8 7 1 0 4 3 2
                           7 6 5 9 8 2 1 0 4 3
                           8 7 6 5 9 3 2 1 0 4
                           9 8 7 6 5 4 3 2 1 0);
array v[10] /nosymbols (0 4 3 2 1 5 6 7 8 9);
array p[8,10] /nosymbols (0 1 2 3 4 5 6 7 8 9
                          1 5 7 6 2 8 3 0 9 4
                          5 8 0 3 7 9 6 1 4 2
                          8 9 1 6 0 4 3 5 2 7
                          9 4 5 3 1 2 6 8 7 0
                          4 2 8 6 5 7 3 9 0 1
                          2 7 9 3 8 0 6 4 1 5
                          7 0 4 6 9 1 3 2 5 8);
array n[1] /nosymbols;
k=length(s);
call dynamic_array(n, k);
do i=1 to k;
  n[i]=input(char(s,k-i+1),1.);
end;
c=0;
do i=1 to k;
  c=d[c+1,p[mod(i&lt;FONT color="#000000"&gt;&lt;STRONG&gt;-1&lt;/STRONG&gt;&lt;/FONT&gt;,8)+1,n[i]+1]+1];
end;
&lt;FONT color="#000000"&gt;&lt;STRONG&gt;val&lt;/STRONG&gt;&lt;/FONT&gt;=&lt;FONT color="#000000"&gt;&lt;STRONG&gt;(c=0)&lt;/STRONG&gt;&lt;/FONT&gt;;
return(&lt;FONT color="#000000"&gt;&lt;STRONG&gt;val&lt;/STRONG&gt;&lt;/FONT&gt;);
endsub;
run;

options cmplib=work.funcs;&lt;/FONT&gt;

/* Example */

data _null_;
if vcdval('2363') then put 'Check digit is correct.';
                  else put 'Check digit is wrong.';
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having the two functions in place, it's easy to check their consistency on, say, one million random digit strings with lengths ranging from 1 to, e.g., 40:&lt;/P&gt;
&lt;PRE&gt;358   data _null_;
359   call streaminit('MT64',27182818);
360   length s $40;
361   do i=1 to 1e6;
362     s=' ';
363     do j=1 to rand('integer',40);
364       substr(s,j,1)=put(rand('integer',0,9),1.);
365     end;
366     if vcdval(cats(s,vcd(s)))=0 then do;
367       put 'ER' 'ROR: Wrong check digit encountered for ' s=;
368       stop;
369     end;
370   end;
371   run;

NOTE: DATA statement used (Total process time):
      real time           20.93 seconds
      cpu time            20.79 seconds&lt;/PRE&gt;</description>
    <pubDate>Mon, 27 May 2024 10:57:21 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-05-27T10:57:21Z</dc:date>
    <item>
      <title>Using Verhoeff Check Digit in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/928777#M365455</link>
      <description>&lt;P&gt;Hi, do you guys ever work with Verhoeff check digit algorithm (&lt;A href="https://en.wikipedia.org/wiki/Verhoeff_algorithm" target="_blank"&gt;https://en.wikipedia.org/wiki/Verhoeff_algorithm&lt;/A&gt;) with SAS? I am trying to use sas for verhoeff check digit but havent found any script to do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 00:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/928777#M365455</guid>
      <dc:creator>febyinka</dc:creator>
      <dc:date>2024-05-17T00:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using Verhoeff Check Digit in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/928836#M365470</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466033"&gt;@febyinka&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank your very much for sharing this interesting link.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466033"&gt;@febyinka&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to use sas for verhoeff check digit but havent found any script to do so.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In this situation I would try and write my own function using &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p10b4qouzgi6sqn154ipglazix2q.htm" target="_blank" rel="noopener"&gt;PROC FCMP&lt;/A&gt;, as shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Compute a check digit from a digit string S according to the Verhoeff algorithm,
   using tables and formulas from https://en.wikipedia.org/wiki/Verhoeff_algorithm (2024-05-17) */

proc fcmp outlib=work.funcs.test;
function vcd(s $);
array d[10,10] /nosymbols (0 1 2 3 4 5 6 7 8 9
                           1 2 3 4 0 6 7 8 9 5
                           2 3 4 0 1 7 8 9 5 6
                           3 4 0 1 2 8 9 5 6 7
                           4 0 1 2 3 9 5 6 7 8
                           5 9 8 7 6 0 4 3 2 1
                           6 5 9 8 7 1 0 4 3 2
                           7 6 5 9 8 2 1 0 4 3
                           8 7 6 5 9 3 2 1 0 4
                           9 8 7 6 5 4 3 2 1 0);
array v[10] /nosymbols (0 4 3 2 1 5 6 7 8 9);
array p[8,10] /nosymbols (0 1 2 3 4 5 6 7 8 9
                          1 5 7 6 2 8 3 0 9 4
                          5 8 0 3 7 9 6 1 4 2
                          8 9 1 6 0 4 3 5 2 7
                          9 4 5 3 1 2 6 8 7 0
                          4 2 8 6 5 7 3 9 0 1
                          2 7 9 3 8 0 6 4 1 5
                          7 0 4 6 9 1 3 2 5 8);
array n[1] /nosymbols;
k=length(s);
call dynamic_array(n, k);
do i=1 to k;
  n[i]=input(char(s,k-i+1),1.);
end;
c=0;
do i=1 to k;
  c=d[c+1,p[mod(i,8)+1,n[i]+1]+1];
end;
cd=v[c+1];
return(cd);
endsub;
run;

options cmplib=work.funcs;

/* Example */

data _null_;
x=vcd('236');
put 'Check digit = ' x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result: 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 16:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/928836#M365470</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-05-17T16:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using Verhoeff Check Digit in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/928850#M365471</link>
      <description>&lt;P&gt;Excellent approach by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. It reminds me of a challenge I had years ago in &lt;A href="https://blogs.sas.com/content/sasdummy/validate-npi-with-sas/" target="_self"&gt;validating NPI (national provider identity) numbers&lt;/A&gt;, which relies on the Luhn algorithm. I also created an FCMP version!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 16:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/928850#M365471</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2024-05-17T16:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using Verhoeff Check Digit in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/929768#M365811</link>
      <description>&lt;P&gt;Hi Thank You it was great and working perfectly!!&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2024 07:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/929768#M365811</guid>
      <dc:creator>febyinka</dc:creator>
      <dc:date>2024-05-27T07:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using Verhoeff Check Digit in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/929808#M365830</link>
      <description>&lt;P&gt;You're welcome. Only a few small changes (highlighted in bold below) to the previous code are needed to create a new function VCDVAL that returns 1 if the last digit of the argument is the correct Verhoeff check digit and 0 otherwise:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#999999"&gt;/* &lt;FONT color="#000000"&gt;&lt;STRONG&gt;Validate&lt;/STRONG&gt;&lt;/FONT&gt; a check digit from a digit string S according to the Verhoeff algorithm,
   using tables and formulas from https://en.wikipedia.org/wiki/Verhoeff_algorithm (2024-05-17) */

proc fcmp outlib=work.funcs.test;
function vcd&lt;FONT color="#000000"&gt;&lt;STRONG&gt;val&lt;/STRONG&gt;&lt;/FONT&gt;(s $);
array d[10,10] /nosymbols (0 1 2 3 4 5 6 7 8 9
                           1 2 3 4 0 6 7 8 9 5
                           2 3 4 0 1 7 8 9 5 6
                           3 4 0 1 2 8 9 5 6 7
                           4 0 1 2 3 9 5 6 7 8
                           5 9 8 7 6 0 4 3 2 1
                           6 5 9 8 7 1 0 4 3 2
                           7 6 5 9 8 2 1 0 4 3
                           8 7 6 5 9 3 2 1 0 4
                           9 8 7 6 5 4 3 2 1 0);
array v[10] /nosymbols (0 4 3 2 1 5 6 7 8 9);
array p[8,10] /nosymbols (0 1 2 3 4 5 6 7 8 9
                          1 5 7 6 2 8 3 0 9 4
                          5 8 0 3 7 9 6 1 4 2
                          8 9 1 6 0 4 3 5 2 7
                          9 4 5 3 1 2 6 8 7 0
                          4 2 8 6 5 7 3 9 0 1
                          2 7 9 3 8 0 6 4 1 5
                          7 0 4 6 9 1 3 2 5 8);
array n[1] /nosymbols;
k=length(s);
call dynamic_array(n, k);
do i=1 to k;
  n[i]=input(char(s,k-i+1),1.);
end;
c=0;
do i=1 to k;
  c=d[c+1,p[mod(i&lt;FONT color="#000000"&gt;&lt;STRONG&gt;-1&lt;/STRONG&gt;&lt;/FONT&gt;,8)+1,n[i]+1]+1];
end;
&lt;FONT color="#000000"&gt;&lt;STRONG&gt;val&lt;/STRONG&gt;&lt;/FONT&gt;=&lt;FONT color="#000000"&gt;&lt;STRONG&gt;(c=0)&lt;/STRONG&gt;&lt;/FONT&gt;;
return(&lt;FONT color="#000000"&gt;&lt;STRONG&gt;val&lt;/STRONG&gt;&lt;/FONT&gt;);
endsub;
run;

options cmplib=work.funcs;&lt;/FONT&gt;

/* Example */

data _null_;
if vcdval('2363') then put 'Check digit is correct.';
                  else put 'Check digit is wrong.';
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having the two functions in place, it's easy to check their consistency on, say, one million random digit strings with lengths ranging from 1 to, e.g., 40:&lt;/P&gt;
&lt;PRE&gt;358   data _null_;
359   call streaminit('MT64',27182818);
360   length s $40;
361   do i=1 to 1e6;
362     s=' ';
363     do j=1 to rand('integer',40);
364       substr(s,j,1)=put(rand('integer',0,9),1.);
365     end;
366     if vcdval(cats(s,vcd(s)))=0 then do;
367       put 'ER' 'ROR: Wrong check digit encountered for ' s=;
368       stop;
369     end;
370   end;
371   run;

NOTE: DATA statement used (Total process time):
      real time           20.93 seconds
      cpu time            20.79 seconds&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 May 2024 10:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Verhoeff-Check-Digit-in-SAS/m-p/929808#M365830</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-05-27T10:57:21Z</dc:date>
    </item>
  </channel>
</rss>

