BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BernyOsuna
Obsidian | Level 7

Hi Guys

 

So i have a dataset with a variable with ID´s. ID´s should consist of 2 ALPHA positions and 8 DIGITposition. If this requirement is not met i should write it in a separated dataset.

 

AB12345678

 

The first filter i wanna say its the length = 10.

Second one is that first 2 positions both should be ALPHA.

Third that every single position from the 3rd to the 10th should be DIGIT.

 

If any of this requirements is not met, immediatly without going any further should be sent to a dataset.

 

I´ve seen the following code.

 

data _null_;    
   string='Next = _n_ + 12E3;';  
   j=0;  
   do until(j=0);  
      j=anyalpha(string,j+1);  
      if j=0 then put +3 "That's all";  
      else do;          
         c=substr(string,j,1);  
         put +3 j= c=;  
      end; 
   end;
run;

 

 But i wonder how could i integrate the ANYDIGIT part and the conditional for every position after has been validated wheater is an ALPHA or a DIGIT.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input x $20.;
cards;
AB12345678
A12345678
;
run;
data right error;
 set have;
 if prxmatch('/^[a-z]{2}\d{8}$/i',strip(x)) then output right;
  else output error;
 run;

View solution in original post

3 REPLIES 3
Reeza
Super User

Substr out the components and check them. Look at NOTALPHA/NOTDIGIT as well.

 

LENGTH() = 10

SUBSTR(string, 1, 2) - NOTALPHA

SUBSTR(string, 3, 😎 - NOTDIGIT

 

 

Ksharp
Super User
data have;
input x $20.;
cards;
AB12345678
A12345678
;
run;
data right error;
 set have;
 if prxmatch('/^[a-z]{2}\d{8}$/i',strip(x)) then output right;
  else output error;
 run;
BernyOsuna
Obsidian | Level 7

Thanks a lot Ksharp I didn´t know about this PRXMATCH command it did work great!!

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!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2988 views
  • 2 likes
  • 3 in conversation