Help using Base SAS procedures

Make first letter capital only

Accepted Solution Solved
Reply
Super Contributor
Posts: 395
Accepted Solution

Make first letter capital only

Hi,  how do I go about making the values form a field capital for the first letter and then lower case for the rest ?  Thanks

HAVE:

Name

BOB

Fred

jim

WANT:

Name

Bob

Fred

Jim


Accepted Solutions
Solution
‎08-01-2013 04:01 PM
Super Contributor
Posts: 339

Re: Make first letter capital only

data want;

     set have;

     name=propcase(name);

run;

This would actually change PAUL-Karl to Paul-Karl etc. with any delimiter specified in the propcase function documentation. If you really only want the very first letter of a string regardless of what the string contains to be upcased and everything else lowcased, you can do

name=upcase(substr(name,1,1))||lowcase(substr(name,2,0));

View solution in original post


All Replies
Super User
Posts: 3,108

Re: Make first letter capital only

Solution
‎08-01-2013 04:01 PM
Super Contributor
Posts: 339

Re: Make first letter capital only

data want;

     set have;

     name=propcase(name);

run;

This would actually change PAUL-Karl to Paul-Karl etc. with any delimiter specified in the propcase function documentation. If you really only want the very first letter of a string regardless of what the string contains to be upcased and everything else lowcased, you can do

name=upcase(substr(name,1,1))||lowcase(substr(name,2,0));

Super Contributor
Posts: 395

Re: Make first letter capital only

Thank you

Regular Contributor
Posts: 199

Re: Make first letter capital only

@Vince28_Statcan I'm just trying to capitalize the first letter of the first word in a string. I'm using your suggested code. It works, but I'm getting the following warning. Any suggestions? Thanks!

 

316 QWB4a_NOSCORE=upcase(substr(QWB4a_NOSCORE,1,1))||lowcase(substr(QWB4a_NOSCORE,2,0));
317 QWB4b_NOSCORE=upcase(substr(QWB4b_NOSCORE,1,1))||lowcase(substr(QWB4b_NOSCORE,2,0));
318
319 DROP
320 QWB7D_1QWB7D_2QWB7D_3;
321 RUN;

NOTE: Invalid third argument to function SUBSTR at line 316 column 59.
NOTE: Invalid third argument to function SUBSTR at line 317 column 59.

Regular Contributor
Posts: 199

Re: Make first letter capital only

@Vince28_Statcan

 

<name=upcase(substr(name,1,1))||lowcase(substr(name,2,0))>

 

What do the "1,1" and the "2,0" represent in this syntax? 

 

Thanks!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 8331 views
  • 0 likes
  • 4 in conversation