<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: prxchange how to change the case of specified character in a string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673610#M202680</link>
    <description>&lt;P&gt;Thanks a lot! It will be helpful.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jul 2020 02:39:54 GMT</pubDate>
    <dc:creator>Maplefin</dc:creator>
    <dc:date>2020-07-31T02:39:54Z</dc:date>
    <item>
      <title>prxchange how to change the case of specified character in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673371#M202565</link>
      <description>&lt;P&gt;Hi,I'm recently learning perl regular expression. I wonder how to change the case of single character in strings.I have read SASHELP document, knowing \u,\U,\l,\L can be used to change the case.The example in SASHELP confused me:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   x = 'MCLAUREN';
   x = prxchange("s/(MC)/\u\L$1/i", -1, x);
   put x=;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class="xis-topic"&gt;&lt;DIV class="xis-subTopic"&gt;&lt;DIV class="xis-subSubTopic"&gt;&lt;DIV class="xis-topicContent"&gt;&lt;DIV class="xis-paragraph"&gt;SAS writes the following output to the log:&lt;PRE class="xis-codeFragment"&gt;x=McLAUREN&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;what's the rules under this?Such as "ABC", I want to switch this string into "aBc".How to complete the right perl regular expression?I tried to imitate the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
x="ABC";
y=prxchange("s/(abc)/\l\u\l$1/i",-1,x);
put x= y=;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;but got the wrong result:&lt;/P&gt;&lt;PRE&gt;x=ABC y=aBC&lt;/PRE&gt;&lt;P&gt;So,how to use perl regular expression to get the results I want? In another situation, I want to change "ADAM" into "ADaM".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2020 09:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673371#M202565</guid>
      <dc:creator>Maplefin</dc:creator>
      <dc:date>2020-07-30T09:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: prxchange how to change the case of specified character in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673378#M202571</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329461"&gt;@Maplefin&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The rule in your first example is: If "MC" (&lt;EM&gt;case-insensitive&lt;/EM&gt; due to "&lt;FONT face="courier new,courier"&gt;/i&lt;/FONT&gt;") is found (&lt;EM&gt;anywhere&lt;/EM&gt; due to "&lt;FONT face="courier new,courier"&gt;-1&lt;/FONT&gt;") in &lt;FONT face="courier new,courier"&gt;x&lt;/FONT&gt;, replace it with the lowercase (&lt;FONT face="courier new,courier"&gt;\L&lt;/FONT&gt;)&amp;nbsp; version of it, but with the first character in uppercase (&lt;FONT face="courier new,courier"&gt;\u&lt;/FONT&gt;), i.e., replace it with "Mc".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The rule in your second example is: If "abc" (&lt;EM&gt;case-insensitive&lt;/EM&gt; due to "&lt;FONT face="courier new,courier"&gt;/i&lt;/FONT&gt;") is found (&lt;EM&gt;anywhere&lt;/EM&gt; due to "&lt;FONT face="courier new,courier"&gt;-1&lt;/FONT&gt;") in &lt;FONT face="courier new,courier"&gt;x&lt;/FONT&gt;, replace it with itself, but with the first character in "lowercase -- no, uppercase! -- no, lowercase!!" (&lt;FONT face="courier new,courier"&gt;\l\u\l&lt;/FONT&gt;), i.e., replace the first character with "a" and leave the other two characters unchanged. Of course, the replacement expression&amp;nbsp;&lt;FONT face="courier new,courier"&gt;\l\u\l$1&lt;/FONT&gt; can be simplified to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;\l$1&lt;/FONT&gt;.&amp;nbsp;To obtain the constant result "aBc" I would rather specify the replacement expression explicitly. The same applies to&amp;nbsp;your example "ADaM" where the intention is to correct the possibly misspelled CDISC abbreviation for "Analysis Data Model."&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length x y $10;
