- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Check out the PROPCASE function:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
<name=upcase(substr(name,1,1))||lowcase(substr(name
What do the "1,1" and the "2,0" represent in this syntax?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
try this -
data test;
fname="james";
lname="Bond";
name=propcase(catx('',fname,lname),'-');
run;