DATA Step, Macro, Functions and more

PRXMATCH, Regular expression id not changing

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

PRXMATCH, Regular expression id not changing

Hi,

 

Base SAS 9.4 user; 

 

I'm a first time user of prxmatch but I'm having issues getting it to work in my datastep.

 

I have 2 variables set up in a dataset and I want to cross reference all the words in one variable with all the words in the other variable to see if there were any matches.  Here is an example of my code:

 

data xxx ;
   x="Drug: Pimavanserin tartrate (ACP-103)" ;
   y="Drug: pimavanserin tartrate" ;
    output ;
   x="Drug: masitinib" ;
   y="Drug: masitinib (AB1010)" ;
    output ;
run ;

 

What I want now it to see if any of the words in y appear in x, I decided to see if PRXMATCH would work, so I've created a pattern (which hopefully contains all the pearl stuff and the words to match 'm/word1|word2|word3/io')

 

data yyy ;
   set xxx ;

/*create pattern to search for*/
   pattern='m/'||lowcase(translate(compress(strip(scan(y,2,":")),,"adsk"),"|"," "))||'/io' ;
   parse=prxparse(pattern) ;

/*this is my checking criteria... so eventually if z>0 then there is a match with >= 1 of the keywords*/
   z=prxmatch(prxparse(pattern),x) ;
run ;

 

 

What I'm finding is that because the regular expression id (from the prxparse) isn't changing it will only find the first match and then nothing else.

 

Can anyone help?

 

thanks

 

Lindsey


Accepted Solutions
Solution
‎02-05-2018 09:44 AM
PROC Star
Posts: 260

Re: PRXMATCH, Regular expression id not changing

Posted in reply to lindseyj79

The problem is probably that you use the "o" option on your expression, meaning that it will compile only once in the datastep. Try changing "/io" in the end of the expression to just "/i".

View solution in original post


All Replies
Super Contributor
Super Contributor
Posts: 266

Re: PRXMATCH, Regular expression id not changing

Posted in reply to lindseyj79

What would be the values of Z you would want for the following data?

 

x y z
pimavanserin tartrate (ACP-103) pimavanserin tartrate  
masitinib masitinib (AB1010)  
aspirin tablets 100mg aspirin  
calcium tartrate calcium  
calcium tartrate tartrate  
aluminum tartrate tartrate  
doxycycline lexapro  
hydrochlorothiazide oxide oxide   
Ibuprofen tablets 100mg red tab  
one two three four two three  
New Contributor
Posts: 4

Re: PRXMATCH, Regular expression id not changing

I know this is very imperfect but a colleague is finding the minimum matches and I'm finding the maximum so we know the true answer will lie somewhere in between

 

xyz
pimavanserin tartrate (ACP-103)pimavanserin tartrate1
masitinibmasitinib (AB1010)1
aspirin tablets 100mgaspirin1
calcium tartratecalcium1
calcium tartratetartrate1
aluminum tartratetartrate1
doxycyclinelexapro0
hydrochlorothiazide oxideoxide 1
Ibuprofen tablets 100mg redtab0
one two three fourtwo three1
Solution
‎02-05-2018 09:44 AM
PROC Star
Posts: 260

Re: PRXMATCH, Regular expression id not changing

Posted in reply to lindseyj79

The problem is probably that you use the "o" option on your expression, meaning that it will compile only once in the datastep. Try changing "/io" in the end of the expression to just "/i".

New Contributor
Posts: 4

Re: PRXMATCH, Regular expression id not changing

BINGO!  thank you so much!

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 145 views
  • 1 like
  • 3 in conversation