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: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 325 views
  • 1 like
  • 2 in conversation