Hi!
I am trying to use a regular expression in the DATA step to check that a value is EXACTLY 9 digits.
patternNoDash=prxparse("/^(\d){9}$/");
Another valid pattern is 11 digits long, so the variable has a length of 11. With the anchor characters, this seems to be messing me up(?) I am using ID= strip(ID) to remove all of the outer whitespace but the pattern will still not match with the anchor characters. Am I missing something obvious? I don't have to use regex but I am
You could use the LENGTH() function in SAS, much simpler.
Is the variable character or numeric?
This can be important as when you use character functions, such as the PRX functions, then SAS does an automatic conversion from the numeric to character that likely is not going to result in the actual desired character string before "counting" or matching.
If the variable is actually character than the LENGTH function will return the number of characters though may count any leading spaces. So actual examples of your data and complete code plus what you expect might be helpful in diagnosing what is going on.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.