Is there a way to use lookbehind for a few possible letters as a whole? In the example below, I need ABC, DEF, GHI be found as a whole (ABCDE is ok), but seems like it was taken as each letter. I tried (ABC|DEF|GHI), it’s not working, one word is working. Any suggestions?
data a;
var='ABC 1.89 DEF A YELLOW LINES'; output;
var='ABC 1.89 YELLOW JKLM LINE'; output;
var='9 GHI YELLOW LINE'; output;
var='9 H BLK LINE'; output;
var='9 BC JT GREEN LINE'; output;
run;
data b;
set a;
retain re1;
if _N_=1 then do;
re1 = prxparse('/(?<=[ABC|DEF|GHI] )(YELLOW|BLK|GREEN)(?=\s*LI)/');
end;
if prxmatch(re1,var) then do;
var2 = prxposn(re1,0,var);
end;
run;
proc print data=b; run;
1 | ABC 1.89 DEF A YELLOW LINES | 1 | YELLOW |
2 | ABC 1.89 YELLOW JKLM LINE | 1 |
|
3 | 9 GHI YELLOW LINE | 1 | YELLOW |
4 | 9 H BLK LINE | 1 | BLK |
5 | 9 BC JT GREEN LINE | 1 |
|
I think you need () instead of []
prxparse('/(?<=(ABC|DEF|GHI) )(YELLOW|BLK|GREEN)(?=\s*LI)/')
Please provide details on what you mean by "not working"? What was your expected output?
For example if I have “re1 = prxparse('/(?<=ABC).*(\bYELLOW|BLK|GREEN\b)(?=\s*LI)/');” in code, so ‘YELLOW’ in “ABC 1.89 DEF A YELLOW LINES” will be captured, but I need to list more possible words, like GHI, so YELLOW in “9 GHI YELLOW LINE”’ can be captured too.
I think you need () instead of []
prxparse('/(?<=(ABC|DEF|GHI) )(YELLOW|BLK|GREEN)(?=\s*LI)/')
gergely! you are right. I thought I tried that, got error earlier, I must have added an extra closed parenthesis. Thank you!
Hi, is there a way to look around, either ahead or behind, for example, as long as ABC or GHI is in the string, before or after (\bYELLOW|BLK|GREEN\b) return the color?
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.