<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I subtract certain parts of a string value using text rather than positions? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723530#M224529</link>
    <description>&lt;P&gt;Thank you, Amir!&lt;/P&gt;&lt;P&gt;Just what I wanted&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 17:32:12 GMT</pubDate>
    <dc:creator>Pili1100</dc:creator>
    <dc:date>2021-03-04T17:32:12Z</dc:date>
    <item>
      <title>How do I subtract certain parts of a string value using text rather than positions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723471#M224509</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA WORK.A;&lt;BR /&gt;LENGTH Name $10 Note_from_Agent $150;&lt;BR /&gt;INFILE DATALINES DELIMITER =','; &lt;BR /&gt;INPUT ID $ Name $ Note_from_Agent $;&lt;BR /&gt;CARDS; &lt;BR /&gt;1,Jessica, Carthago delenda est Purpose: Happy sad Action: xoxojaodj &lt;BR /&gt;2,Seth,Non ducor duco Purpose: Something Something Action: xoxojaodj&lt;BR /&gt;3,Mort, Vincit qui se vincit Purpose:Tralalala Action: xoxojaodj&lt;BR /&gt;4,Eve,Ad astra per aspera Purpose: Hihih Action: xoxojaodj&lt;BR /&gt;5,Lauretta, Carpe vinum Purpose: Hehehe Action: xoxojaodj&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/PRE&gt;&lt;P&gt;I only want to substract the words from &lt;EM&gt;Purpose&lt;/EM&gt; to word before Action&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eg for Lauretta&lt;STRONG&gt;:&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;Carpe vinum Purpose: Hehehe Action: xoxojaodj&lt;/STRONG&gt; &lt;STRONG&gt;-&amp;gt;&lt;/STRONG&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#993366"&gt;Purpose: Hehehe&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;How do I do it?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 14:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723471#M224509</guid>
      <dc:creator>Pili1100</dc:creator>
      <dc:date>2021-03-04T14:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract certain parts of a string value using text rather than positions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723483#M224516</link>
      <description>&lt;P&gt;Pretty much going to be stuck using a function like Index, Indexw, Find or Findw to find the positions of the key words and use substr function to extract what falls between.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 15:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723483#M224516</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-04T15:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract certain parts of a string value using text rather than positions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723493#M224522</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/363831"&gt;@Pili1100&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for supplying a data step with datalines, that really helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There can be multiple ways of achieving what you want. I have made some assumptions in the solution below (e.g., no extra ":" in the text), so it might not be as robust for all of your needs, but it appears to work for the sample data you have provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   length name $10 note_from_agent $150;
   infile datalines delimiter =','; 
   input id $ name $ note_from_agent $;
   cards; 
1,Jessica, Carthago delenda est Purpose: Happy sad Action: xoxojaodj 
2,Seth,Non ducor duco Purpose: Something Something Action: xoxojaodj
3,Mort, Vincit qui se vincit Purpose:Tralalala Action: xoxojaodj
4,Eve,Ad astra per aspera Purpose: Hihih Action: xoxojaodj
5,Lauretta, Carpe vinum Purpose: Hehehe Action: xoxojaodj
;


data want;
   set have;

   length excerpt $ 100;

   /* take text between colons, then prefix "Purpose:" and remove "Action" */
   excerpt = cats('Purpose:',substr(scan(note_from_agent,2,':'),1,length(scan(note_from_agent,2,':')) - 6));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If this does not do what you want then please explain with more data where this solution does not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 15:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723493#M224522</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-03-04T15:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract certain parts of a string value using text rather than positions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723530#M224529</link>
      <description>&lt;P&gt;Thank you, Amir!&lt;/P&gt;&lt;P&gt;Just what I wanted&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 17:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-subtract-certain-parts-of-a-string-value-using-text/m-p/723530#M224529</guid>
      <dc:creator>Pili1100</dc:creator>
      <dc:date>2021-03-04T17:32:12Z</dc:date>
    </item>
  </channel>
</rss>

