<?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: Spliting a string with all upper case in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604112#M175095</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this one (not perfect, but 90%)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Var1 $30.;
datalines;
ABCReport
MainUsers
A-ABCTestReport
Overview(ABC)
ABC-I2.5.3
Report+DOS
ABC/DSReport
;
run;

data want;
  set have;
  length Var2 $ 60;
  keep Var1 Var2;

  array letters[60] $ 1 _temporary_;
  array markers[3] $ 1 _temporary_ ('=' '+' '/');

  i = 0;
  do until(letters[i] = " ");
    i+1;
    letters[i] = char(Var1,i);
  end;
  i+(-1);

  do i = 1 to i;
    select;
      when ( ('A' &amp;lt;= letters[i] &amp;lt;= 'Z') and ('A' &amp;lt;= letters[i+1] &amp;lt;= 'Z') )
        do; 
          Var2 = strip(Var2) || letters[i] ;
        end;
      when ( ('a' &amp;lt;= letters[i] &amp;lt;= 'z') and not('a' &amp;lt;= letters[i+1] &amp;lt;= 'z') )
        do; 
          Var2 = strip(Var2) || letters[i] || " " || letters[i+1];
          i + 1;
        end;
      when ( ('A' &amp;lt;= letters[i] &amp;lt;= 'Z') and ('a' &amp;lt;= letters[i+1] &amp;lt;= 'z') )
        do; 
          Var2 = strip(Var2) || " " || letters[i] ||  letters[i+1];
          i + 1;
        end;
      otherwise Var2 = strip(Var2) || letters[i] ; 
    end;
  end;

  do i = 1 to dim(markers);
    Var2 = compbl(tranwrd(Var2, markers[i], " "||markers[i]||' '));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But since collapsing spaces is irreversible function having general solution may not be doable &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Thu, 14 Nov 2019 14:27:37 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2019-11-14T14:27:37Z</dc:date>
    <item>
      <title>Spliting a string with all upper case</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604090#M175088</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;I have a variable i.e. Var1 and want to split it as shown in Want column below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In Var1 all values do not have Spaces between words so need to insert a space inbetween.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data ana_pres.have;&lt;BR /&gt;input Var1 $30.;&lt;BR /&gt;datalines;&lt;BR /&gt;ABCReport&lt;BR /&gt;MainUsers&lt;BR /&gt;A-ABCTestReport&lt;BR /&gt;Overview(ABC)&lt;BR /&gt;ABC-I2.5.3&lt;BR /&gt;Report+DOS&lt;BR /&gt;ABC/DS Report&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="284"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="162"&gt;HAVE&lt;/TD&gt;
&lt;TD width="122"&gt;WANT&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ABCReport&lt;/TD&gt;
&lt;TD&gt;ABC Report&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MainUsers&lt;/TD&gt;
&lt;TD&gt;Main Users&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;A-ABCTestReport&lt;/TD&gt;
&lt;TD&gt;A-ABC Test Report&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Overview(ABC)&lt;/TD&gt;
&lt;TD&gt;Overview (ABC)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ABC-I2.5.3&lt;/TD&gt;
&lt;TD&gt;ABC -I2.5.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Report+DOS&lt;/TD&gt;
&lt;TD&gt;Report + DOS&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ABC/DS Report&lt;/TD&gt;
&lt;TD&gt;ABC / DS Report&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 13:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604090#M175088</guid>
      <dc:creator>Rahul_SAS</dc:creator>
      <dc:date>2019-11-14T13:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a string with all upper case</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604099#M175091</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The purpose of this forum is to give/get technical help regarding the SAS language.&lt;/P&gt;
