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
Onyx | Level 15

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 873 views
  • 3 likes
  • 5 in conversation