- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
I've been working with free text - medical notes - that have been uploaded into a SAS dataset. Below are 2 examples that I've copied and pasted as well as a screenshot of the text within Notepad ++ that shows the Carriage Returns/Line Feeds. The keyword is 'carbapenem' and I've tried, without any luck, to extract only the line in the text that contains the keyword using some Regex code. Ideally, I'd like to pull out only the 1st line in example #1 and the 2nd line in example #2.
I'm looking for any tips or advice on how to pull out the keyword line using Regex or non-Regex code.
"Organism is a confirmed carbapenem.
If infection is present, preferred treatment
is with a fluoroquinolone. "
"COLONY TYPE 2
CARBAPENEM PRODUCER:
RECOMMEND A TREATMENT FOR COMPLICATED UTI OR SYSTEMIC INFECTION"
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I assume that what you have are SAS text variables that contain carriage returns and/or linefeeds. To extract the relevant lines from that, you could try something like this (assuming your initial variable is called TEXT, and the found lines will be in the variable LINE):
data want;
set have;
prxid=prxparse('/[^\r\l]*carbapenem[^\r\l]*/i');
pos=1;
do until(0);
call prxsubstr(prxid,text,pos,len);
if pos=0 then leave;
line=substr(text,pos,len);
output;
pos+length;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
can you post the data in datalines?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Below code should work
data want;
infile "c:\temp\source_text.txt" truncover termstr=crlf;
input line $1000.;
if find(upcase(line),'CARBAPENEM') then output;
run;
proc print data=want;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I assume that what you have are SAS text variables that contain carriage returns and/or linefeeds. To extract the relevant lines from that, you could try something like this (assuming your initial variable is called TEXT, and the found lines will be in the variable LINE):
data want;
set have;
prxid=prxparse('/[^\r\l]*carbapenem[^\r\l]*/i');
pos=1;
do until(0);
call prxsubstr(prxid,text,pos,len);
if pos=0 then leave;
line=substr(text,pos,len);
output;
pos+length;
end;
run;