Nobody mentioned pattern matching? Impress your friends at DM with:
data _null_;
str = "capitalize this";
Cstr = prxchange("s/^(.)/\u\1/o", 1, str);
put Cstr;
run;
PG
That's the "correct answer".
Beware of solutions that do not work with accented characters. Compare :
data _null_;
retain MATCHstr RANKstr UPCASEstr PROPCASEstr "évariste Galois";
MATCHstr = prxchange("s/^(.)/\u\1/o",1,MATCHstr);
if rank(substr(RANKstr,1,1)) in (97:122) then
substr(RANKstr,1,1)=byte(rank(substr(RANKstr,1,1))-32);
substr(UPCASEstr,1,1) = UPCASE(substr(UPCASEstr,1,1));
substr(PROPCASEstr,1,1) = PROPCASE(substr(PROPCASEstr,1,1));
put _ALL_ ;
run;
MATCHstr=Évariste Galois RANKstr=évariste Galois UPCASEstr=Évariste Galois
PROPCASEstr=Évariste Galois _ERROR_=0 _N_=1
PG
An beware of the assumption of 1-byte = 1 character it is something many people learned and thinking it is true.
We are living in the age of Unicode (UTF-8) word excel html are using that. Just old dinosaurusses are forgetting this.
If you like to dig into that area of I18N see:
SAS(R) 9.4 National Language Support (NLS): Reference Guide, Second Edition
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.