Hi guys,
I have special names which contain parentheses. I like to remove the whole parentheses expression.
What I have is this:
166/666-C-122 PP3(ZIAN)
199/999-H-888 ZZZ(PLING)
Z-12(AAAAAAA)
Z-2T (NILGON)
And what I need is this:
166/666-C-122 PP3
199/999-H-888 ZZZ
Z-12
Z-2T
Can you please help me with it?
Please note the space inside the names. Thank you!
Best regards
Farshid
data have;
input string :$&100.;
datalines;
166/666-C-122 PP3(ZIAN)
199/999-H-888 ZZZ(PLING)
Z-12(AAAAAAA)
Z-2T (NILGON)
;
data want;
set have;
newstring=prxchange('s/\(.*\)//', -1, string);
run;
Result:
string newstring 166/666-C-122 PP3(ZIAN) 166/666-C-122 PP3 199/999-H-888 ZZZ(PLING) 199/999-H-888 ZZZ Z-12(AAAAAAA) Z-12 Z-2T (NILGON) Z-2T
Assuming the word in parenthesis is at the end of the character expression, you can try this code:
data want;
set have;
var2 = trim(substr(var1, 1, index(var1,"(")-1));
run;
Or maybe even something shorter:
data want;
set have;
var2 = scan(var1, 1, "(");
run;
All the best
Bart
data have;
input string :$&100.;
datalines;
166/666-C-122 PP3(ZIAN)
199/999-H-888 ZZZ(PLING)
Z-12(AAAAAAA)
Z-2T (NILGON)
;
data want;
set have;
newstring=prxchange('s/\(.*\)//', -1, string);
run;
Result:
string newstring 166/666-C-122 PP3(ZIAN) 166/666-C-122 PP3 199/999-H-888 ZZZ(PLING) 199/999-H-888 ZZZ Z-12(AAAAAAA) Z-12 Z-2T (NILGON) Z-2T
If you have such kind of data, you will get wrong result.
data have;
infile cards truncover;
input string $100.;
datalines;
166/666-C-(122) PP3(ZIAN)
199/999-H-(888) ZZZ(PLING)
Z-12(AAAAAAA)
Z-2T (NILGON)XXXX
;
data want;
set have;
newstring=prxchange('s/\(.*?\)//', -1, string);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.