<?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: Removing last word from string. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279557#M269725</link>
    <description>&lt;P&gt;That only keeps the first and 2nd word, but I want the entire string minus the 2nd word.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jun 2016 20:16:18 GMT</pubDate>
    <dc:creator>tropical_surfer</dc:creator>
    <dc:date>2016-06-22T20:16:18Z</dc:date>
    <item>
      <title>Removing last word from string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279538#M269721</link>
      <description>&lt;P&gt;How can I remove the last word in a string?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 19:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279538#M269721</guid>
      <dc:creator>tropical_surfer</dc:creator>
      <dc:date>2016-06-22T19:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Removing last word from string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279549#M269722</link>
      <description>&lt;P&gt;Good question. This was answered &lt;A href="http://stackoverflow.com/questions/33283714/remove-last-word-from-string-in-sas" target="_self"&gt;on StackOverflow&lt;/A&gt; as well as in &lt;A href="http://mcdc.missouri.edu/sascode/lastword.sas" target="_self"&gt;this code example&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, you can pass -1 in to &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/a002255934.htm" target="_self"&gt;CALL SCAN&lt;/A&gt; to get the last word, and once you've found it, it's trivial to remove.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 20:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279549#M269722</guid>
      <dc:creator>paulkaefer</dc:creator>
      <dc:date>2016-06-22T20:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Removing last word from string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279550#M269723</link>
      <description>&lt;P&gt;Thanks! Any advice on how to remove the second word from a string? I'm trying to check between two variables that excluding the 2nd word both strings are identical.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 20:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279550#M269723</guid>
      <dc:creator>tropical_surfer</dc:creator>
      <dc:date>2016-06-22T20:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Removing last word from string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279553#M269724</link>
      <description>&lt;P&gt;Try the same steps, but using CALL SCAN with a count of 2.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 20:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279553#M269724</guid>
      <dc:creator>paulkaefer</dc:creator>
      <dc:date>2016-06-22T20:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Removing last word from string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279557#M269725</link>
      <description>&lt;P&gt;That only keeps the first and 2nd word, but I want the entire string minus the 2nd word.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 20:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279557#M269725</guid>
      <dc:creator>tropical_surfer</dc:creator>
      <dc:date>2016-06-22T20:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Removing last word from string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279561#M269726</link>
      <description>&lt;P&gt;Oh, I see. Well in the StackOverflow post,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;substr(starting_word,1,pos-2);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is used to return a string that includes all but the last word.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'll probably need this:&lt;/P&gt;&lt;PRE&gt;call scan(original_string, 2, pos, length);&lt;/PRE&gt;&lt;P&gt;to get the length and position of the second word, then&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first_piece = substr(original_string, 1, pos-1)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(maybe pos-2 to remove the space between the words)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;PRE&gt;second_piece = substr(original_string, pos+length, lengthOfString)&lt;/PRE&gt;&lt;P&gt;(you'll have to calculate lengthOfString using the LENGTH function)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then use a CAT function (see &lt;A href="http://www.mwsug.org/proceedings/2013/S1/MWSUG-2013-S108.pdf" target="_self"&gt;here&lt;/A&gt; for a good description of the different choices) to combine first_piece and second_piece.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 20:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-from-string/m-p/279561#M269726</guid>
      <dc:creator>paulkaefer</dc:creator>
      <dc:date>2016-06-22T20:27:43Z</dc:date>
    </item>
  </channel>
</rss>

