Help using Base SAS procedures

SAS perl question - lookbehind

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

SAS perl question - lookbehind

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


Accepted Solutions
Solution
‎12-30-2014 04:12 PM
SAS Employee
Posts: 340

Re: SAS perl question - lookbehind

Posted in reply to allaboutsas

I think you need () instead of []

prxparse('/(?<=(ABC|DEF|GHI) )(YELLOW|BLK|GREEN)(?=\s*LI)/')

View solution in original post


All Replies
Super User
Posts: 11,343

Re: SAS perl question - lookbehind

Posted in reply to allaboutsas

Please provide details on what you mean by "not working"? What was your expected output?

Contributor
Posts: 40

Re: SAS perl question - lookbehind

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 LINESwill be captured, but I need to list more possible words, like GHI, so YELLOW in 9 GHI YELLOW LINE”’ can be captured too.

Solution
‎12-30-2014 04:12 PM
SAS Employee
Posts: 340

Re: SAS perl question - lookbehind

Posted in reply to allaboutsas

I think you need () instead of []

prxparse('/(?<=(ABC|DEF|GHI) )(YELLOW|BLK|GREEN)(?=\s*LI)/')

Contributor
Posts: 40

Re: SAS perl question - lookbehind

Posted in reply to gergely_batho

gergely! you are right. I thought I tried that, got error earlier, I must have added an extra closed parenthesis. Thank you!

Contributor
Posts: 40

Re: SAS perl question - lookbehind

Posted in reply to allaboutsas

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?

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 217 views
  • 0 likes
  • 3 in conversation