I've got some code which creates an acronym from a department name:
acronym=propcase(prxchange('s/ for | of the | \& |, cio/ /io',1,FullDepartmentName));
acronym=prxchange('s/[a-z ]+//',-1,acronym);
It's used in a data step and creates a variable called: acronym - which is the shortened version of FullDepartmentName.
For example: FullDepartmentName="Department of the Interior & Toxicology for Cancer" would create a variable acronym='DITC"
With all the quotes, parens, ampersands, etc, how would i turn this into a macro? Something like:
%macro acronym(FullDepartmentName);
%let acronym=;;;
%put('acronym',acronym);
%mend;
Note: I was trying to see how little code i could use to create the acronym. If you think you can do it with less code, I'd like to see it
Wouldn't you use PROC FCMP instead of a macro in this case?
or in 9.3, even a format?
Wow - that would be much easier. is there a format for acronym which takes out the "and", "the", "&" and other irrelevant words??
I think you're looking for acronymns instead of anagrams?
But no, there isn't a format, but you can put a function into a format.
: Not sure if this is exactly what you are looking for, but it may at least be close:
%macro acronym;
acronym=propcase(prxchange('s/ for | of the | \& |, cio/ /io',-1,department));
acronym=prxchange('s/[a-z ]+//',-1,acronym);
%mend acronym;
data have;
informat department $80.;
input department &;
%acronym
cards;
Department of the Interior & Toxicology for Cancer
Office for Something
Statistical Analysis System
;
If case might be an issue then this works:
%macro acronym; |
acronym=prxchange('s/\bof\b|\bthe\b|&|\bfor\b//io',-1,department);
acronym=upcase(compress(prxchange('s/(?<=\b\w{1})\w*//io',-1,acronym),,'s')) ;
%mend ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.