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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
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 

View solution in original post

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @farshidowrang 

 

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;
yabwon
Amethyst | Level 16

Or maybe even something shorter:

 

data want;
	set have;
	var2 = scan(var1, 1, "(");
run;

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PeterClemmensen
Tourmaline | Level 20
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 
Ksharp
Super User

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;
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
  • 1908 views
  • 3 likes
  • 5 in conversation