I want to make sentence case through out my variables.
For ex: in 3 parts of my paper there are remarks. please go through them.
This should become like this
In 3 parts of my paper there are remarks. Please go through them.
How can this be done.
One way to go:
data _null_;
have='in 3 parts of my paper there are remarks. Have you read them? please go through them! then send it back to me.';
want=prxchange('s/(^ *.)|([\.\?!] +.)/\U\1\2\E/oi',-1,have);
put want=;
run;
i do not have any other signs other than .(full stop).
will it still work because i am getting all in upcase after using patricks code
You must have made an error in copying the code. here's my log:
16 data _null_;
17 have='in 3 parts of my paper there are remarks. Have you read them. please go through them. then send it back to me.';
18 want=prxchange('s/(^ *.)|([\.\?!] +.)/\U\1\2\E/oi',-1,have);
19 put want=;
20 run;
want=In 3 parts of my paper there are remarks. Have you read them. Please go through them. Then send it back to me.
Your Perl Regular Expression is more and more better now . Are you working on it for a long time ?
BTW, \1\2\ stand for what ?
Xia Keshan
To refer first and second buffer. Same as using $1$2.
Thanks . And no, didn't take me that long.
Amending this based on 's explanation:
I love the power of regular expressions even though the syntax is "cryptic" and I have still almost always to consult the metacharacter page SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition to get it right.
In real life implementations I don't have that many cases where I use regular expressions - but if I have such a case then using regular expressions makes a difference. Most of the time it's related to data cleansing tasks.
Hello,
Another one:
data _null_;
length y $ 50;
x="in 3 parts of my paper there are remarks. please go through them.";
i+1;
do until(scan(x,i,".") eq "");
y=cats(upcase(substr(left(scan(x,i,".")),1,1)),substr(left(scan(x,i,".")),2));
x=left(tranwrd(x,scan(x,i,"."),cat(" ",strip(y))));
i+1;
put x= ;
end;
run;
unfortunately they are not working
Tried the prxchange solution provided by Patrick, and the output was:
want=In 3 parts of my paper there are remarks. Have you read them? Please go through them! Then send it back to me.
Please explain what does not work.
hello,
what do you mean by "not working" ? the output is:
x=In 3 parts of my paper there are remarks. Please go through them.
Here is another way other than Perl.
data _null_;
have='in 3 parts of my paper there are remarks. Have you read them? please go through them! then send it back to me.';
length want temp punc $ 200;
punc=compress(have,'.?!','k');
do i=1 to countw(have,'.?!') ;
temp=strip(scan(have,i,'.?!')); put temp=;
substr(temp,1,1)=upcase(substr(temp,1,1)) ;
want=cats(want,temp,substr(punc,i,1));
end;
put want=;
run;
Xia Keshan
Here is my PRX.
data _null_;
have='in 3 parts of my paper there are remarks. Have you read them? please go through them! then send it back to me.';
want=prxchange('s/((^\s*\w)|(?<=\.|\?|!)(\s*\w))/\U$1\E/',-1,have);
put want=;
run;
Xia Keshan
Hi all,
I somehow cant get it cracked as for my variable i still get few observations with upcase
ex: SMALL PARTICLES IN THE RESERVOIR, APPEAR TO BE SILICONE PARTICLES
is it because there is no comma or full stop which is not working in this case
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 25. 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.