BookmarkSubscribeRSS Feed
Nikos
Fluorite | Level 6

Dear all,

I would very much appreciate your help.

I have a variable that should contain letters and numbers in a predefined combination i.e.   XYZ1234  (3letters - any letters and 4 numbers - any numbers)

The problem is that some values they have:

1.- 2 letters (false) and 3 numbers   (false)

2. 3 letters (correct) and 3 numbers (false)

3.- sometimes within the 3 letters there is one or more numbers while they shouldn't have been

4.  the same applies to letters section ( there are letters instead of numbers

5.-- No letters only numbers --more than  4

etc..

I would like to create a variable that will flag each and every discrepancy from the required as above (3 letters+ 4 numbers)

Thanking you in advance.

Best

Nikos

1 REPLY 1
Haikuo
Onyx | Level 15

If you don't mind using Perl Regular expression, then it can be as simple as:

DATA HAVE;

     INPUT VAR $;

     FLAG=PRXMATCH('/^[A-Z]{3}\d{4}$/',strip(VAR))>0;

     CARDS;

XYZ1234

XZ124

XY1234

12345

X1Y1Z1234

XYZ1234

;


Regards,

Haikuo

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 898 views
  • 0 likes
  • 2 in conversation