- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I want to create a new variable (ABBR) that forms the abbreviation of another variable containing company names (Company) by selecting the first letters of the words in the name. However, I would like to avoid getting the first character of words like 'the" "for" "in" ...
For example:
THE INTERNATIONAL COMPANY FOR ELECTRICITY SUPPLY --> ICES
REGIONAL COMPANY OF DEVELOPMENT --> RCD
The goal is to match this with company names from another source which might contain only the abbreviation. This will not be flawless but might work on a small percentage of the unmatched cases.
PS: There might be a trick using the PROPCASE function, but as a beginner with SAS I have no idea how to even begin (underneath is how far I got). Probably an alternative option is using SCAN function in a way.
data want;
set have;
UpcaseFirst = Propcase(Company);
Abbr = Anyupper(UpcaseFirst);
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Another way of solving the problem:
data want;
set have;
length
Abbr $ 20
Word $ 100
;
do i = 1 to countw(Company);
Word = scan(Company, i);
if not (trim(Word) in ('OF', 'THE', 'FOR')) then do;
Abbr = cats(Abbr, first(Word));
end;
end;
drop i word;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
to accomplish the same we need to first compress or remove the words which are not part of the acronym like, 'the' 'for' 'of' etc.,
then we need to take the first letter from the remaining words which form the acronym and combine them to form the acronym.
I tried the same in the following code which derives the variable acronym which could be compare with the acronym from another source.
data have;
input text &:$200.;
countw=countw(text);
array cnt(*)$ char1-char100;
do i = 1 to countw;
cnt(i)=first(scan(prxchange('s/the|for|of//i',-1,text),i,''));
end;
acronym=cats(of char1-char100);
cards;
THE INTERNATIONAL COMPANY FOR ELECTRICITY SUPPLY
REGIONAL COMPANY OF DEVELOPMENT
;
run;
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This works partially but can it be that this code also removes a part when a string starts with a "banned" word?
So for example turns:
OFFICIAL COMPANY OF COMPUTERS first to FICIAL COMPANY COMPUTERS to acronym FCC instead of OCC?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Another way of solving the problem:
data want;
set have;
length
Abbr $ 20
Word $ 100
;
do i = 1 to countw(Company);
Word = scan(Company, i);
if not (trim(Word) in ('OF', 'THE', 'FOR')) then do;
Abbr = cats(Abbr, first(Word));
end;
end;
drop i word;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@andreas_ldsI would suggest modifying
Word = scan(Company, i);
/*TO*/
Word = upcase( scan(Company, i) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@DanielLangley wrote:
@andreas_ldsI would suggest modifying
Word = scan(Company, i);/*TO*/ Word = upcase( scan(Company, i) );
Well, of course, good idea.