There’s Power in Edit Words
December 3, 2008 Hey, Ted
I am trying to use an edit word to insert hyphens into an account number. I must be doing something wrong, because leading zeros don’t show up. I’ve used edit codes for years, but rarely edit words. Can you help?
You’re not doing anything wrong. That’s the way edit words work, Laurie. The system blanks out everything before the first non-zero digit, including editing characters. The good news is there’s a way around it.
Let’s illustrate with an example that many of your fellow readers will be familiar with: those nine-digit Social Security numbers without which Americans can’t do anything.
The usual way to edit a Social Security number is to place hyphens after the third and fifth digits, like this: 123-45-6789. I don’t know if any Social Security numbers begin with zero or not, but that’s irrelevant to this illustration, so I’ll assume they can.
The following code uses an edit word to insert the hyphens, as you are trying to with your account numbers.
D SSN s 9p 0 D EditedSSN s 11a /free EditedSSN = %editw(SSN:' - - ');
This code works fine if the first digit is not zero, but fails otherwise. Look at the edited values in the following table.