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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: