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

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)

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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

SASPhile
Quartz | Level 8
Specific variable , say variable "fieldid"
PeterClemmensen
Tourmaline | Level 20

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;
Patrick
Opal | Level 21

@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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 550 views
  • 2 likes
  • 3 in conversation