<?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: substr for the last occurrence of a blank space in a string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/628044#M185507</link>
    <description>&lt;P&gt;It is easy to find the value after the last space&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;scan(name,-1,' ')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have that you can figure out how many characters to chop off.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;susbtrn(name,1,length(name)-length(scan(name,-1,' '))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But what do want to do when there are no embedded spaces?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name='LONDON';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want an empty string?&amp;nbsp; Or do you want to remove nothing?&lt;/P&gt;</description>
    <pubDate>Thu, 27 Feb 2020 20:50:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-27T20:50:07Z</dc:date>
    <item>
      <title>substr for the last occurrence of a blank space in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/627995#M185487</link>
      <description>&lt;P&gt;Hi folks.&amp;nbsp; I'm looking for a method to create a variable of the string up until the last blank space in the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;nm1 =&amp;nbsp; 'SAN ANTONIO CA';&lt;/P&gt;
&lt;P&gt;nm2 =&amp;nbsp;&amp;nbsp;'NEW SAN ANTONIO CA'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for nm1 I'd want to return only 'SAN ANTONIO'&lt;/P&gt;
&lt;P&gt;So for nm2 I'd want to return only 'NEW SAN ANTONIO'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any thoughts on how to do this?&amp;nbsp; Basically the requirement is to return everything prior to the final blank space in the string? But the under of blank spaces may vary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 17:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/627995#M185487</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2020-02-27T17:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: substr for the last occurrence of a blank space in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/627997#M185488</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79805"&gt;@buechler66&lt;/a&gt;&amp;nbsp; Please see if this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length nm $50;
nm =  'SAN ANTONIO CA';
output;
nm =  'NEW SAN ANTONIO CA';
output;
run;

data want;
 set have;
 length want $30;
 want=substr(nm,1,findc(trim(nm),' ','b')-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or something fancy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; want=prxchange('s/(.*)\s.+$/$1/',-1, trim(nm));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 18:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/627997#M185488</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-27T18:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: substr for the last occurrence of a blank space in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/628002#M185490</link>
      <description>&lt;P&gt;I appreciate you taking the time to help.&amp;nbsp; Greatly!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 18:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/628002#M185490</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2020-02-27T18:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: substr for the last occurrence of a blank space in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/628044#M185507</link>
      <description>&lt;P&gt;It is easy to find the value after the last space&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;scan(name,-1,' ')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have that you can figure out how many characters to chop off.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;susbtrn(name,1,length(name)-length(scan(name,-1,' '))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But what do want to do when there are no embedded spaces?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name='LONDON';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want an empty string?&amp;nbsp; Or do you want to remove nothing?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 20:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/628044#M185507</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-27T20:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: substr for the last occurrence of a blank space in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/628046#M185508</link>
      <description>Ty for posting this. I appreciate ur time.</description>
      <pubDate>Thu, 27 Feb 2020 21:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/substr-for-the-last-occurrence-of-a-blank-space-in-a-string/m-p/628046#M185508</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2020-02-27T21:02:22Z</dc:date>
    </item>
  </channel>
</rss>

