Intentional truncation of data

Accepted Solution Solved
Reply
New Contributor mkd
New Contributor
Posts: 4
Accepted Solution

Intentional truncation of data

     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.


Accepted Solutions
Solution
‎10-28-2014 07:02 AM
Frequent Contributor
Posts: 144

Re: Intentional truncation of data

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


All Replies
Trusted Advisor
Posts: 1,204

Re: Intentional truncation of data

Please show some sample data.

Super User
Posts: 10,516

Re: Intentional truncation of data

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

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

New Contributor mkd
New Contributor
Posts: 4

Re: Intentional truncation of data

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.

Solution
‎10-28-2014 07:02 AM
Frequent Contributor
Posts: 144

Re: Intentional truncation of data

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

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

Super Contributor
Posts: 336

Re: Intentional truncation of data

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;

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 313 views
  • 3 likes
  • 5 in conversation