Hi, I need to check Swedish personal identity numbers and need code to check wether the numer in a variable is correct or not. Please submit code if you have any.
What is the exact condition for the number to be valid?
In reference to your thread title, you might take a look at the mod() function (if this is somehow used to verify that the number is a valid one)
The modulo of 35 by 10 would be 5. Where in the number should the 5 be found? Or should 5 then be the sum of the digits of the last 2 positions?
A preliminary implementation of the check algorithm looks like this:
data _null_;
x = '196308101632';
sum = 0;
do i = 1 to 10;
sumi = input(substr(x,i,1),1.);
if mod(i,2) = 1
then do;
sumi = sumi * 2;
if sumi > 10 then sumi = sumi - 9;
end;
sum + sumi;
put i=;
put sumi=;
end;
put sum=;
check = mod(sum,10);
put check=;
run;
The question is now, with what should we compare the value "check"?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.