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

     I have data that includes the name of a town in parenthesis.  I want to get rid of what's in the parenthesis.  Is there a way to do this in SAS...or does it need to be done outside of SAS?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
arodriguez
Lapis Lazuli | Level 10

I will select the first word separated by "(" character with an scan function in the datastep

newvar=SCAN(var,1,'(');

View solution in original post

5 REPLIES 5
stat_sas
Ammonite | Level 13

Please show some sample data.

ballardw
Super User

One approach, inside a data step is to include code similar to

Variable = substr(variable, 1,(index(variable,'(')-1));

mkd
Calcite | Level 5 mkd
Calcite | Level 5

This was very useful and did what I needed.  Thank you for answering, however, I found the SCAN function much easier to use and most likely easier for me to remember in the future.

arodriguez
Lapis Lazuli | Level 10

I will select the first word separated by "(" character with an scan function in the datastep

newvar=SCAN(var,1,'(');

user24feb
Barite | Level 11

Depending on your actual data, this might work (kicks out ( and ) without replacement):

Data A;

  Ex="xxxcd(1dfd32)"; Output;

  Ex="gegewx1d (322)"; Output;

Run;

Data B;

  Set A;

  Ex_new=PRXChange("s/[\(\)]//",-1,Ex);

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
  • 5 replies
  • 973 views
  • 3 likes
  • 5 in conversation