<?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 a set of strings from a field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500429#M133280</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, when I try this on my data, I get this error (the structure is the same as yours)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array rmve_strs(*) _temporary_ $ ('LTD','LLC','INC','CORPORATION','COMPANY','LP');
                                            _
                                            22
                                            200
ERROR: The non-variable based array rmve_strs has been defined with zero elements.
ERROR 22-322: Syntax error, expecting one of the following: (, ;.  

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Oct 2018 15:07:32 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2018-10-01T15:07:32Z</dc:date>
    <item>
      <title>Removing a set of strings from a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500245#M133190</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to remove certain strings from company names in my data. That is, I would like to remove things like 'LTD', 'CO', 'INC', 'LLC', etc. I'm also looking to get rid of leading and trailing blanks and punctuation. So, I am able to do this for one use case as you see below. But I don't want to keep writing new lines for each tranwrd as I am unable to put a list of strings in tranwrd. What I'd like to do is have some sort of loop that sends a list of strings through the tranwrd function (applying to the same field - company_name). Like define a list of strings as a macro variable and send that through a loop within a macro or something like that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data MyCompanies;
 set CompanyListing;
 Company_Name=tranwrd(strip(compress(CompanyName,,"p")),"LTD",'');
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 00:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500245#M133190</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2018-10-01T00:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a set of strings from a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500247#M133191</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MYCOMPANIES;
 * set COMPANYLISTING;
 COMPANYNAME='Incredible Company Ltd.';
 COMPANY_NAME=prxchange('s/(\b(LTD|CO|INC|LLC)\b)//i',1,left(compress(COMPANYNAME,,'p')));
 putlog COMPANY_NAME=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;COMPANY_NAME=Incredible Company&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 00:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500247#M133191</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-10-01T00:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a set of strings from a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500254#M133194</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73936"&gt;@JediApprentice&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What I'd like to do is have some sort of loop that sends a list of strings through the tranwrd function (applying to the same field - company_name). Like define a list of strings as a macro variable and send that through a loop within a macro or something like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data MyCompanies;
 set CompanyListing;
 Company_Name=tranwrd(strip(compress(CompanyName,,"p")),"LTD",'');
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You would use an ARRAY, not a macro here. Use a temporary array to store the words you want to remove and then use a loop to remove them. You aren't factoring in variable CaSE&amp;nbsp;though, so you may want to do that as well, eg. ltD, LTD, ltd, Ltd, Limited are all different and TRANWRD will not replace them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mycomp;
set listing;

array _remove(*) _temporary_ $ ('LTD', 'INC', 'CO');

do i=1 to dim(_remove);
company_name = tranwrd(strip(compress(companyName, ,"p")), _remove(i), '');
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Oct 2018 02:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500254#M133194</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-01T02:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a set of strings from a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500260#M133198</link>
      <description>&lt;P&gt;Just like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;said, but&amp;nbsp;taking care of&amp;nbsp;spaces and punctuation. Adjust to your needs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MYCOMPANIES;
 do COMPANYNAME = 'Big Corp., Local Division', 'Incredible Company Ltd.';
 COMPANYNAME=prxchange('s/\s*\b(LTD|CO|INC|LLC|CORP)\b\.?\s*//io', 1, COMPANYNAME);
 putlog COMPANYNAME=;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Oct 2018 03:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500260#M133198</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-10-01T03:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a set of strings from a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500262#M133200</link>
      <description>&lt;P&gt;My understanding is that OP&amp;nbsp;wants&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;I.B.M.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to become&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;IBM&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;Big Corp., Local Division&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to become&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;Big Local Division&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 03:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500262#M133200</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-10-01T03:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a set of strings from a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500429#M133280</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, when I try this on my data, I get this error (the structure is the same as yours)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array rmve_strs(*) _temporary_ $ ('LTD','LLC','INC','CORPORATION','COMPANY','LP');
                                            _
                                            22
                                            200
ERROR: The non-variable based array rmve_strs has been defined with zero elements.
ERROR 22-322: Syntax error, expecting one of the following: (, ;.  

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 15:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500429#M133280</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2018-10-01T15:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a set of strings from a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500431#M133282</link>
      <description>&lt;P&gt;1. It needs a dimension apparently so replace the * with the number of elements&lt;/P&gt;
&lt;P&gt;2. Move the $ before the keyword _TEMPORARY_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73936"&gt;@JediApprentice&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, when I try this on my data, I get this error (the structure is the same as yours)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array rmve_strs(*) _temporary_ $ ('LTD','LLC','INC','CORPORATION','COMPANY','LP');
                                            _
                                            22
                                            200
ERROR: The non-variable based array rmve_strs has been defined with zero elements.
ERROR 22-322: Syntax error, expecting one of the following: (, ;.  

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 15:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500431#M133282</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-01T15:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a set of strings from a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500479#M133297</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;Hmm it runs without errors or warnings but still doesn't seem to be working, not removing those strings. The only thing it removes is the punctuation. In the output it shows the value of i as 7 all the way down, like it's stuck on one iteration outside the dimensions of the array. There is an info message in the log, not sure if it's relevant:&amp;nbsp;Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result. That is for company_name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the current code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set CompanyListing;
  array rmve_strs(6) $ _temporary_ ('LTD','LLC','INC','CORPORATION','COMPANY','LP');
  do i=1 to dim(rmve_strs);
    company_name = tranwrd(strip(compress(CompanyName, ,"p")), rmve_strs(i), '');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Oct 2018 16:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-set-of-strings-from-a-field/m-p/500479#M133297</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2018-10-01T16:54:08Z</dc:date>
    </item>
  </channel>
</rss>

