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

I am trying to find observations that contain one word in a string but NOT another.

For example, my observations look something like this:

Diabetes mellitus

Screening for diabetes mellitus

Type II diabetes 

History of diabetes

Family history of type II diabetes

Encounter for screening of diabetes mellitus

 

I want to return observations that contain 'diabetes' or 'Diabetes' but NOT 'Screening' 'screening' 'History' 'history'

I tried what I thought the most intuitive way to do this would be:

proc freq data=data;

tables diagnosis;

where find(diagnosis, 'diabetes') or find(diagnosis, 'Diabetes') and not find(diagnosis, 'History') or find(diagnosis, 'screening');

run;

but obviously, this did not work and returned observations that DO contain History and Screening, ignoring the 'not.' Is the find function the best way to do this? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    if find(diagnosis,'diabetes','i')>0 and find(diagnosis,'history','i')=0 and find(diagnosis,'screening','i')=0;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
    set have;
    if find(diagnosis,'diabetes','i')>0 and find(diagnosis,'history','i')=0 and find(diagnosis,'screening','i')=0;
run;
--
Paige Miller
shughe5
Calcite | Level 5
Awesome, thank you.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 343 views
  • 1 like
  • 2 in conversation