<?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: add space between consecutive code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969030#M376708</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475477"&gt;@ballakaay&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length fac_code $20; /* Declare a length that allows adding spaces */
fac_code='K111I001 C01'; output;
fac_code='A01B001'; output;
run;

data want;
set have;
fac_code=compress(fac_code); /* Remove existing spaces */
RegularExpressionId = prxparse('s/\w\d{2,}/ $0/');
call prxchange(RegularExpressionId, -1, fac_code); /* Insert delimiting space */
fac_code=strip(fac_code);
put fac_code=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 14 Jun 2025 19:21:25 GMT</pubDate>
    <dc:creator>AhmedAl_Attar</dc:creator>
    <dc:date>2025-06-14T19:21:25Z</dc:date>
    <item>
      <title>add space between consecutive code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969016#M376705</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a variable named "fac_code" which contains code delimited by space. However, there are some errors in code where there is no delimiter between code. The code starts with a letter and followed by some digits. I would like to fix it by adding space between codes. For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fac_code&lt;/P&gt;&lt;P&gt;K111I001 C01&lt;/P&gt;&lt;P&gt;A01B001&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want it to be&lt;/P&gt;&lt;P&gt;K111 I001 C01&lt;/P&gt;&lt;P&gt;A01 B001&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did something like&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;set a;&lt;/P&gt;&lt;P&gt;if prxmatch('/[A-Z](\d+)[A-Z](\d+)/)', fac_code)&amp;gt;0 then&lt;/P&gt;&lt;P&gt;fac_code_clean = catx(' ', char(fac_code,2)) but it does not work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated! Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jun 2025 16:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969016#M376705</guid>
      <dc:creator>ballakaay</dc:creator>
      <dc:date>2025-06-14T16:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: add space between consecutive code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969018#M376706</link>
      <description>&lt;P&gt;What is the plain language rule for adding blanks?&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jun 2025 17:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969018#M376706</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-06-14T17:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: add space between consecutive code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969030#M376708</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475477"&gt;@ballakaay&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length fac_code $20; /* Declare a length that allows adding spaces */
fac_code='K111I001 C01'; output;
fac_code='A01B001'; output;
run;

data want;
set have;
fac_code=compress(fac_code); /* Remove existing spaces */
RegularExpressionId = prxparse('s/\w\d{2,}/ $0/');
call prxchange(RegularExpressionId, -1, fac_code); /* Insert delimiting space */
fac_code=strip(fac_code);
put fac_code=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Jun 2025 19:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969030#M376708</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2025-06-14T19:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: add space between consecutive code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969050#M376711</link>
      <description>&lt;PRE&gt;data have;
input x $80.;
cards;
K111I001 C01
A01B001
;

data want;
 set have;
 want=compbl(prxchange('s/([a-z]\d+)/\1 /i',-1,x));
run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Jun 2025 00:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969050#M376711</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-06-15T00:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: add space between consecutive code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969055#M376714</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  CODE='K111I001 C01 '; output;
  CODE='A01B001      '; output;
run;

data WANT;
  set HAVE;
  CODE = prxchange('s/(\d)([A-Z]\d*)/\1 \2/', -1, CODE); 
  putlog CODE=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="sasSource"&gt;CODE=K111 I001 C01&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;CODE=A01 B001&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jun 2025 03:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969055#M376714</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2025-06-15T03:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: add space between consecutive code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969065#M376719</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whilst you have already been provided with a number of solutions, I have tried to break down each part of the regular expression in the comments in the below data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input fac_code $char50.;
  datalines;
K111I001 C01
A01B001
;


data want(drop = substitute);
  /* define perl regular expression for substitution (assigned once in data step) */
  substitute = cat(
                   's/'      /* substitution specification start:       */
                  ,'(\d)'    /* replace any digit                       */
                  ,'([A-Z])' /* that is followed by an uppercase letter */
                  ,'/'       /* with                                    */
                  ,'$1'      /* the digit that was found                */
                  ,' '       /* followed by a new space character       */
                  ,'$2'      /* and the uppercase letter that was found */
                  ,'/'       /* substitution specification end          */
                  ,'o'       /* compile-once (i.e., not every obs)      */
                  );
  
  /* use Do-Whitlock to loop through obs */
  do until(last_obs);
    set have end = last_obs;
  
    fac_code_clean = prxchange(substitute, -1, fac_code);
    
    output;
  end;
  
  /* prevent unnecessary return to start of data step */
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Amir_0-1750001733567.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107842iDC2167B7B1598FD5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Amir_0-1750001733567.png" alt="Amir_0-1750001733567.png" /&gt;&lt;/span&gt;&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;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jun 2025 15:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/969065#M376719</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2025-06-15T15:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: add space between consecutive code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/970622#M377109</link>
      <description>&lt;P&gt;Thank you so much! That is exactly what I want&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2025 16:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-space-between-consecutive-code/m-p/970622#M377109</guid>
      <dc:creator>ballakaay</dc:creator>
      <dc:date>2025-07-11T16:12:31Z</dc:date>
    </item>
  </channel>
</rss>

