- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 .
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
look up propcase, that'll do the trick for you. I can't test it now but something like this:
word1 = propcase(word);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Data Have;
Input Name $ 30.;
_name=prxchange('s/(\w)(\w)/\U$1\L$2/i',-1,name);
cards;
abcdefhg
ghfedcba
IJKLMNOP
qtunvjrf
FgYhbder
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your code only work on even length of string .
cards;
abcdefh
ghfedcba
IJKLMNOP
qtunvjrf
FgYhbder
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;