Help using Base SAS procedures

Delete parts of variables, but how??

Reply
Contributor
Posts: 62

Delete parts of variables, but how??

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!
Super Contributor
Posts: 260

Re: Delete parts of variables, but how??

Hi.
What you can try is check where "debtor" is with the INDEW function, then pick the string beginning after that place with a SUBSTR function.
[pre]
DATA test ;
INFILE CARDS MISSOVER DLM="," ;
INPUT Variable_1 :$50. ;
posDebtor = INDEXW(variable_1, "debtor") ;
afterDebtor = LEFT(SUBSTR(variable_1, posDebtor+LENGTH("debtor"))) ;
CARDS ;
xxx debtor profile 7
x debtor profile 3 to 1
xx x x x x xx debtor profiles 133 to 155
xxxx debtor profile 3
;
RUN ;
[/pre]
Regards.
Olivier
Contributor
Posts: 62

Re: Delete parts of variables, but how??

Thanks, works perfect!! Right now, I don't fully understand the complete code (the statements INDEXW, SUBSTR), but the idea I fully understand. Most of the time, I've got the idea, but lacking the ability to 'convert' it into SAS codes... Right now, I'm going to check the statements. Thanks!!
Super Contributor
Super Contributor
Posts: 3,174

Re: Delete parts of variables, but how??

Consider using the SCAN function in a DATA step to extract / parse your SAS variable. Your delimiter argument can be a something other than a single character, which will work for your circumstances.

Related topic links are provided for your reference - found on the SAS support website. http://support.sas.com/

Scott Barry
SBBWorks, Inc.

SUGI 2007 paper:

http://www2.sas.com/proceedings/forum2007/035-2007.pdf

SAS DOC on SCAN function:

http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a000214639.htm

SAS Support SAMPLES:

ftp://ftp.sas.com/techsup/download/sample/datastep/scanfunction.html
Ask a Question
Discussion stats
  • 3 replies
  • 177 views
  • 0 likes
  • 3 in conversation