Hi,
I need to capitalize the first letter of the word if there is a dash. So in image above, 'Construction -industrial' should be 'Construction - Industrial'.
Here is my code:
Concatenate(UpCase(Substring('Industry_Desc'n, 1, 1)),
LowerCase(Substring('Industry_Desc'n, 2, 1000)))
Can someone help?
Thanks!
Please provide more sample data together with desired result via a SAS data step.
It is impossible to code from pictures. So let's use the values you put into your question body instead.
Construction -industrial
Construction - Industrial
So assuming that the hyphen is immediately in front of the character to upcase you could try something like this:
data want;
set have;
loc=-1;
do until(loc=0);
loc=findc(string,'-',loc+2);
if loc then substr(string,loc+1,1)=upcase(char(string,loc+1));
end;
run;
Which is almost exactly like the first example in the FINDC() documentation.
Not hard to adjust to skip over spaces after the hyphen.
data want;
set have;
loc=0;
do until(loc=0);
loc=findc(string,'-',loc+1);
if loc then loc=findc(string,'- ',loc+1,'k');
if loc then substr(string,loc,1)=upcase(char(string,loc));
end;
run;
If below doesn't return what you're after then please provide representative sample data that shows have and want.
data have;
infile datalines truncover dsd dlm=',';
input have_str:$60. want_str:$60.;
datalines;
Construction - industrial sector ,Construction - Industrial sector
Construction - INDUSTRIAL sector ,Construction - INDUSTRIAL sector
Industrial construction ltd ,Industrial construction ltd
;
run;
data want;
set have;
length derived_string $60;
derived_string=prxchange('s/(- *)([a-z])/$1\u$2/', -1, trim(have_str));
run;
proc print data=want;
run;
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!