BookmarkSubscribeRSS Feed
VRD
Calcite | Level 5 VRD
Calcite | Level 5

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.

17 REPLIES 17
Patrick
Opal | Level 21

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;

VRD
Calcite | Level 5 VRD
Calcite | Level 5

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

Kurt_Bremser
Super User

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.

Ksharp
Super User

Patrick

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

Haikuo
Onyx | Level 15

To refer first and second buffer. Same as using $1$2.

Patrick
Opal | Level 21

Thanks . And no, didn't take me that long.

Amending this based on 's explanation:

Hi

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.

Haikuo
Onyx | Level 15

,

Being as same Chinese as  ,   Please allow me to interpret what he really means Smiley Happy:

Are you working on it for a long time ? = Are you using PRX a lot?

Haikuo

Loko
Barite | Level 11

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;

VRD
Calcite | Level 5 VRD
Calcite | Level 5

unfortunately they are not working

andreas_lds
Jade | Level 19

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.

Loko
Barite | Level 11

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.

Ksharp
Super User

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

Ksharp
Super User

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

VRD
Calcite | Level 5 VRD
Calcite | Level 5

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 5530 views
  • 1 like
  • 8 in conversation