Help using Base SAS procedures

Make first letter capital only

Accepted Solution Solved
Reply
Super Contributor
Posts: 409
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,920

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

Re: Make first letter capital only

Posted in reply to Vince28_Statcan

Thank you

Regular Contributor
Posts: 202

Re: Make first letter capital only

Posted in reply to Vince28_Statcan

@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: 202

Re: Make first letter capital only

Posted in reply to Vince28_Statcan

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

Regular Learner
Posts: 1

Re: Make first letter capital only

Acctually, you can use propcase like this to solve your problem

propcase(lowcase(col),'')

 

BUT, you must use it in an SQL

proc sql;
    create table y as
        select namn, propcase(lowcase(namn), '') as PROPCASE
    from x
    ;
quit;

 

propcase works differentially inte proc sql and data step

Occasional Contributor
Posts: 6

Re: Make first letter capital only

Indeed, the solution name=upcase(substr(name,1,1))||lowcase(substr(name,2,0)); is working well but you get a warning. 
If you want all the remaining characters of a string, there is no need to specifiy the number of characters to extract, then the correct syntax is name=upcase(substr(name,1,1))||lowcase(substr(name,2));
Hope it helps! 

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 14460 views
  • 1 like
  • 6 in conversation