- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You could use the LENGTH() function in SAS, much simpler.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.