<?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: Reading Text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309570#M66645</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;, you would have to use something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sentence = coalescec(scan(text ,-1, '.?!' ), scan(text ,-2, '.?!' ));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but you would still miss the last punctuation character.&lt;/P&gt;</description>
    <pubDate>Sun, 06 Nov 2016 05:03:31 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-11-06T05:03:31Z</dc:date>
    <item>
      <title>Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309522#M66619</link>
      <description>&lt;P&gt;i want to read the&amp;nbsp;last sentence&amp;nbsp;in a long text having length 350 .it can be separated&amp;nbsp;by marks, or ! or ? or period. I don't want to use &amp;nbsp;No leading blanks be there. &amp;nbsp; I don't&amp;nbsp;know how to develop a code for this .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2016 17:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309522#M66619</guid>
      <dc:creator>afs</dc:creator>
      <dc:date>2016-11-05T17:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309530#M66623</link>
      <description>&lt;P&gt;You can use either SCAN() or regular expression matching. Here is how to do the later:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input text $char350.;
datalines;
i want to read the last sentence in a long text having length 350 .it can be separated by marks, or ! or ? or period. I don't want to use  No leading blanks be there.   I don't know how to develop a code for this .
;

data lastSentence;
set have;
length sentence $350;
if not prx then prx + prxParse("/[^.?!]*[.?!]/");
start = 1;
stop=length(text);
call prxNext(prx, start, stop, text, pos, len);
do while(pos&amp;gt;0);
    sentence = substr(text, pos, len);
    call prxNext(prx, start, stop, text, pos, len);
    end;
keep text sentence;
run;

proc print; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2016 21:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309530#M66623</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-05T21:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309533#M66625</link>
      <description>&lt;P&gt;Function INDEXC enables look &lt;STRONG&gt;forward&lt;/STRONG&gt; for first occurence of a character from a given string characters.&lt;/P&gt;
&lt;P&gt;As I couldn't find similar function to look backwards, I shall use a loop searching the end of a last-previous sentence:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length paragraph $350; &amp;nbsp;/* contains your long string */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do i = length(trim(paragraph)) to 1 by -1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if substr(paragraph,i,1) in ('.' , '!' , '?') &amp;nbsp; &amp;nbsp; &amp;nbsp;/* you may add any other characters you want */&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then leave; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* get out of the loop with i points to end of last_previous sentence */&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;last_sentence = substr(paragraph, i+1,&amp;nbsp;&lt;SPAN&gt;length(trim(paragraph)) - i );&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2016 21:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309533#M66625</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-05T21:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309553#M66631</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You can search from right to left with findc()&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#n1mdh2gvd5potjn14jipysvzn4o7.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#n1mdh2gvd5potjn14jipysvzn4o7.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2016 00:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309553#M66631</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-06T00:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309557#M66634</link>
      <description>It worked -Thanks But the result is showing both the text and the sentence..Is it possible just to see the result ?</description>
      <pubDate>Sun, 06 Nov 2016 02:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309557#M66634</guid>
      <dc:creator>afs</dc:creator>
      <dc:date>2016-11-06T02:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309558#M66635</link>
      <description>Dear Patrick-Thanks - I will study the link</description>
      <pubDate>Sun, 06 Nov 2016 02:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309558#M66635</guid>
      <dc:creator>afs</dc:creator>
      <dc:date>2016-11-06T02:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309559#M66636</link>
      <description>&lt;P&gt;&lt;STRONG&gt;keep sentence;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;keep text sentence;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2016 02:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309559#M66636</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-06T02:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309562#M66639</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick﻿&lt;/a&gt;, I have skiped the right modifier reading the FINDC documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this function shorts the code into:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;STRONG&gt; &amp;nbsp;i = findc(paragraph , '.?!' , B);&lt;/STRONG&gt; &amp;nbsp; /*&lt;STRONG&gt; B&lt;/STRONG&gt; modifies to search Backwards */&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;sentence = substr(paragraph, i+1,&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;length(trim(paragraph)) - i );&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;put sentence=; &amp;nbsp; &amp;nbsp;/* write the sentence to the log */&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2016 02:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309562#M66639</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-06T02:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309568#M66644</link>
      <description>&lt;P&gt;Can't use scan() ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; want = scan(paragraph ,-1, '.?!' );   &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Nov 2016 04:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309568#M66644</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-06T04:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309570#M66645</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;, you would have to use something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sentence = coalescec(scan(text ,-1, '.?!' ), scan(text ,-2, '.?!' ));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but you would still miss the last punctuation character.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2016 05:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309570#M66645</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-06T05:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309580#M66653</link>
      <description>&lt;P&gt;As &lt;STRONG&gt;any&lt;/STRONG&gt; of the functions: INDEXC , FINDC, SCAN - &lt;STRONG&gt;will miss&lt;/STRONG&gt; the delimiter character (. ? ! )&lt;/P&gt;
&lt;P&gt;then maybe a slight change to the loop code will do the work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do i = length(trim(paragraph)) &lt;STRONG&gt;- 1&lt;/STRONG&gt; to 1 by -1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if substr(paragraph,i,1) in ('.' , '!' , '?') &amp;nbsp; &amp;nbsp; &amp;nbsp;/* you may add any other characters you want */&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then leave; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* get out of the loop with i points to end of last_previous sentence */&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;last_sentence = substr(paragraph, i+1,&amp;nbsp;&lt;SPAN&gt;length(trim(paragraph)) - i );&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2016 06:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309580#M66653</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-06T06:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309608#M66674</link>
      <description>&lt;P&gt;Same, but slightly improved and better tested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input text $char350.;
datalines;
i want to read the last sentence in a long text having length 350 .it can be separated by marks, or ! or ? or period. I don't want to use  No leading blanks be there.   I don't know how to develop a code for this .
First sentence. Last sentence with missing punctuation
First sentence!!! Last sentence, with emphatic punctuation ?!

First sentence is also the last.
;

data lastSentence;
set have;
length sentence $350;
if not prx then prx + prxParse("/[^.?!]+([.?!]+|$)/");
start = 1;
stop = length(text);
call prxNext(prx, start, stop, text, pos, len);
do while(pos&amp;gt;0);
    sentence = left(substr(text, pos, len));
    call prxNext(prx, start, stop, text, pos, len);
    end;
keep sentence;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Nov 2016 18:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Text/m-p/309608#M66674</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-06T18:53:06Z</dc:date>
    </item>
  </channel>
</rss>

