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;
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;
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?
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;
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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.