<?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 with length 1 or 2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859124#M339457</link>
    <description>&lt;P&gt;In below code the RegEx for want1 just removes the last term, the RegEx for want2 only removes the last term if it has 1 or 2 characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  infile datalines truncover;
  input have $80.;
  length want1 want2 $80;
  want1=prxchange('s/\b\w+$//',1,strip(have));
  want2=prxchange('s/\b\w{1,2}$//',1,strip(have));
  datalines;
EXPERTS INTERNATIONAL RECRUITMENT S 
LOOTAH BUILDING CONSTRUCTION LL
LOOTAH BUILDING CONSTRUCTION LLS
;
proc print data=sample;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1676533747616.png" style="width: 664px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80455iA2271AAC494FA1F1/image-dimensions/664x83?v=v2" width="664" height="83" role="button" title="Patrick_0-1676533747616.png" alt="Patrick_0-1676533747616.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Feb 2023 07:49:18 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-02-16T07:49:18Z</dc:date>
    <item>
      <title>Removing last word with length 1 or 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859115#M339453</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a string and I want to remove last word with length one or two.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example 1: Input: EXPERTS INTERNATIONAL RECRUITMENT S --------Output:&amp;nbsp;EXPERTS INTERNATIONAL RECRUITMENT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example 2: Input:&amp;nbsp;LOOTAH BUILDING CONSTRUCTION LL -----------Output:&amp;nbsp;LOOTAH BUILDING CONSTRUCTION&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 05:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859115#M339453</guid>
      <dc:creator>madhustats</dc:creator>
      <dc:date>2023-02-16T05:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Removing last word with length 1 or 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859120#M339455</link>
      <description>&lt;P&gt;If the last word is longer than two chars it should not be removed, right?&lt;/P&gt;
&lt;P&gt;Are words separated by blanks only?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If both assumptions are true, then i would use:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;b = findc(trim(string), ' ', 'b') to find the position of the last blank&lt;/LI&gt;
&lt;LI&gt;calculate the difference between b and the length of the string,&lt;/LI&gt;
&lt;LI&gt;if the result is smaller than 3: substr to extract anything before b&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 16 Feb 2023 06:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859120#M339455</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-02-16T06:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Removing last word with length 1 or 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859124#M339457</link>
      <description>&lt;P&gt;In below code the RegEx for want1 just removes the last term, the RegEx for want2 only removes the last term if it has 1 or 2 characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  infile datalines truncover;
  input have $80.;
  length want1 want2 $80;
  want1=prxchange('s/\b\w+$//',1,strip(have));
  want2=prxchange('s/\b\w{1,2}$//',1,strip(have));
  datalines;
EXPERTS INTERNATIONAL RECRUITMENT S 
LOOTAH BUILDING CONSTRUCTION LL
LOOTAH BUILDING CONSTRUCTION LLS
;
proc print data=sample;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1676533747616.png" style="width: 664px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80455iA2271AAC494FA1F1/image-dimensions/664x83?v=v2" width="664" height="83" role="button" title="Patrick_0-1676533747616.png" alt="Patrick_0-1676533747616.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 07:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859124#M339457</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-02-16T07:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Removing last word with length 1 or 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859142#M339465</link>
      <description>&lt;P&gt;You could simply scan the last word by space, and check if length is 1 or 2:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  str="abc ert werty we";
  if lengthn(scan(str,-1," ")) in (1,2) then check=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Feb 2023 08:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-last-word-with-length-1-or-2/m-p/859142#M339465</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2023-02-16T08:57:39Z</dc:date>
    </item>
  </channel>
</rss>

