Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

deleting part of the string

deleting part of the string

deleting part of the string


I hope someone could help me with my dilemna... :(
I have a set of table with a field called 'FileName_ID'. This field has sets of values which has no definite length but at the end of each entries are series of 6 numbers enclosed in a parenthesis().
I needed to remove the number groups including the parenthesis(), so I figured to use the RIGHT function to have them all aligned and start counting from the right. Now, what cannot find out is how I can remove those unwanted part of the entries?

FileName_ID: August_ES_AMBP_Default_LeftNews_1_UK_Visa (278414)
The result needed: August_ES_AMBP_Default_LeftNews_1_UK_Visa

Thank you soooo much in advance for all the help :)  

RE: deleting part of the string

Here is my solution, hope this helps.


/* create test dataset */
data have;
input FileName_ID $80.;
August_ES_AMBP_Default_LeftNews_1_UK_Visa (278414)
September_ES_AMBP_Default_LeftNews_1_UK_Visa (278415)
October_ES_AMBP_Default_LeftNews_1_UK_Visa (278416)
November_ES_AMBP_Default_LeftNews_1_UK_Visa (278417)

/* find position of the first ( */
data have;
set have;
pos = index(FileName_ID,'(');

/* substring the field using the position to define the length */
data want;
set have;
NewFileName_ID = substr(FileName_ID, 1, pos-1);


RE: deleting part of the string

ponytails2 Thank you soooo much Dave! This does the trick 2thumbsup

RE: deleting part of the string

Ooooh, I did something like this a while ago to remove strings inside parentheses from the middle of a bigger string.  You obviously don't need this as Dave's method worked for you, but for completeness (and I like showing off my code) here's my method.


        if indexc(some_string,'(') > 0 and indexc(some_string,')') > 0 then
            start = indexc(some_string,'(');
            end = indexc(some_string,')');
            len = length(some_string);
            cut = substr(some_string,start,end-start);
            if len = end then
                remainder = substr(some_string,1,start-1);
                remainder = catt(substr(some_string,1,start-1),(substr(some_string,end+1,len-end)));
The only downside to this is that if there are 2 sets of brackets within the string (either "this ((sort of)) thing" or "this (sort) of (thing)") only the first set brackets get removed.  In the first case you'll be left with


"this ) thing"
and in the second case you'll be left with


"this of (thing)"
Maybe someone else can play with this to make it bullet proof.  I can see a way to do this, using a do loop which keeps iterating throguh removing the pairs of brackets till there's none left, and removing any remaining close brackets at the end.

Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.

RE: deleting part of the string

Just realised there is a line of code missing fromt he end of my code snippet there.
You'll also want


        else remainder = some_string;
otherwise it'll be empty if there's no parentheses in your original text string. :)

Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close