BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PGStats
Opal | Level 21

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

PG
data_null__
Jade | Level 19

That's the "correct answer".

PGStats
Opal | Level 21

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

PG
jakarman
Barite | Level 11

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

---->-- ja karman --<-----

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 18 replies
  • 11765 views
  • 14 likes
  • 8 in conversation