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?
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
;
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
;
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".)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.