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
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));
Check out the PROPCASE function:
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));
Thank you
@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.
<name=upcase(substr(name,1,1))||lowcase(substr(name
What do the "1,1" and the "2,0" represent in this syntax?
Thanks!
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
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!
try this -
data test;
fname="james";
lname="Bond";
name=propcase(catx('',fname,lname),'-');
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.