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.
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;
Substr out the components and check them. Look at NOTALPHA/NOTDIGIT as well.
LENGTH() = 10
SUBSTR(string, 1, 2) - NOTALPHA
SUBSTR(string, 3, 😎 - NOTDIGIT
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;
Thanks a lot Ksharp I didn´t know about this PRXMATCH command it did work great!!
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.
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.