I have a patient data set with "notes" as a string variable. It is pretty long, and the delimiter used in the notes is "¶".
Here is an example.
distress ¶XXX... ¶YYY... ¶STOP taking these medications ¶ ¶ XXX .05mg Tab ¶Commonly known as... ¶ YYY 100mg Cap ¶ ¶START taking these medications ¶ ¶ OOO 5mg tab ¶ .... ¶CONTINUE taking these medications ¶UUU 100mg Cap ¶ ¶
What I need to do is extracting
So I need three columns or rows per patient, but I cannot figure out how to write codes for that. Any advice would be greatly appreciated. Please let me know if anything is unclear. Thank you.
A basic way to do this:
data HAVE;
STR0='distress ¶XXX... ¶YYY... ¶STOP taking these medications ¶ ¶ XXX .05mg Tab ¶Commonly known as... ¶ YYY 100mg Cap ¶ ¶START taking these medications ¶ ¶ OOO 5mg tab ¶ .... ¶CONTINUE taking these medications ¶UUU 100mg Cap ¶ ¶';
POS1=index(STR0, 'STOP taking these medications')+length('STOP taking these medications');
POS2=index(STR0, 'START taking these medications')-1;
STR1=substr(STR0, POS1, POS2-POS1);
POS1=index(STR0, 'START taking these medications')+length('START taking these medications');
POS2=index(STR0, 'CONTINUE taking these medications')-1;
STR2=substr(STR0, POS1, POS2-POS1);
POS1=index(STR0,'CONTINUE taking these medications')+length('CONTINUE taking these medications');
STR3=substr(STR0, POS1 );
run;
A basic way to do this:
data HAVE;
STR0='distress ¶XXX... ¶YYY... ¶STOP taking these medications ¶ ¶ XXX .05mg Tab ¶Commonly known as... ¶ YYY 100mg Cap ¶ ¶START taking these medications ¶ ¶ OOO 5mg tab ¶ .... ¶CONTINUE taking these medications ¶UUU 100mg Cap ¶ ¶';
POS1=index(STR0, 'STOP taking these medications')+length('STOP taking these medications');
POS2=index(STR0, 'START taking these medications')-1;
STR1=substr(STR0, POS1, POS2-POS1);
POS1=index(STR0, 'START taking these medications')+length('START taking these medications');
POS2=index(STR0, 'CONTINUE taking these medications')-1;
STR2=substr(STR0, POS1, POS2-POS1);
POS1=index(STR0,'CONTINUE taking these medications')+length('CONTINUE taking these medications');
STR3=substr(STR0, POS1 );
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.