I'd appreciate some advice regarding selective upcase.
Consider the following string:
"Some examples are Sas, Fbi, Cia, Fda, and Nsa."
Is there a practical way of saying "when the string contains ('Sas', 'Fbi', 'Cia', etc.) then those should be upcase?
I can always treat each individual case using the case function w/multiple when-then, but I'd rather put everything that should be upcase within a set of paranthesis, as above. If possible...
Thanks for your time.
Yes, though I don't use formats. As mentioned, first step would be to create the dataset of the pairs, e.g.
VAL1 VAL2
Bank 1 Asa Bank 1 ASA
Bank 2 Asa Bank 2 ASA
Then from that dataset you can do:
data _null_;
set codelist end=last;
if _n_=1 then call execute('data want; set have;');
call execute('if myvalue="'||strip(val1)||'" then newvalue="'||strip(val2)||"';');
if last then call execute('run;');
run;
Note, you could alo do the above by merging as well. Its really a case of knowing what to change, i.e. what logic rules, up front, rather than a method of coding it.
Well, if you can put some logic rules on it then possibly. For instance, will they always be three letters? I doubt you can put logic on it though, as what your talking about is anachronisms which aren't part of a basic language formula, but a made up thing by companies or such like. For instance, Sas, could relate to SAS Software, the SAS (military), Scandanavian Air Services etc. depending on context. Cia could be a shortening of Cioa in Italian etc.
So without a logical rule, you would need to supply a list of them yourself. Maybe create a dataset with the ones you know, and a decode. Then you can update that separately from your code. E.g.
proc sql;
create table WANT as
select A.*,
(select LONG_VAL from CODELIST where SHORT_VAL=A.SHORT_VAL) as LONG_VAL
from HAVE;
quit;
Dataset:
Short_Val Long_val
fbi FBI
sas SAS
...
Thanks for the feedback. Here's a little more background:
We have a list of bank names, and they're all in upcase. We need them in propcase. However, there's a few 'shared terms' that should always be upcase, such as for example 'ASA'.
Basically I want to avoid writing this for each of those terms and banks:
case
when 'Bank 1 Asa' then 'Bank 1 ASA'
when 'Bank 2 Asa' then 'Bank 2 ASA'
when 'Bank 3 Asa' then 'Bank 3 ASA'
when 'Bank 4 Asa' then 'Bank 4 ASA'
end
I could of course use tranwrd(bankname, 'Asa', 'ASA'), but is there a way to use it multiple times, for 5-6 different terms, within the same expression? In example 'As' should always be 'AS', and 'Sb' should always be 'SB' - and only as long as they're individual words, not part of other words ('Asatru Asa' should not become 'ASAtru ASA', but 'Asatru ASA', to use a random fictive example).
Yes, though I don't use formats. As mentioned, first step would be to create the dataset of the pairs, e.g.
VAL1 VAL2
Bank 1 Asa Bank 1 ASA
Bank 2 Asa Bank 2 ASA
Then from that dataset you can do:
data _null_;
set codelist end=last;
if _n_=1 then call execute('data want; set have;');
call execute('if myvalue="'||strip(val1)||'" then newvalue="'||strip(val2)||"';');
if last then call execute('run;');
run;
Note, you could alo do the above by merging as well. Its really a case of knowing what to change, i.e. what logic rules, up front, rather than a method of coding it.
you can use proc format for this.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.