<?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: Extra a sentence in a string that has a specific word in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348244#M273383</link>
    <description>&lt;P&gt;I have not more&amp;nbsp;than 10 occurrances in the string and I would like to have them all under one charecter variable instead of one per each occurance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;say if the input variable &lt;EM&gt;comment&lt;/EM&gt; has "The worst &lt;STRONG&gt;experience&lt;/STRONG&gt; I've ever had with them, especially after being with them for over a decade.I will not be recommending this gym and I will be contacting corporate as well as the Better Business Bureau.&lt;BR /&gt;I hope my &lt;STRONG&gt;experience&lt;/STRONG&gt; can be of help."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output variable &lt;EM&gt;extract&lt;/EM&gt; should have "&lt;SPAN&gt;he worst &lt;STRONG&gt;experience&lt;/STRONG&gt; I've ever had with them, especially after being with them for over a decade.I hope my &lt;STRONG&gt;experience&lt;/STRONG&gt; can be of help."&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2017 18:06:56 GMT</pubDate>
    <dc:creator>Bhuvaneswari</dc:creator>
    <dc:date>2017-04-07T18:06:56Z</dc:date>
    <item>
      <title>Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348198#M273378</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for help in extracting a sentence from a string (this is a charecter variable in sas), that has a specific word.&lt;/P&gt;&lt;P&gt;Say I'm looking for a word experience in a review and wanted to extract only the sentences that used the word 'experience' in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input: Variable named&amp;nbsp;&lt;EM&gt;comment&lt;/EM&gt; has text "&lt;SPAN&gt;The worst &lt;STRONG&gt;experience&lt;/STRONG&gt; I've ever had with them, especially after being with them for over a decade.I will not be recommending this gym and I will be contacting corporate as well as the Better Business Bureau."&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output: Variable named&amp;nbsp;&lt;EM&gt;extract&lt;/EM&gt; with sentence "&lt;SPAN&gt;The worst &lt;STRONG&gt;experience&lt;/STRONG&gt; I've ever had with them, especially after being with them for over a decade" containing the word experience.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Kindly help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Bhuvana&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 16:37:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348198#M273378</guid>
      <dc:creator>Bhuvaneswari</dc:creator>
      <dc:date>2017-04-07T16:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348204#M273379</link>
      <description>&lt;P&gt;Here's one approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   comment ="The worst experience I've ever had with them, especially after being with them for over a decade.I will not be recommending this gym and I will be contacting corporate as well as the Better Business Bureau." ;
   length extract sentence $200.;
   do i = 1 to countw(comment,'.');
      sentence = scan(comment,i,'.');
      if findw( sentence,'experience',' .,/','i')&amp;gt;0 then do;
         extract= catt(sentence,'.') ;
         output;
      end;
   end;
   drop sentence i;
run;&lt;/PRE&gt;
&lt;P&gt;You do not specify what to do if the target word occurs in two or more sentences. The above loop would create a separate record for each sentence found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you think that that you have other "sentence" delimiters such as ; involved add them to the SCAN function.&lt;/P&gt;
&lt;P&gt;The catt is to put the period back into the sentence that SCAN will remove.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 16:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348204#M273379</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-07T16:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348210#M273380</link>
      <description>&lt;P&gt;Thanks for quick help. Have a good weekend!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 17:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348210#M273380</guid>
      <dc:creator>Bhuvaneswari</dc:creator>
      <dc:date>2017-04-07T17:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348227#M273381</link>
      <description>&lt;P&gt;I have another request, how can put all such sentences in one record say I want to append those sentences in the outputted variable extract intead of having one record per each sentence.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 17:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348227#M273381</guid>
      <dc:creator>Bhuvaneswari</dc:creator>
      <dc:date>2017-04-07T17:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348236#M273382</link>
      <description>&lt;P&gt;Here is modified example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   comment ="The worst experience I've ever had with them. The worst service in a decade. Because of this experience I will not be recommending this gym." ;
   length extract sentence $200.;
   do i = 1 to countw(comment,'.');
      sentence = scan(comment,i,'.');
      if findw( sentence,'experience',' .,/','i')&amp;gt;0 then do;
         extract= catx(' ',extract,catt(sentence,'.')) ;

      end;
   end;
   drop sentence i;
run;&lt;/PRE&gt;
&lt;P&gt;Note that I did change the original comment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Length assignment for Extract in this case should likely be the length of the comment variable in practice.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 18:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348236#M273382</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-07T18:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348244#M273383</link>
      <description>&lt;P&gt;I have not more&amp;nbsp;than 10 occurrances in the string and I would like to have them all under one charecter variable instead of one per each occurance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;say if the input variable &lt;EM&gt;comment&lt;/EM&gt; has "The worst &lt;STRONG&gt;experience&lt;/STRONG&gt; I've ever had with them, especially after being with them for over a decade.I will not be recommending this gym and I will be contacting corporate as well as the Better Business Bureau.&lt;BR /&gt;I hope my &lt;STRONG&gt;experience&lt;/STRONG&gt; can be of help."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output variable &lt;EM&gt;extract&lt;/EM&gt; should have "&lt;SPAN&gt;he worst &lt;STRONG&gt;experience&lt;/STRONG&gt; I've ever had with them, especially after being with them for over a decade.I hope my &lt;STRONG&gt;experience&lt;/STRONG&gt; can be of help."&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 18:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348244#M273383</guid>
      <dc:creator>Bhuvaneswari</dc:creator>
      <dc:date>2017-04-07T18:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348251#M273384</link>
      <description>&lt;P&gt;Thanks a lot! That helped!!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 18:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348251#M273384</guid>
      <dc:creator>Bhuvaneswari</dc:creator>
      <dc:date>2017-04-07T18:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348363#M273385</link>
      <description>&lt;P&gt;Hi ballardw,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I experimented a bit witht he code and noticed that if I write something like "very bad experience!", SAS won't output it - but if I omit the exclamation mark from the word "experience" then SAS outputs it. So the code looks for the exact word "experience", but is it possible to make the code such that it will be searching for the presence of a string, even if it is a part of a bigger string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2017 04:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348363#M273385</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-04-08T04:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extra a sentence in a string that has a specific word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348917#M273386</link>
      <description>&lt;P&gt;Delimiter choices, add or remove as needed. I just used periods for the SCAN part, you could add any character you want but make sure it is a "sentence", where sentence is whatever you&amp;nbsp;want for a group of words,&amp;nbsp;delimiter in your data. Note that this approach has a potential more complex problem. "My experience meant I would like to rate it 4.5 but the entry window would not allow that" would require addtional steps to identify if the . in 4.5 is actually a sentence end, or in "For a price of 53.67 the experience was too expensive and I won't return".&amp;nbsp; That sentence would start with "67 the experience ..." Freeform language is rife with other suitable issues. If you see a pattern like digit.digit that might fix some but what about the guy that does $.02 for "two cents worth"? Or an email address?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any text you search for has rules. Pick the appropriate tool. Index, Find, Indexw, FindW, and sometimes prey. If the result quality needs to be high then often you get a human involved or a much better trained AI than I know how to access.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 22:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extra-a-sentence-in-a-string-that-has-a-specific-word/m-p/348917#M273386</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-10T22:48:11Z</dc:date>
    </item>
  </channel>
</rss>

