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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.