Hello,
I just require the First letter in varible value in Uppercase and 2nd letter in variable value should be in lower case, it should continue till the end letter of the variable value.
/********************I have a the data like this *****************/
Data Have;
Input Name $ 30.;
cards;
abcdefhg
ghfedcba
IJKLMNOP
qtunvjrf
FgYhbder
;
/************************The output Should be like below**************/
NAME
AbCdEfGh
GhFeDcBa
IjKlMnOp
QtUnVjRf
FgThBdEr
Please help me on this .
Very interesting question.
I am wondering why you behavior this way ?
Data Have; Input Name $ 30.; cards; abcdefhg ghfedcba IJKLMNOPI qtunvjrf FgYhbder ; run; data want; set have; new=upcase(name); do i=2 to length(name) by 2; substr(new,i,1)=lowcase(substr(new,i,1)); end; drop i; run;
Xia Keshan
look up propcase, that'll do the trick for you. I can't test it now but something like this:
word1 = propcase(word);
Hello,
Data Have;
Input Name $ 30.;
cards;
abcdefhg
ghfedcba
IJKLMNOPI
qtunvjrf
FgYhbder
run;
data want;
length _c $ 30 _a $ 1;
if _n_=1 then
do;
declare hash h(ordered:'Y');
h.definekey('i');
h.definedata('_a');
h.definedone();
call missing(_a);
declare hiter hi('h');
end;
i=1;
set have;
do while(substr(name,i,1) ne ' ');
if mod(i,2) then _a=upcase(substr(strip(name),i,1));
else _a=lowcase(substr(strip(name),i,1));
_rc=h.add();
i=i+1;
end;
do _rc = hi.first() by 0 while (_rc = 0);
_c=strip(_c)||strip(_a);
_rc = hi.next();
end;
h.clear();
keep name _c;
run;
I don't know much about hash, is there a book out there that you prefer? I have "SAS Hash object programming made easy" I've been crazy busy at work so I haven't gone through much but I like it so far. Anything else you'd recommend?
Hello,
Here are some useful links:
https://communities.sas.com/message/180853#180853
If you have the book in electronic format could you please send it to my email address - potosi2345@gmail.com ?
10x
I bought a traditional paperback, not an electronic version. I'll have to look to see if the electronic is included, if so I'll send it your way.
Very interesting question.
I am wondering why you behavior this way ?
Data Have; Input Name $ 30.; cards; abcdefhg ghfedcba IJKLMNOPI qtunvjrf FgYhbder ; run; data want; set have; new=upcase(name); do i=2 to length(name) by 2; substr(new,i,1)=lowcase(substr(new,i,1)); end; drop i; run;
Xia Keshan
Data Have;
Input Name $ 30.;
_name=prxchange('s/(\w)(\w)/\U$1\L$2/i',-1,name);
cards;
abcdefhg
ghfedcba
IJKLMNOP
qtunvjrf
FgYhbder
;
run;
Really today you guys made my life easy.
Thanks Loko, Mark Johnson, Xia Keshan and Slchen for the valueble suggetions and fast response on this discussion.
Your code only work on even length of string .
cards;
abcdefh
ghfedcba
IJKLMNOP
qtunvjrf
FgYhbder
;
run;
You are right, if not even length of string, it should be modified as
Data Have;
Input Name $ 30.;
_name=prxchange('s/(\w)(\w)?/\U$1\L$2/i',-1,name);
cards;
abcdefh
ghfedcba
IJKLMNOP
qtunvjrf
FgYhbde
;
run;
Slightly simplified version:
Data Have;
Input Name $ 30.;
new_name=prxchange('s/(\w\w?)/\u\l$1/i', -1,name);
cards;
abcdefhgf
ghfedcba
IJKLMNOP
qtunvjrf
FgYhbder
;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.