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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Vince28_Statcan
Quartz | Level 8

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

8 REPLIES 8
Vince28_Statcan
Quartz | Level 8

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

podarum
Quartz | Level 8

Thank you

_maldini_
Barite | Level 11

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

_maldini_
Barite | Level 11

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

LtRogers
Calcite | Level 5

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

AudeP
Fluorite | Level 6

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! 

nikhilwagh
Obsidian | Level 7

try this -

data test;
	fname="james";
	lname="Bond";
	name=propcase(catx('',fname,lname),'-');
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 60843 views
  • 7 likes
  • 7 in conversation