DATA Step, Macro, Functions and more

capitalize first letter of first word

Accepted Solution Solved
Reply
Regular Contributor
Posts: 196
Accepted Solution

capitalize first letter of first word

I would like to capitalize the first letter of the first word of a string. For example, "abc def" would be "Abc def" and "xyz mno rptd" would be "Xyz mno rptd".

Any ideas?

Thank you.


Accepted Solutions
Solution
‎05-06-2013 05:29 PM
Respected Advisor
Posts: 3,124

Re: capitalize first letter of first word

There is function propcase(), but it will upcase first char of very word in your string. So you may want to try following approach:

data _null_;

  a="abc def";

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

  put a=;

run;

Haikuo

View solution in original post


All Replies
Solution
‎05-06-2013 05:29 PM
Respected Advisor
Posts: 3,124

Re: capitalize first letter of first word

There is function propcase(), but it will upcase first char of very word in your string. So you may want to try following approach:

data _null_;

  a="abc def";

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

  put a=;

run;

Haikuo

PROC Star
Posts: 7,356

Re: capitalize first letter of first word

: Couldn't you just use the substr function?  e.g.:

data have;

  informat text $30.;

  input text &;

  cards;

abc def

xyz mno rptd

;

data want;

  set have;

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

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 1267 views
  • 3 likes
  • 3 in conversation