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 --<-----

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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