- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-27-2006 08:47 AM
(3792 views)
In Excel there is a proper function, quote from their help:
"Capitalizes the first letter in a text string and any other letters in text that follow any character other than a letter. Converts all other letters to lowercase letters."
There is no equivalent SAS function (I think), but is there is easier way than this?
data _null_;
label='I nEED tO_BE/mAdE PRopeR!';
label=lowcase(label);
z=1;
do i=1 to length(label);
if 97 le rank(substr(label,i,1)) le 122 then y=0;
else y=1;
if z=1 then substr(label,i,1)=upcase(substr (label,i,1));
z=y*1;
end;
put label=;
run;
"Capitalizes the first letter in a text string and any other letters in text that follow any character other than a letter. Converts all other letters to lowercase letters."
There is no equivalent SAS function (I think), but is there is easier way than this?
data _null_;
label='I nEED tO_BE/mAdE PRopeR!';
label=lowcase(label);
z=1;
do i=1 to length(label);
if 97 le rank(substr(label,i,1)) le 122 then y=0;
else y=1;
if z=1 then substr(label,i,1)=upcase(substr (label,i,1));
z=y*1;
end;
put label=;
run;
5 REPLIES 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here is the code that will convert first letter of string to upcase.
/**Macro to convert 1st letter to uppercase**/
%macro UpfirstLetter(Invar);
&Invar.=compbl(lowcase(&Invar.));
length next $ 50;
i=0;
do until(next=' ');
i+1;
next=scan(&Invar.,i," ' '- , . / : ");
pos=index(&Invar.,trim(next));
substr(&Invar.,pos,1)=upcase(substr(&Invar.,pos,1));
end;
%mend UpFirstLetter;
*%UpFirstLetter(name);
/**Macro to convert 1st letter to uppercase**/
%macro UpfirstLetter(Invar);
&Invar.=compbl(lowcase(&Invar.));
length next $ 50;
i=0;
do until(next=' ');
i+1;
next=scan(&Invar.,i," ' '- , . / : ");
pos=index(&Invar.,trim(next));
substr(&Invar.,pos,1)=upcase(substr(&Invar.,pos,1));
end;
%mend UpFirstLetter;
*%UpFirstLetter(name);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to use the propcase function. Syntax:
propcase(var)
This will do what you are trying to do.
propcase(var)
This will do what you are trying to do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Quote Q:
"You need to use the propcase function. Syntax:
propcase(var)
This will do what you are trying to do. "
I am using version 8.2 and there is no such function. Is this a new function in version 9?
"You need to use the propcase function. Syntax:
propcase(var)
This will do what you are trying to do. "
I am using version 8.2 and there is no such function. Is this a new function in version 9?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Propcase() is new in SAS 9. Try the code I posted, should give you what you are looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks snk1!