12-13-2017 10:47 AM
I have run the code (please see below)
data have; input = "CRH PLC TO BID FOR PPC LTD"; run; data want; set have; temp=input; p=prxmatch('/\b(TO BID)\b/i',temp); do while(p); temp=substr(temp,p); temp=substr(temp,findc(temp,' ')+1); Buy=catx(' ',scan(temp,1,' '),scan(temp,2,' '),scan(temp,3,' '),scan(temp,4,' ')); p=prxmatch('/\b(TO BID)\b/i',temp); end; drop temp p; run;
which uses an anchor word "TO BID" and brings back exactly the data I require after the anchor which is "BID FOR PPC LTD"
Do you happen to know how I can reverse this and take words before the anchor word "TO BID" ? I am wanting to obtain the text "CRH PLC TO BID"
12-13-2017 11:24 PM
How far back do you want to go?
This may help:
data WANT; STR = "CRH PLC TO BID FOR PPC LTD"; WANT = prxchange('s/(.*)\bTO BID\b.*/$1/i',1,STR); put WANT=; run;
Also look at the prxsubstr() function.
12-14-2017 03:44 AM
Thanks for your reply. So if I wanted to go back and retrieve "
"CRH PLC TO BID"
"BID FOR PPC LTD"
how would I tweak the code? It's a function that I have never used before. I'll need to do some reading up around the subject.
12-14-2017 06:01 PM - edited 12-14-2017 06:01 PM
Need further help from the community? Please ask a new question.