&lt;P&gt;Here your problem lacks clear specifications. You have to design unambiguous rules&lt;/P&gt;
&lt;P&gt;to decide when and where spaces should be inserted and then, users of this forum&lt;/P&gt;
&lt;P&gt;can help you implement your design in SAS. Your example does not make&lt;/P&gt;
&lt;P&gt;that clear at all.&lt;/P&gt;
&lt;P&gt;For instance, why "Overview"&amp;nbsp; gives "Overview"and not "O verview" ?&lt;/P&gt;
&lt;P&gt;Why "ABCReport" gives "ABC Report" and not "ABCR eport" ?&lt;/P&gt;
&lt;P&gt;What should be done with non alphabetical characters surroundig uppercase&lt;/P&gt;
&lt;P&gt;strings : "Overview(ABC)" gives "Overview( ABC )" or "Overview (ABC) " ?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 13:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604099#M175091</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-11-14T13:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a string with all upper case</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604106#M175093</link>
      <description>&lt;P&gt;This probably calls for PRX:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Var1 $30.;
datalines;
ABCReport
MainUsers
A-ABCTestReport
Overview(ABC)
ABC-I2.5.3
Report+DOS
ABC/DS Report
;
run;

data want;
  set have;
  prxid1=prxparse('s/([A-Z,a-z])([A-Z][a-z])/$1 $2/');
  prxid2=prxparse('s/([+,\/])/ $1 /');
  prxid3=prxparse('s/\(/ (/');
  call prxchange(prxid1,-1,Var1);
  call prxchange(prxid2,-1,Var1);
  call prxchange(prxid3,-1,Var1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first regular expression inserts a space when you have a letter followed by a capital letter, followed by a non-capital letter.&lt;/P&gt;
&lt;P&gt;The second inserts spaces around "+" and "/" (the latter is escaped with a backslash in the search string).&lt;/P&gt;
&lt;P&gt;The third inserts a blank before "(".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I am not sure what to do about the "-", in one case you precede "-" with a blank, in the other case you do not.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 14:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604106#M175093</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-11-14T14:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a string with all upper case</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604112#M175095</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this one (not perfect, but 90%)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Var1 $30.;
datalines;
ABCReport
MainUsers
A-ABCTestReport
Overview(ABC)
ABC-I2.5.3
Report+DOS
ABC/DSReport
;
run;

data want;
  set have;
  length Var2 $ 60;
  keep Var1 Var2;

  array letters[60] $ 1 _temporary_;
  array markers[3] $ 1 _temporary_ ('=' '+' '/');

  i = 0;
  do until(letters[i] = " ");
    i+1;
    letters[i] = char(Var1,i);
  end;
  i+(-1);

  do i = 1 to i;
    select;
      when ( ('A' &amp;lt;= letters[i] &amp;lt;= 'Z') and ('A' &amp;lt;= letters[i+1] &amp;lt;= 'Z') )
        do; 
          Var2 = strip(Var2) || letters[i] ;
        end;
      when ( ('a' &amp;lt;= letters[i] &amp;lt;= 'z') and not('a' &amp;lt;= letters[i+1] &amp;lt;= 'z') )
        do; 
          Var2 = strip(Var2) || letters[i] || " " || letters[i+1];
          i + 1;
        end;
      when ( ('A' &amp;lt;= letters[i] &amp;lt;= 'Z') and ('a' &amp;lt;= letters[i+1] &amp;lt;= 'z') )
        do; 
          Var2 = strip(Var2) || " " || letters[i] ||  letters[i+1];
          i + 1;
        end;
      otherwise Var2 = strip(Var2) || letters[i] ; 
    end;
  end;

  do i = 1 to dim(markers);
    Var2 = compbl(tranwrd(Var2, markers[i], " "||markers[i]||' '));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But since collapsing spaces is irreversible function having general solution may not be doable &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 14:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604112#M175095</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-11-14T14:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a string with all upper case</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604454#M175255</link>
      <description>&lt;P&gt;This could give you a start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Var1 $30.;
datalines;
ABCReport
MainUsers
A-ABCTestReport
Overview(ABC)
ABC-I2.5.3
Report+DOS
ABC/DS Report
;
run;

data want;
 set have;
 want=left(compbl(prxchange('s/([A-Z][a-z]+)/ \1 /',-1,var1)));
 want=left(compbl(prxchange('s/(\W)/ \1 /',-1,want)));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Nov 2019 13:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Spliting-a-string-with-all-upper-case/m-p/604454#M175255</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-15T13:35:03Z</dc:date>
    </item>
  </channel>
</rss>

