hi
Please can you tell me how can i convert the first letter of a sting to uppercase without using procase()
data h;
input name$;
cards;
krishna
jizin
gayathri
madhav
neerav
priya
run;
DATA WANT;
SET HAVE;
NAME2 = UPCASE(SUBSTR(LEFT(NAME),1,1))||SUBSTR(LEFT(NAME),2);
RUN;
DATA WANT;
SET HAVE;
NAME2 = UPCASE(SUBSTR(LEFT(NAME),1,1))||SUBSTR(LEFT(NAME),2);
RUN;
Thanks Scott_Mitchell
Just to note, you can modify a character in place, without have to concatenate data back together again, though you won't notice any time diff without lots of rows ![]()
data x;
attrib res format=$20.;
res="assfsa";
substr(res,1,1)=upcase(substr(res,1,1));
run;
I wonder if using FIRST would make any difference
substr(res,1,1)=upcase(first(res));
Yes, excellent suggestion. A few runs of the below two steps shows first using about 0.08 seconds less than the substr (e.g. 0.23 vs 0.31).
data x;
attrib res format=$20.;
do i=1 to 2000000;
res="assfsa";
substr(res,1,1)=upcase(first(res));
end;
run;
data y;
attrib res format=$20.;
do i=1 to 2000000;
res="assfsa";
substr(res,1,1)=upcase(substr(res,1,1));
end;
run;
Or try this one . You gotta love Peal Regular Expression .
data h;
input name$;
cards;
krishna
jizin
gayathri
madhav
neerav
priya
run;
data _null_;
set h;
name = prxchange("s/(\w+)/\u\L$1/i", -1, name);
put name=;
run;
Xia Keshan
NameHard = upcase(first(Name)) || substr(Name,2,length(Name));
You need to get first letter in caps with upcase and first function
After that with substring function get the last letters with length function.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.