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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Scott_Mitchell
Quartz | Level 8

DATA WANT;

SET HAVE;

NAME2 = UPCASE(SUBSTR(LEFT(NAME),1,1))||SUBSTR(LEFT(NAME),2);

RUN;

View solution in original post

8 REPLIES 8
Scott_Mitchell
Quartz | Level 8

DATA WANT;

SET HAVE;

NAME2 = UPCASE(SUBSTR(LEFT(NAME),1,1))||SUBSTR(LEFT(NAME),2);

RUN;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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 Smiley Happy

data x;

  attrib res format=$20.;

  res="assfsa";

  substr(res,1,1)=upcase(substr(res,1,1));

run;

data_null__
Jade | Level 19

I wonder if using FIRST would make any difference

substr(res,1,1)=upcase(first(res));

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

VISHNU239
Obsidian | Level 7
can anyone please explain me the SUBSTR function in the code?Thank you.
Ksharp
Super User

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

arpi
Fluorite | Level 6

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 6468 views
  • 2 likes
  • 7 in conversation