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

 

Hello;

 

I'm trying to extract whith regulars expressions the parts of names that are surrounded by paratheses.

For started, I try to detect what starts with a parenthesis and no word does match.

That is why, i am asking you for help me.

Thank you

 

 

data test;
  input name $25.;
  cards;
test (ex)
(ex) test
test test
;
run;


data test1;
set test;
i=1;
do while (scan(name,i, " ") ne ' ') ;
    part=scan(name,i);
    regex = prxparse("/(?<=\()/");
    if prxmatch(regex, part) >0 then output;
    i+1;
end;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ok. You can do something like this

 

data test;
  input name $25.;
  cards;
test (ex)
(ex) test
test test
;
run;

data want;
   set test;
   a=prxchange('s/\(.*\)//', -1, name);
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

So for each value of the name variable that is inside a parenthesis, you want a new record, correct? 

 

From your posted data set, what does your desired result look like?

mansour_ib_sas
Pyrite | Level 9

Thank you for your answer,

For your first question, i want to delete the reccord inside a parenthesis  by regulare expression.

For your second question:

 

data test;
  input name $25.;
  cards;

test test test test
;
run;

 

PeterClemmensen
Tourmaline | Level 20

Ok. You can do something like this

 

data test;
  input name $25.;
  cards;
test (ex)
(ex) test
test test
;
run;

data want;
   set test;
   a=prxchange('s/\(.*\)//', -1, name);
run;
PGStats
Opal | Level 21

Or rather,

 

data test;
  input name $25.;
  cards;
test (ex)
(ex) test
(ex) test (ex)
test test
;

data want;
   set test;
   new_name = prxchange('s/\s*\(.*?\)\s*//', -1, name);
run;
PG
mansour_ib_sas
Pyrite | Level 9

 

To the method I'm trying to applay, I understood where the problem came.

At the scan, I forgot  to add space as a separator.

Now, I can separate the string charcters correctly.

Thank you for you help.

 

data test1;
set test;
i=1;
do while (scan(name,i, " ") ne ' ') ;
    part=scan(name,i,'');
    regex = prxparse('/\(/');
    if prxmatch(regex, part) >0 then output;
    i+1;
end;
run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5 replies
  • 1489 views
  • 2 likes
  • 3 in conversation