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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

@Kapir Hi and welcome to the SAS Community 🙂

 

Is it a requirement to use PRX function? 

Kapir
Calcite | Level 5
Thxs draycut.

Its not. I used regexp on the DB without problems so i thought, i could do it with SAS too.
PeterClemmensen
Tourmaline | Level 20

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;
andreas_lds
Jade | Level 19

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.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1349 views
  • 2 likes
  • 3 in conversation