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

I am looking to use prxparse to find homelessness in text. I need to be able to search for phrases like "is currrently homeless," "is homeless," "Homeless: Yes," and "Living situation: Homeless." In the text, the only phrases I want to exclude are phrases like "Homless: No" and "not homeless." Using prxparse, is there a way to search for the words "no" and "homeless" being very close to each other if not directly next to each other, so that I am able to remove them?

1 ACCEPTED SOLUTION

Accepted Solutions
mar0000
Obsidian | Level 7
data notes;
input text;
patient is not homeless
she said that she is currently working and it no longer homeless
he is afraid that he will become homeless
at the end of the month he is going to be homeless
Patient description: Homless? No
;

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
Could you please provide the exact sample data with 'no' as well
Thanks,
Jag
mar0000
Obsidian | Level 7
data notes;
input text;
patient is not homeless
she said that she is currently working and it no longer homeless
he is afraid that he will become homeless
at the end of the month he is going to be homeless
Patient description: Homless? No
;

mklangley
Lapis Lazuli | Level 10

Is this somewhat in the direction you're hoping? The code below uses PRXMATCH to see if each string contains 'homeless' and 'no' within 10 characters of each other. You can modify the gap length, as well as the logic for when that condition is met.

data notes;
    input text $65.;
    cards;
    patient is not homeless
    she said that she is currently working and it no longer homeless
    he is afraid that he will become homeless
    at the end of the month he is going to be homeless
    Patient description: Homless? No
    ;
run;

data want;
   set notes;
   if prxmatch('/(.*)(HOMELESS(.{1,10}?)NO)|(NO(.{1,10}?)HOMELESS)(.*)/', upcase(text))
       then contains_homeless_and_no = 'yes';
   else contains_homeless_and_no = 'no';
run;

Edit: use the input data @mar0000  provided. (Note, the last record has the word "Homless"... Not sure if that typo is intentional, or to be included when looking for "homeless".) 

mar0000
Obsidian | Level 7
This is definitely what I'm looking for. Thank you! (p.s. Homless was a typo on my end)

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
  • 4 replies
  • 507 views
  • 0 likes
  • 3 in conversation