SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vegan_renegade
Obsidian | Level 7

Hi,  I would like to use PRXmatch to exclude the words in the argument rather than the usual include. Is there an option or modifier to do this? 

1 ACCEPTED SOLUTION

Accepted Solutions
vegan_renegade
Obsidian | Level 7

Thanks, just figured it out.  It's as simple as including not in front of prxmatch:

 

if not prxmatch(arguments)

View solution in original post

4 REPLIES 4
maguiremq
SAS Super FREQ

https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf

 

maguiremq_0-1651256583218.png

 

I think this is what you want. Without example data, we can't know what you need.

vegan_renegade
Obsidian | Level 7

I don't have data immediately available but here's my data step as an example:

 

data test1;
set test;
if prxmatch("m/word1|word2|word3/io", variable) > 0; 
run;

 

Instead including word1, word2, and word3 in output, I want to exclude those. 

Just now, I thought that if I include "then delete" after the if statement, it might do what I want.

maguiremq
SAS Super FREQ
data have;
input variable :$25.;
datalines;
word1
word2
word99
whatisaword
wordle
what
;
run;

data want;
	set have;
		if prxmatch("/[^(word1|word2|word3)]/", trim(variable)) > 0;
run;

maguiremq_0-1651258328593.png

But even then, I'm wondering if you have extra whitespace or you could literally just switch the condition (>0). I can't tell without example data.

vegan_renegade
Obsidian | Level 7

Thanks, just figured it out.  It's as simple as including not in front of prxmatch:

 

if not prxmatch(arguments)

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1833 views
  • 0 likes
  • 2 in conversation