Generate a control figure and authenticate a universal credit identifier in SAS
This article shows how to use SAS to implement ISO algorithm to generate (and validate) an identifier of universal credit (UL). A ul is a long range of numbers and letters that serve as a unique identifier used for certain financial transactions. The ISO standard ensures that banks and other financial entities have a uniform way to identify accounts. The details are provided by a financial regulation showing how to generate and certify a check figure for an account. One step that can challenge SAS programmers is to calculate the module operations in a long range range. A previous article explains why you should use a special function for that step, rather than convert the string to a numerical value and use the integrated mod function in SAS.
What is a check figure?
Have you ever mistaken your credit card on a website and you were told that the credit card number is invalid? Have you thought about how the website knew the number you were wrong? When using a long number or range to identify a financial account, it is common to enter a check digit into the number, which can help ensure that the number is suppressed and transmitted properly. The credit card validity algorithm receives a number like 1789372997 and calculates a new number (called the control figure) based on a modulo operation has performed a number transformation (such as the sum of the digits). Chris Hemedinger has blogged for credit cards and the ID of the National Provider. It shows how to use SAS to generate control figures and prove that the numbers are valid.
Generate a control figure for a ul
Entity Financial Entity is designated with 20 alphanumeric characters of the Legal Entity (Lei). For example, Wikipedia’s article about Leis states that Jaguar Land Rover Ltd has Lei 213800WSGIZCF1P572. Similarly, each account has an identifier such as 123456x. If you combine these wires together, the combined string 213800WSGIZCF1P572123456X uniquely identifies the account within the company. Documentation for ISO standard tells you exactly how to generate a control figure for this long range:
- Replace each letter (the issue does not matter) with a figure according to the map ‘a’ = 10, ‘b’ = 11, …, ‘z’ = 35. Now you have a long string consisting entirely of the digits.
- Add string ’00’ (two voices) to the end of the string. Call the N.
- Apply the modulo mathematical operation R = mod (n, 97) to find the remainder of the division n with the main number 97. You can perform this operation in SAS by passing through the string characters. You should not turn the string into a number of double precision.
The following call for Procmp FCMP defines a function that replaces letters with two-digit numbers. The function is also determined by the previous article (which calculates the module for a range of digits).
proc fcmp outlib=work.banking.ULI; /* Given an input string that contains numbers and letters, upcase the string and transform it by replacing letters according to 'A'->'10', 'B'->'11', 'C'->'12', ..., 'Z'->'35', The output is a 64-byte string, so make sure the input arg isn't too long */ function replace_alphabetic(ULI_alpha $) $64; /* return a 64-byte string */ length ULI $64; array Letters(26) $1; /* target characters */ array Numbers(26) $2; /* replacement characters */ do i = 1 to dim(Letters); Letters(i) = byte(64 + i); /* the ASCII seq: 'A'=65, ..., 'Z'=90 */ Numbers(i) = put(9 + i, 2.); /* '10', '11', '12', ..., '35' */ end; ULI = upcase(ULI_alpha); do i = 1 to dim(Letters); ULI = tranwrd(ULI, Letters(i), Numbers(i)); /* replaces each letter with a 2-digit number */ end; return ( ULI ); endsub; /* Compute the remainder of a large integer (represented as a string) when divided by d. This implements the standard long-division algorithm, but at the i_th step the i_th character is converted to an integer. */ function mod_from_string(s $, d); r = 0; /* initialize remainder */ do i = 1 to length(s); c = substr(s, i, 1); /* i_th digit as character */ digit = input(c, 1.); /* i_th digit as integer */ r = mod(10*r + digit, d); /* running remainder */ end; return( r ); /* return remainder as an integer */ endsub; quit; |
Create a lei and credit ID
Once you calculate the control figure, you can use it to create a unique string is called a universal credit identifier. Let’s apply the algorithm to two financial entities (GE funding GMBH and Jaguar Land Rover Ltd) presented in the Wikipedia article for Leis. The first entity has three credits. The second unit has two credits. Here are example data:
data Loans; length LEI $20 LoanID $8; input LEI LoanID; datalines; 54930084UKLVMY22DS16 999143X 54930084UKLVMY22DS16 999103Z 54930084UKLVMY22DS16 999104Z 213800WSGIIZCXF1P572 123456X 213800WSGIIZCXF1P572 789012Y ; |
ISO standard specifies how to create a control figure and form ul:
- Concine Lei’s and Loan ID wires. Replace the letters with numbers.
- Appendix ’00’ to finish string.
- Calculate the remainder r = mod (n, 97), where n is the range of numbers in the previous step. You can do this without converting the string to a number.
- Calculate the control figure as 98 – r. This is a number between 2-98. Turn it into a two-character string ’02’-’98’
- Uli is the union of the LEI string, the credit ID and the control figure.
For example, the following step of SAS data creates a low for credit and fictitious credit data group:
option cmplib=work.banking; /* set search path for the FCMP function(s) */ /* Generate a check digit for a LEI and LoanId pair, then create a ULI. The procedure for generating a check digit is documented at https://www.consumerfinance.gov/rules-policy/regulations/1003/c/ */ data Create_ULI; set Loans; /* vars are LEI and LoanID */ /* Steps */ sA = cats(LEI, LoanID); /* 0: concat LEI and LoanID */ sN = replace_alphabetic(sA); /* 1: Replace letters with numbers */ L = length(sN); substr(sN, L+1, 2) = '00'; /* 2: append '00' to end of string */ r = mod_from_string(sN, 97); /* 3: remainder mod 97 (as a number) */ checkdigit = 98 - r; /* 4: compute the check digit (as a number) */ ULI = cats(LEI, LoanID, put(checkdigit,Z2.)); /* 5: Append check digits (as a two-character string) */ keep LEI LoanID sN checkdigit ULI; run; proc print data=Create_ULI; var checkdigit ULI; run; |
You can visually inspect the ULI column to verify that the UL is the Lei Union, the Credit ID and the control figure.
Appreciate a ul
If someone gets ul, they can easily extract the original lei and the credit ID. However, they must first prove that the ulce contains no mistakes. To do it, you perform the following steps:
- Replace the letters in the number with numbers.
- Calculate the remainder r = mod (n, 97), where n is the range of numbers in the previous step. You can do this without converting the string to a number.
- If the rest is 1, conclude that the ul is valid. Otherwise, refuse ul.
Each low in the CREATE_ULI data set and valid. To demonstrate that valoring algorithm can detect invalid ulcers, the following data step changes a figure in the last low from A ‘5’ to A ‘6’:
/* Create an "error": to test whether the validation can detect errors, change a digit of the last ULI */ data ULI; set Create_ULI(keep=ULI) end=EOF; if EOF then substr(ULI, 1, 1) = '6'; /* create an "error" in this ULI */ run; |
For the new ule, the following step of the SAS data reads ulis and creates the remaining modulo 97:
/* Validate a ULI. The validation procedure is documented at https://www.consumerfinance.gov/rules-policy/regulations/1003/c/ */ data Validate_ULI; set ULI; /* var is named ULI */ sN = replace_alphabetic(ULI); /* 1: Replace letters with numbers */ r = mod_from_string(sN, 97); /* 2: remainder mod 97 */ isValid = (r=1); /* 3: check if remainder is 1 */ run; proc print data=Validate_ULI; var ULI r isValid; run; |
Validity algorithm reports that the first four seals are valid. However, the last low, which we deliberately modified is invalid.
Briefing
This article shows how to use SAS to generate and certify a universal credit identifier (uli). A ul is a long range of numbers and letters that serve as a unique identifier used for certain financial transactions. To ensure that the string is transmitted correctly, you must be able to calculate the remaining 97 module of a long range of numbers. This article shows how to implement the FCMP Assistant Functions that help you encode and decipher ul.
Although the auxiliary functions in this article are specific to a universal credit identifier, there are many other wires of numbers and letters that serve as identifiers and for which you need to calculate a control figure. You can modify the help functions in this article to handle similar situations.