Text mining and content categorization

ANYALPHA & ANYDIGIT VALIDATION

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

ANYALPHA & ANYDIGIT VALIDATION

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.


Accepted Solutions
Solution
‎03-07-2017 11:07 AM
Grand Advisor
Posts: 9,463

Re: ANYALPHA & ANYDIGIT VALIDATION

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


All Replies
Grand Advisor
Posts: 16,926

Re: ANYALPHA & ANYDIGIT VALIDATION

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

 

LENGTH() = 10

SUBSTR(string, 1, 2) - NOTALPHA

SUBSTR(string, 3, 8) - NOTDIGIT

 

 

Solution
‎03-07-2017 11:07 AM
Grand Advisor
Posts: 9,463

Re: ANYALPHA & ANYDIGIT VALIDATION

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;
New Contributor
Posts: 3

Re: ANYALPHA & ANYDIGIT VALIDATION

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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