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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.