How to scan for and delete the ending brackets of a string

Accepted Solution Solved
Reply
Regular Contributor
Posts: 161
Accepted Solution

How to scan for and delete the ending brackets of a string

Ladies and Gentlemen:

May I ask how to get rid of the "(NasdaqGS:ACAS)" at the end of string "American Capital, Ltd. (NasdaqGS:ACAS)"

HAVE:

Alyeska Investment Group, L.P.

Amaranth Advisors LLC

American Capital, Ltd. (NasdaqGS:ACAS)

American Securities

Ampere Capital Management, LP

Ampersand Capital Partners

WANT:

Alyeska Investment Group, L.P.

Amaranth Advisors LLC

American Capital, Ltd.

American Securities

Ampere Capital Management, LP

Ampersand Capital Partners

I tried the following in order to get the string before "(NasdaqGS:ACAS)" but unfortunately the scan function won't take the both of the deliminters at the same time.

want = scan(have, 1,' (');

Thanks -


Accepted Solutions
Solution
‎01-28-2014 10:31 AM
Super User
Posts: 17,745

Re: How to scan for and delete the ending brackets of a string

Does this work:

You can include multiple delimiters within the quotation marks:

want = scan(have, 1,'()');

View solution in original post


All Replies
Solution
‎01-28-2014 10:31 AM
Super User
Posts: 17,745

Re: How to scan for and delete the ending brackets of a string

Does this work:

You can include multiple delimiters within the quotation marks:

want = scan(have, 1,'()');

Regular Contributor
Posts: 180

Re: How to scan for and delete the ending brackets of a string

Try this:

data have;
input line $50.;
cards;
Alyeska Investment Group, L.P.
Amaranth Advisors LLC
American Capital, Ltd. (NasdaqGS:ACAS)
American Securities
Ampere Capital Management, LP
Ampersand Capital Partners
;
run;

data want;
  set have;
  i=index(line,'(');
  if i > 0 then line=substr(line,1,i-1);
  drop i;
run;

Regards,

Super User
Posts: 5,071

Re: How to scan for and delete the ending brackets of a string

That should work fine, as long as there is only one bracketed expression per row, and it should always be removed.  If the situation becomes more complex ... such as don't touch a bracketed expression that occurs in the middle of the text ... it's still do-able but becomes a little harder.  But let's not solve that unless it is necessary.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 563 views
  • 3 likes
  • 4 in conversation