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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 690 views
  • 0 likes
  • 2 in conversation