<?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 Removing abbreviations in firms names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534857#M146818</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of abbreviations, as below,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abbrev;
infile datalines truncover;
input word $50.;
datalines;
AG
BV
CORPORATION
GMBH
INC
LIMITED
LLC
LP
LTD
PJSC
PLC
PTE
PTY
SA
SA/NV
SL
SPA
SRL
COMPANY
V LP
CO
NV
HOLDINGS
HOLDING
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and I also have list of firm names, that has some company names ending with abbreviations of above.&lt;/P&gt;&lt;P&gt;For each name among the firm names, I want to iterate through the dataset 'abbrev' and see if the firm name is ending with the any of the abbreviation. If it does, then simply remove the abbreviation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Feb 2019 14:40:19 GMT</pubDate>
    <dc:creator>jimmychoi</dc:creator>
    <dc:date>2019-02-12T14:40:19Z</dc:date>
    <item>
      <title>Removing abbreviations in firms names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534857#M146818</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of abbreviations, as below,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abbrev;
infile datalines truncover;
input word $50.;
datalines;
AG
BV
CORPORATION
GMBH
INC
LIMITED
LLC
LP
LTD
PJSC
PLC
PTE
PTY
SA
SA/NV
SL
SPA
SRL
COMPANY
V LP
CO
NV
HOLDINGS
HOLDING
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and I also have list of firm names, that has some company names ending with abbreviations of above.&lt;/P&gt;&lt;P&gt;For each name among the firm names, I want to iterate through the dataset 'abbrev' and see if the firm name is ending with the any of the abbreviation. If it does, then simply remove the abbreviation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 14:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534857#M146818</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2019-02-12T14:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Removing abbreviations in firms names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534862#M146820</link>
      <description>&lt;P&gt;Can you post some firm names as data-step using datalines, so that we have something to play with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To be 100% sure: if one of the abbreviations appears in the middle of a company name, the abbreviation is not removed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: I would load the dataset abbrev in a hash-object, defining word as key. The use&lt;/P&gt;
&lt;PRE&gt;word = scan(firm_name, -1);&lt;/PRE&gt;
&lt;P&gt;to get the last word of each name, check if that word is in the hash-object and finally use prxchange to remove the word from the name:&lt;/P&gt;
&lt;PRE&gt;firm_name = prxchange(cats('s/(.*)\W(', word, ')/$1/'), 1, trim(firm_name));&lt;/PRE&gt;
&lt;P&gt;That should not be to much code to write and perform somewhat fast as long as the number of obs in abbrev is not to high.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534862#M146820</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-12T15:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Removing abbreviations in firms names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534866#M146824</link>
      <description>&lt;P&gt;exactly +1 from me&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534866#M146824</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-12T15:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Removing abbreviations in firms names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534893#M146833</link>
      <description>&lt;P&gt;Here's a brute force method that will work if both your datasets are small. Similar but less efficient to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13593"&gt;@Andreas&lt;/a&gt;_Ids 's hash method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 481px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27088i8DAD7529213C7398/image-dimensions/481x180?v=v2" width="481" height="180" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abbrev;
infile datalines truncover;
input word $50.;
datalines;
AG
BV
CORPORATION
GMBH
INC
LIMITED
LLC
LP
LTD
PJSC
PLC
PTE
PTY
SA
SA/NV
SL
SPA
SRL
COMPANY
V LP
CO
NV
HOLDINGS
HOLDING
;
run;

data firms;
infile datalines truncover;
input firm $50.;
firm=strip(firm);
datalines;
SAS AG
GOOGLEBV
not a match
BOSCHINC
my company LIMITED
also not a match
this has 2 abbrevs HOLDING INC
;
run;

*get abbreviations into a macro -assuming that you only have these 24;
*using a ^ as delimeter since some of your abbrevs have spaces;
proc sql noprint;
	select word into :abbrevs separated by '^'
	from abbrev;
quit;
%put &amp;amp;abbrevs;
%let to_loop = %eval(%sysfunc(countc(&amp;amp;abbrevs., "^"))+1);
%put &amp;amp;to_loop;
data final_firms;
	set firms;
	length firm_updated $32.;
	
	match='false';
	i=0;
	*check each firm name against the list of abbreviations;
	do while (match='false' and i &amp;lt; &amp;amp;to_loop);
		i +1; 

		*get current abbreviation and length ;
	    abbrev=scan("&amp;amp;abbrevs", i, "^");
		abbrev_len=(length(abbrev));

		*check for match at end of firm name;
		if strip(upcase(substr(firm, length(firm) - abbrev_len +1))) = strip(upcase(abbrev)) then do;
			firm_updated = substr(firm,1, length(firm) - abbrev_len);
			match='true';
		end;
		else firm_updated=firm;
    end;

	keep firm firm_updated;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Feb 2019 15:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-abbreviations-in-firms-names/m-p/534893#M146833</guid>
      <dc:creator>noling</dc:creator>
      <dc:date>2019-02-12T15:59:36Z</dc:date>
    </item>
  </channel>
</rss>

