BookmarkSubscribeRSS Feed
Fluorite | Level 6



I am trying to use a regular expression in the DATA step to check that a value is EXACTLY 9 digits. 




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



Diamond | Level 26

You could use the LENGTH() function in SAS, much simpler.

Paige Miller
Super User

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. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3 in conversation