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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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