Hello,
i have a colum "CODE" with data like "22A", "3z", "43 G" and so on.
Tryed to extract the characters with prxmatch('/[a-zA-Z]/',CODE). It shows me the position but i dont know, what to write in SAS EG that the new column just have the character.
Besides i need the same, just for the numbers.
So that Code are split in 2 new columns with just the characters and just the numbers.
How to archive this in SAS EG? I created 2 new calculated columns and thought with prxmatch('/[a-zA-Z]/',CODE) and prxmatch('/[0-9]/',CODE) i can archive this.
You can do something like this
data have;
length string $20;
string="22A"; output;
string="3z"; output;
string="43 G"; output;
run;
data want;
set have;
newstring=compress(string, , 'ka');
run;
You can do something like this
data have;
length string $20;
string="22A"; output;
string="3z"; output;
string="43 G"; output;
run;
data want;
set have;
newstring=compress(string, , 'ka');
run;
The function prxmatch does exactly what its names says: it verifies that text matches an expression. If you want extract something you have to use prxchange or prxposn additionally. Fortunately the function compress - as suggested by @PeterClemmensen - can solve the issue without regex.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.