<?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: Finding first and second word of the last line in a text in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560128#M10430</link>
    <description>&lt;P&gt;So what is your desired outcome of row 2 and 4 here?&lt;/P&gt;</description>
    <pubDate>Mon, 20 May 2019 13:34:57 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-05-20T13:34:57Z</dc:date>
    <item>
      <title>Finding first and second word of the last line in a text</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560125#M10428</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to ask you how to find first and second word ( string) in a row of text ? and use a rule if the first word is the only one in row ( there is no other text after that word ?)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have found this code , but it's only of first and last text., thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;options pageno=1 nodate ls=80 ps=64;

data firstlast;
   input String $60.;
   First_Word = scan(string, 1);
   Last_Word = scan(string, -1);
   datalines4;
Jack and Jill
&amp;amp; Bob &amp;amp; Carol &amp;amp; Ted &amp;amp; Alice &amp;amp;
Leonardo
! $ % &amp;amp; ( ) * + , - . / ;
;;;;

proc print data=firstlast;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 13:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560125#M10428</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2019-05-20T13:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first and second word of the last line in a text</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560128#M10430</link>
      <description>&lt;P&gt;So what is your desired outcome of row 2 and 4 here?&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 13:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560128#M10430</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-20T13:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first and second word of the last line in a text</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560146#M10431</link>
      <description>&lt;P&gt;Hi, Thank you for your message,&lt;BR /&gt;this code was just an example.&lt;BR /&gt;&lt;BR /&gt;I would like to check for thsi text:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;text text text text end of line of this text
&lt;STRONG&gt;some other text&lt;/STRONG&gt; &lt;FONT color="#FF0000"&gt;and here we are&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;if the text '&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;some other text'&lt;/STRONG&gt;&lt;/CODE&gt; is the last text at the end of the last row I want to assign a value to a variable, else if there is text '&lt;CODE class=" language-sas"&gt;&lt;FONT color="#FF0000"&gt;and here we are'&amp;nbsp;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;then i want to assign another value to the variable ( without using regular expressions)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 14:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560146#M10431</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2019-05-20T14:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first and second word of the last line in a text</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560277#M10444</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250627"&gt;@SIgnificatif&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, Thank you for your message,&lt;BR /&gt;this code was just an example.&lt;BR /&gt;&lt;BR /&gt;I would like to check for thsi text:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;text text text text end of line of this text
&lt;STRONG&gt;some other text&lt;/STRONG&gt; &lt;FONT color="#ff0000"&gt;and here we are&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if the text '&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;some other text'&lt;/STRONG&gt;&lt;/CODE&gt; is the last text at the end of the last row I want to assign a value to a variable, else if there is text '&lt;CODE class=" language-sas"&gt;&lt;FONT color="#ff0000"&gt;and here we are'&amp;nbsp;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;FONT color="#ff0000"&gt;&lt;FONT color="#000000"&gt;then i want to assign another value to the variable ( &lt;STRONG&gt;&lt;FONT color="#800080"&gt;without using regular expressions&lt;/FONT&gt;&lt;/STRONG&gt;)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you arbitrarily limit possible solutions, such as your "without using regular expressions" you really need to explain why that is not a valid solution.&lt;/P&gt;
&lt;P&gt;It is similar to saying "I want to subtract one number from another without using the - operator".&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 20:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560277#M10444</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-20T20:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first and second word of the last line in a text</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560436#M10462</link>
      <description>Hi, thank you for the question, the single answer I have is that I found re take more time compared to sas finding stuff, I agree that they may seem ( or really are ) more intuitive ..., if there is no other way, then maybe I'll use the re.</description>
      <pubDate>Tue, 21 May 2019 10:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560436#M10462</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2019-05-21T10:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first and second word of the last line in a text</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560641#M10480</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250627"&gt;@SIgnificatif&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi, thank you for the question, the single answer I have is that I found re take more time compared to sas finding stuff, I agree that they may seem ( or really are ) more intuitive ..., if there is no other way, then maybe I'll use the re.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We seem to also have a moving target as to what you want. You started with first and second "word" but have wandered quite a ways from that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please read the documentation for the SCAN function to see what a "word" is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if the text '&lt;CODE class="  language-sas"&gt;some other text'&lt;/CODE&gt; is referring to a phrase and Scan would be inappropriate unless you have some specific delimiter between chunks of text&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use several functions to search for strings inside other text. INDEX and FIND come to mind. If a value of the index function is greater than zero the text was found. Since you are now playing with something besides a single word you could use the length of the "word" you are searching for along with the length of the string to see if it is the last of a line of text.&lt;/P&gt;
&lt;P&gt;You may need to consider what you mean by a match as far as capitalization or presence of punctuation though.&lt;/P&gt;
&lt;P&gt;Consider&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines truncover;
   input phrase $ 1-50 ;
   target='a phrase';
   last = ( (find(phrase,target,-50) + length(target) -1) = length(phrase) );
   last2 = ( (find(phrase,target,-50,'i') + length(target) -1) = length(phrase) );
datalines;
This is a phrase
This is a different phrase
a phrase at the begining
THIS IS A PHRASE
;
&lt;/PRE&gt;
&lt;P&gt;A value of 1 for last or last2 means that the phrase was found at the "end" of the string. Notice that the difference between the two is the capitalization of "A PHRASE" and how the Find function modifier 'i' ignores case. You may potentially want to look at the T modifier&lt;/P&gt;
&lt;P&gt;The -50 uses the length of the string as the start position and then the negative says to search backwards from that position.&lt;/P&gt;
&lt;P&gt;If your search bit includes leading or trailing blanks. The FINDW function has some additional options to consider.&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2019 20:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-first-and-second-word-of-the-last-line-in-a-text/m-p/560641#M10480</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-21T20:11:38Z</dc:date>
    </item>
  </channel>
</rss>

