<?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: seperating number and charcter in a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/540017#M148911</link>
    <description>&lt;P&gt;So you don't want split the string when this string only contains one digit ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
str = 'abc def123 ftr kkkg3 a'; output;
str = 'def 123red der5 ffr 45'; output;
run;

data want; 
set have;
	length newstr $80;
    newstr=compbl(prxchange('s/(\d\d+)/ $1 /i',-1,str));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 04 Mar 2019 13:26:57 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-03-04T13:26:57Z</dc:date>
    <item>
      <title>seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539729#M148761</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp; a dataset with values as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;abc def123 ftr kkkg34&lt;/P&gt;&lt;P&gt;def 123red der45 ffr 45&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want here is to seperate number and characte with space delimeter&lt;/P&gt;&lt;P&gt;so my result would be something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;abc def 123 ftr kkkg 34&lt;/P&gt;&lt;P&gt;def 123 red der 45 ffr 45&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rohit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 18:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539729#M148761</guid>
      <dc:creator>Rohit_1990</dc:creator>
      <dc:date>2019-03-01T18:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539741#M148767</link>
      <description>Think regular expression &lt;BR /&gt;Prxchange()</description>
      <pubDate>Fri, 01 Mar 2019 18:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539741#M148767</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2019-03-01T18:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539748#M148772</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261497"&gt;@Rohit_1990&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are probably more elegant ways with prxchange, but this works too:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=str newstr); set have;
	length w1 w2 $20 newstr $60;
	do i = 1 to countw(str);
		w1 = scan(str,i,' ');
		pos1 = prxmatch('/\d\D|\D\d/',trim(w1));
		if pos1 &amp;gt; 1 then w2 = catx(' ',substr(w1,1,pos1),substr(w1,pos1+1));
		else w2 = w1;
		newstr=catx(' ',newstr,w2);
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;newstr=abc def 123 ftr kkkg 34&lt;BR /&gt;newstr=def 123 red der 45 ffr 45&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 19:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539748#M148772</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-03-01T19:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539835#M148826</link>
      <description>Isn't there a trigger to repeat the regex until exhausted?&lt;BR /&gt;That saves the countw() and loop</description>
      <pubDate>Sat, 02 Mar 2019 07:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539835#M148826</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2019-03-02T07:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539846#M148835</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15174"&gt;@Peter_C&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I gave it a try and found a solution with one prxchange to handle the CN boundaries and another to handle the NC boundaries, and it is nicer than the loop-method, I assume that both boundary-types can be handled in the same expression,&amp;nbsp;but I cannot figure out how, and I hope that sombody will supply the final one-liner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is to find both CN and NC-boundaries and also split them in C N or N C to insert a space in the same expression.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	str = 'abc def123 ftr kkkg34 a'; output;
	str = 'def 123red der45 ffr 45'; output;
run;

data want; set have;
	length newstr $80;
    newstr=prxchange('s/\b([A-Z]+)([0-9]+\b\s)/$1 $2/i',-1,str);
    newstr=prxchange('s/\b([0-9]+)([A-Z]+\b\s)/$1 $2/i',-1,newstr);
    put newstr;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;abc def 123 ftr kkkg 34 a&lt;BR /&gt;def 123 red der 45 ffr 45&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2019 10:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539846#M148835</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-03-02T10:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539849#M148837</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	str = 'abc def123 ftr kkkg34 a'; output;
	str = 'def 123red der45 ffr 45'; output;
run;

data want; 
set have;
	length newstr $80;
    newstr=compbl(prxchange('s/(\d+)/ $1 /i',-1,str));
    put newstr;
run;


proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Mar 2019 11:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539849#M148837</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-03-02T11:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539853#M148839</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your answer is perfect just that it fails when alphanumeric string contains single digit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;str = 'abc def123 ftr kkkg3 a'; output;&lt;BR /&gt;str = 'def 123red der5 ffr 45'; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please suggest on above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a ton for your great suggetion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also can you suggest any documents/attchement to explain more on prx function nad Hash programme in sas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anand&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2019 15:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/539853#M148839</guid>
      <dc:creator>Rohit_1990</dc:creator>
      <dc:date>2019-03-02T15:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/540017#M148911</link>
      <description>&lt;P&gt;So you don't want split the string when this string only contains one digit ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
str = 'abc def123 ftr kkkg3 a'; output;
str = 'def 123red der5 ffr 45'; output;
run;

data want; 
set have;
	length newstr $80;
    newstr=compbl(prxchange('s/(\d\d+)/ $1 /i',-1,str));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2019 13:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/540017#M148911</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-03-04T13:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: seperating number and charcter in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/540102#M148943</link>
      <description>Thanks a lot !!!!!</description>
      <pubDate>Mon, 04 Mar 2019 17:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-number-and-charcter-in-a-string/m-p/540102#M148943</guid>
      <dc:creator>Rohit_1990</dc:creator>
      <dc:date>2019-03-04T17:02:00Z</dc:date>
    </item>
  </channel>
</rss>

