<?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: How to remove last word of a string in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489021#M9946</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Obs Product $50.;
infile datalines dlm=',';
datalines;
1,Product A 1835
2,Product B 201
3,Product A 35
4,Product B 4893
;

data want(drop=pos length);
   set have;
   call scan(Product, -1, pos, length);
   Product_Fam=substr(Product,1,pos-2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Aug 2018 19:39:12 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-08-22T19:39:12Z</dc:date>
    <item>
      <title>How to remove last word of a string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489017#M9943</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem that I think should be simple but cannot quite get it to work. I need to remove the last word in a string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Product A 1835&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Product B 201&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Product A 35&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Product B 4893&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Product_Fam&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Product A 1835&lt;/TD&gt;&lt;TD&gt;Product A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Product B 201&lt;/TD&gt;&lt;TD&gt;Product B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Product A 35&lt;/TD&gt;&lt;TD&gt;Product A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Product B 4893&lt;/TD&gt;&lt;TD&gt;Product B&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there a simple way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489017#M9943</guid>
      <dc:creator>huffa9299</dc:creator>
      <dc:date>2018-08-22T19:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last word of a string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489018#M9944</link>
      <description>&lt;P&gt;Is it always numbers at the end?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, can you apply the COMPRESS() function to the variable to remove the numbers?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;productID = compress(product, , 'ka');
Number = compress(product, , 'kd');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489018#M9944</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-22T19:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last word of a string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489019#M9945</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;product = substr(product,1,length(product)-length(scan(product,-1,' ')));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489019#M9945</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-22T19:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last word of a string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489021#M9946</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Obs Product $50.;
infile datalines dlm=',';
datalines;
1,Product A 1835
2,Product B 201
3,Product A 35
4,Product B 4893
;

data want(drop=pos length);
   set have;
   call scan(Product, -1, pos, length);
   Product_Fam=substr(Product,1,pos-2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489021#M9946</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-08-22T19:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last word of a string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489022#M9947</link>
      <description>&lt;P&gt;Thank you Reeza and Draycut, both worked well, thank you for help!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489022#M9947</guid>
      <dc:creator>huffa9299</dc:creator>
      <dc:date>2018-08-22T19:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last word of a string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489041#M9948</link>
      <description>&lt;P&gt;Just for fun:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Obs Product $50.;
infile datalines dlm=',';
datalines;
1,Product A 1835
2,Product B 201
3,Product A 35
4,Product B 4893
;

data want;
set have;
Product_Fam=substr(Product,1,length(product)-anyspace(reverse(strip(product))));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 20:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489041#M9948</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-22T20:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last word of a string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489048#M9949</link>
      <description>&lt;P&gt;And another:&lt;/P&gt;
&lt;PRE&gt;data have;
input Obs Product $50.;
infile datalines dlm=',';
datalines;
1,Product A 1835
2,Product B 201
3,Product A 35
4,Product B 4893
;
data want;
set have;
Product_Fam=strip(tranwrd(product,scan(Product,-1),''));
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 20:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489048#M9949</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-22T20:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last word of a string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489233#M9950</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Obs Product $50.;
infile datalines dlm=',';
datalines;
1,Product A 1835
2,Product B 201
3,Product A 35
4,Product B 4893
;

data want;
 set have;
 want=prxchange('s/\w+$//',1,strip(Product));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Aug 2018 12:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-remove-last-word-of-a-string/m-p/489233#M9950</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-23T12:42:59Z</dc:date>
    </item>
  </channel>
</rss>