input x;
y=prxchange("s/\bADAM\b/ADaM/i",1,x);
put (x y)($10.);
cards;
ADAM
Adam
adam
aDaM
Madam
Adamsky
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(&lt;FONT face="courier new,courier"&gt;\b&lt;/FONT&gt; stands for word boundary).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;ADAM      ADaM
Adam      ADaM
adam      ADaM
aDaM      ADaM
Madam     Madam
Adamsky   Adamsky&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The metacharacters &lt;FONT face="courier new,courier"&gt;\u&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;\U&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;\l&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;\L&lt;/FONT&gt;&amp;nbsp;are particularly useful if there's a &lt;EM&gt;general&lt;/EM&gt; rule like converting names to proper case with special attention to names starting with "Mc":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length x y $15;
input x;
y=prxchange("s/(MC)?([a-z])([a-z]*)/\u\L$1\E\u$2\L$3/i",1,x);
put (x y)($15.);
cards;
MCLAUREN
mcmaster
McCOY
mCpHeRson
Mcx
SMITH
doe
Adamczyk
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Rule: Replace "MC" (case-insentitive), &lt;EM&gt;if any&lt;/EM&gt;&amp;nbsp;(metacharacter "&lt;FONT face="courier new,courier"&gt;?&lt;/FONT&gt;") and if these are the first letters in &lt;FONT face="courier new,courier"&gt;x&lt;/FONT&gt;, with "Mc" (&lt;FONT face="courier new,courier"&gt;\u\L$1\E&lt;/FONT&gt;), the following letter with its uppercase version (&lt;FONT face="courier new,courier"&gt;\u$2&lt;/FONT&gt;) and write the rest in lowercase (&lt;FONT face="courier new,courier"&gt;\L$3&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;MCLAUREN       McLauren
mcmaster       McMaster
McCOY          McCoy
mCpHeRson      McPherson
Mcx            McX
SMITH          Smith
doe            Doe
Adamczyk       Adamczyk&lt;/PRE&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;The same result can be obtained with a simpler expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;y=prxchange("s/(MC)?([a-z]+)/\u\L$1\E\u\L$2/i",1,x);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the impact of the leading "&lt;FONT face="courier new,courier"&gt;\u&lt;/FONT&gt;" in the replacement expression is not limited to the "MC" part: If "MC" is not found (like in "SMITH", "doe", etc.), $1 will be empty and the character to be written in uppercase will be the first character of the remaining expression &lt;FONT face="courier new,courier"&gt;\u$2\L$3&lt;/FONT&gt;&amp;nbsp;(or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;\u\L$2&lt;/FONT&gt; in the simplified version), which is luckily intended to be an uppercase letter anyway. However, if the remaining expression was &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;\L&lt;/STRONG&gt;$2$3&lt;/FONT&gt;&amp;nbsp;(or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;\L&lt;/STRONG&gt;$2&lt;/FONT&gt;) the leading &lt;FONT face="courier new,courier"&gt;\u&lt;/FONT&gt; would override the &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;\L&lt;/FONT&gt;&lt;/STRONG&gt;!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2020 12:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673378#M202571</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-07-30T12:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: prxchange how to change the case of specified character in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673386#M202575</link>
      <description>&lt;PRE&gt;data _null_;
x="ABC ";
y=prxchange("s/(a)(b)(c)/\l$1\u$2\l$3/i",-1,x);
put x= y=;

x="ADAM";
y=prxchange("s/(ad)(a)(m)/\u$1\l$2\u$3/i",-1,x);
put x= y=;

run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jul 2020 11:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673386#M202575</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-07-30T11:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: prxchange how to change the case of specified character in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673610#M202680</link>
      <description>&lt;P&gt;Thanks a lot! It will be helpful.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 02:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-how-to-change-the-case-of-specified-character-in-a/m-p/673610#M202680</guid>
      <dc:creator>Maplefin</dc:creator>
      <dc:date>2020-07-31T02:39:54Z</dc:date>
    </item>
  </channel>
</rss>

