BookmarkSubscribeRSS Feed
Wouter
Obsidian | Level 7
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!
3 REPLIES 3
Olivier
Pyrite | Level 9
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
Wouter
Obsidian | Level 7
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!!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1563 views
  • 0 likes
  • 3 in conversation