Regex

Accepted Solution Solved
Reply
Super Contributor
Posts: 673
Accepted Solution

Regex

I want to exclude all those records that contain the word "not" before "complete" and that ends with "no" or" na" or 0.

The following doesnt seem to handle the above condition:

^.*(?!.*\bnot\b)(complete(\w)*).*(protocol|therapy|treatment|study)(?!.*\bn(o|a)\b|?!.*\b0\b)

 


Accepted Solutions
Solution
‎09-07-2017 02:23 PM
Respected Advisor
Posts: 4,186

Re: Regex

@SASPhile

It would always really help if you provided sample data via as SAS data step and expected results instead of others expecting to do the work for you. This is imho also about respect for other peoples time and appreciation of their free of charge work for you.

 

Here some code.

data sample;
  infile datalines truncover dlm='|';
  length match_expected_flg match_found_flg 8;
  input match_expected_flg string :$100.;
  match_found_flg= prxmatch('/\bnot\s+complete\b.*(\bna\b|\bno\b|\b0\b)\s*$/oi',string) >0;
  result_as_expected_flg= (match_expected_flg=match_found_flg);
  datalines;
0|dau wd not dnod w complete
0|complete dfoweifj not 0
0|complete fwewe not fwefv
0|dfwefwf efeewfwef fwefwef
0|dnqwo complete not
0|not complete
0|diwq dqw diwhj d no
0|djqwidjq0
0|dwqiojd qwd dqwd na
1|blah not complete blah blah na
1|blah not complete, blah blah no
1|not complete 0
0|not complete 0 or 1
1|blah not   complete   blah no
0|blah not completed blah blah not
;
run;

View solution in original post


All Replies
PROC Star
Posts: 851

Re: Regex

Is this for a specific variable or if any variable in the record contains those values?

Super Contributor
Posts: 673

Re: Regex

Specific variable , say variable "fieldid"
PROC Star
Posts: 851

Re: Regex

[ Edited ]

Something like this then?

 

data have;
input fieldid $100.;
infile datalines truncover;
datalines;
dau wd not dnod w complete
complete dfoweifj not 0
complete fwewe not fwefv
dfwefwf efeewfwef fwefwef
dnqwo complete not
not complete
diwq dqw diwhj d no
djqwidjq0
dwqiojd qwd dqwd na
;

data want;
	set have;
	if find(fieldid, 'not', 'i') and find(fieldid, 'complete', 'i') then do;
		if find(fieldid, 'not', 'i')<find(fieldid, 'complete', 'i') then output;
	end;
	else if scan(fieldid, -1) in ("0", "na", "no") then output;
run;
Solution
‎09-07-2017 02:23 PM
Respected Advisor
Posts: 4,186

Re: Regex

@SASPhile

It would always really help if you provided sample data via as SAS data step and expected results instead of others expecting to do the work for you. This is imho also about respect for other peoples time and appreciation of their free of charge work for you.

 

Here some code.

data sample;
  infile datalines truncover dlm='|';
  length match_expected_flg match_found_flg 8;
  input match_expected_flg string :$100.;
  match_found_flg= prxmatch('/\bnot\s+complete\b.*(\bna\b|\bno\b|\b0\b)\s*$/oi',string) >0;
  result_as_expected_flg= (match_expected_flg=match_found_flg);
  datalines;
0|dau wd not dnod w complete
0|complete dfoweifj not 0
0|complete fwewe not fwefv
0|dfwefwf efeewfwef fwefwef
0|dnqwo complete not
0|not complete
0|diwq dqw diwhj d no
0|djqwidjq0
0|dwqiojd qwd dqwd na
1|blah not complete blah blah na
1|blah not complete, blah blah no
1|not complete 0
0|not complete 0 or 1
1|blah not   complete   blah no
0|blah not completed blah blah not
;
run;
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 141 views
  • 2 likes
  • 3 in conversation