BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
X605191
Fluorite | Level 6

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

  1. the lines from "STOP taking these medications" till right before "START taking these medications"
  2. the lines from "START taking these medications" till right before "CONTINUE taking these medications"
  3. the lines from "CONTINUE taking these medications" till the end of the notes

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. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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;
  

 

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

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;
  

 

X605191
Fluorite | Level 6
After minor modification, I made it work for my project 🙂 Thank you!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 412 views
  • 1 like
  • 2 in conversation