DATA Step, Macro, Functions and more

remove text inside brackets including brackets

Accepted Solution Solved
Reply
Super Contributor
Posts: 713
Accepted Solution

remove text inside brackets including brackets

raw data

abc(123)
(123)abc(pqr)

 

 

How to remove text inside brackets including brackets so the final data is below:
final data
abc
abc


Accepted Solutions
Solution
Thursday
PROC Star
Posts: 8,164

Re: remove text inside brackets including brackets

The following should work:

data raw;
  informat text $80.;
  input text &;
  cards;
abc(123)
(123)abc(pqr)
;

data want;
  set raw;
  want = prxchange('s/\(([^\)]+)\)//i', -1, text);
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
Thursday
PROC Star
Posts: 8,164

Re: remove text inside brackets including brackets

The following should work:

data raw;
  informat text $80.;
  input text &;
  cards;
abc(123)
(123)abc(pqr)
;

data want;
  set raw;
  want = prxchange('s/\(([^\)]+)\)//i', -1, text);
run;

Art, CEO, AnalystFinder.com

 

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 60 views
  • 1 like
  • 2 in conversation