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;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1103 views
  • 2 likes
  • 3 in conversation