BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lindseyj79
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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

4 REPLIES 4
HB
Barite | Level 11 HB
Barite | Level 11

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  
lindseyj79
Calcite | Level 5

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
s_lassen
Meteorite | Level 14

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".

lindseyj79
Calcite | Level 5

BINGO!  thank you so much!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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