Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete parts of variables, but how??

Status
Not open for further replies.

wphupkes

Technical User
Jul 1, 2008
22
NL
Hello,

I've got a dataset in which I want to remain everything after a particular word, like "debtor". Like:

ID | Variable_1
1 xxx debtor profile 7
2 x debtor profile 3 to 1
3 xx debtor profiles 133 to 155
4 xxxx debtor profile 3

So the final result would be:

ID | Variable_1
1 profile 7
2 profile 3 to 1
3 profiles 133 to 155
4 profile 3

In other words, I need a statement with which I could delete everything to the left of a particular word. Anyone any idea? Thanks in advance!
 
Hi

You could use a combination of index and substr

Code:
    variable_1 = substr(variable_1,index(variable_1,'debtor'));

HTH
 
THanks!

The only thing is, when there's no "debtor" stated in the records, SAS responds with the error(s): "NOTE: Invalid second argument to function SUBSTR at line 235 column 14.". While I get a list of multiple errors (ending by " Limit set by ERRORS= option reached. Further errors of this type will not be printed."), everything works well! So I've got to surpress the error statements, but that wouldn't be too hard.

Problem solved!
 
You can conditionally execute to solve the problem:

Code:
loc = index(variable_1, 'debtor');
if loc then variable_1 = substr(variable_1,loc);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top