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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.