<?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: Split variable into columns with conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656636#M196942</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2153"&gt;@JeffMeyers&lt;/a&gt; &lt;EM&gt;&amp;gt; take the&amp;nbsp;length of a missing character it still returns 1.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Use the lengthn() function.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jun 2020 00:21:59 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-06-11T00:21:59Z</dc:date>
    <item>
      <title>Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656580#M196895</link>
      <description>&lt;P&gt;Hello community!&lt;/P&gt;&lt;P&gt;I would like some help with this. I somehow did it manually, but I would want to learn how to do it with a more sophisticated code.&lt;/P&gt;&lt;P&gt;I need to split this grid into columns (up to 12 columns), with the following conditions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;- If it is a "C" or a "-" it must go in a single column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;- If it is a number, example "03" "09" "23", it must go in a single column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;GRID&lt;/TD&gt;&lt;TD&gt;Column1&lt;/TD&gt;&lt;TD&gt;Column2&lt;/TD&gt;&lt;TD&gt;Column3&lt;/TD&gt;&lt;TD&gt;Column4&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;Column 12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;13131313130706050403--01CCCCCCCC&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;CCCCCCCCCCCCCCCCCCCCCC&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;13130234&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;02&lt;/TD&gt;&lt;TD&gt;34&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;13131354&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;54&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;CC020101CCC01CC01CC01CC--&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;02&lt;/TD&gt;&lt;TD&gt;01&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;--C20133&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;C0201CC&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;02&lt;/TD&gt;&lt;TD&gt;01&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;C030201C&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;03&lt;/TD&gt;&lt;TD&gt;02&lt;/TD&gt;&lt;TD&gt;01&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 21:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656580#M196895</guid>
      <dc:creator>marianob</dc:creator>
      <dc:date>2020-06-10T21:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656582#M196897</link>
      <description>&lt;P&gt;Are all numbers two digits?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 21:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656582#M196897</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2020-06-10T21:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656583#M196898</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;Yes, as the ones between 1 and 9 have leading 0s.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 21:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656583#M196898</guid>
      <dc:creator>marianob</dc:creator>
      <dc:date>2020-06-10T21:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656584#M196899</link>
      <description>&lt;P&gt;I think that you need to explicitly show us what the entire result for row 6 might be.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 21:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656584#M196899</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-10T21:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656587#M196902</link>
      <description>&lt;P&gt;Sorry, I manually modified that one in excel (leading 0 in the last "3" was missing). The correct grid for row 6 is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;--C201303&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;03&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 10 Jun 2020 21:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656587#M196902</guid>
      <dc:creator>marianob</dc:creator>
      <dc:date>2020-06-10T21:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656592#M196907</link>
      <description>&lt;P&gt;Here's how I did it with part of your data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data blah;
length x $200.;
x='13131313130706050403--01CCCCCCCC';output;
x='CCCCCCCCCCCCCCCCCCCCCC'; output;
x='13130234';output;
run;

data blah2;
set blah end=last;
    
    n_c=count(x,'C');
    n_dash=count(x,'-');
    if ^missing(compress(x,'-C')) then n_num=length(compress(x,'-C'))/2;
    else n_num=0;
    retain n_columns;
    if sum(n_c,n_dash,n_num)&amp;gt;n_columns then n_columns=sum(n_c,n_dash,n_num);
    
    if last then call symputx('ncol',n_columns);
run;


data blah3;
    set blah2;
    array column {&amp;amp;ncol} $2.;
    
    col=0;
    indx=1;
    do until (indx&amp;gt;length(x));
        if substr(x,indx,1) in('C' '-') then do;
            col=col+1;
            column(col)=substr(x,indx,1);
            indx=indx+1;
        end;
        else do;
            col=col+1;
            column(col)=substr(x,indx,2);
            indx=indx+2;
        end;
        end;
    drop col indx n_c n_dash n_num;
run;
        &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first parts are figuring out how large the array needs to be to hold all of the columns.&amp;nbsp; The last part is filling in the array by incrementing a substring function through and increasing the index based on the character it comes across.&amp;nbsp; This assumes all numbers are two digits.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 22:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656592#M196907</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2020-06-10T22:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656609#M196922</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to learn it properly. I don't understand this part of the code. What is it for?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;if ^missing(compress(x,'-C')) then n_num=length(compress(x,'-C'))/2;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 22:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656609#M196922</guid>
      <dc:creator>marianob</dc:creator>
      <dc:date>2020-06-10T22:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656612#M196925</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set HAVE;
  array COL [12] $2; 
  POS=1;
  do COLNO = 1 to 12 while (char(GRID,POS) ne ' ');
    if '0' &amp;lt;=  char(GRID,POS) &amp;lt;= '9' then do;
      COL[COLNO] = substr(GRID,POS,2);
      POS+2;
    end;
    else do;
      COL[COLNO] = char(GRID,POS);
      POS+1;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" width="790px" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col" width="307.778px" height="18px"&gt;GRID&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL1&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL2&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL3&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL4&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL5&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL6&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL7&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL8&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL9&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL10&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="40px" height="18px"&gt;COL11&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="41.1111px" height="18px"&gt;COL12&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="307.778px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13131313130706050403--01CCCCCCCC&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;07&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;06&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;05&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;04&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;03&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;-&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="41.1111px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;-&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="307.778px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;CCCCCCCCCCCCCCCCCCCCCC&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="41.1111px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="307.778px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13130234&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;02&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;34&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="41.1111px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="307.778px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;--C0234&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;-&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;-&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;02&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&lt;FONT size="2"&gt;34&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="41.1111px" height="27px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 22:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656612#M196925</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-10T22:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656635#M196941</link>
      <description>If you take the length of a missing character it still returns 1.  So what that logic statement is doing is checking first to see if there is any non-missing value after removing the C and - characters (COMPRESS function removes them).  If it is not missing then the length function will tell us how many numbers are left (length of the string after removing the C and - characters).  Otherwise the ELSE statement marks there as 0 numbers.</description>
      <pubDate>Thu, 11 Jun 2020 00:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656635#M196941</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2020-06-11T00:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656636#M196942</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2153"&gt;@JeffMeyers&lt;/a&gt; &lt;EM&gt;&amp;gt; take the&amp;nbsp;length of a missing character it still returns 1.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Use the lengthn() function.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 00:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656636#M196942</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-11T00:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656642#M196947</link>
      <description>Thanks, always good to learn something new.</description>
      <pubDate>Thu, 11 Jun 2020 00:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656642#M196947</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2020-06-11T00:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656712#M196950</link>
      <description>&lt;P&gt;It worked perfectly fine! Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 01:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656712#M196950</guid>
      <dc:creator>marianob</dc:creator>
      <dc:date>2020-06-11T01:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656747#M196951</link>
      <description>&lt;P&gt;Regular expression solution :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input grid : $50. ;
cards;
3131313130706050403--01CCCCCCCC
CCCCCCCCCCCCCCCCCCCCCC
13130234
13131354
CC020101CCC01CC01CC01CC--
--C20133
C0201CC
C030201C
;
run;

data want(rename=(grid_=grid));
length grid_ $50;
	set have;

/*REGEX pattern explained*/
 /*/(\d{2}|\w{1}|\W{1})/io*/
/*1st Capturing Group (\d{2}|\w{1}|\W{1})*/
/*1st Alternative \d{2}*/
/*\d{2} matches a digit (equal to [0-9])*/
/*{2} Quantifier — Matches exactly 2 times*/
/*2nd Alternative \w{1}*/
/*\w{1} matches any word character (equal to [a-zA-Z0-9_])*/
/*{1} Quantifier — Matches exactly one time (meaningless quantifier)*/
/*3rd Alternative \W{1}*/
/*\W{1} matches any non-word character (equal to [^a-zA-Z0-9_])*/
/*{1} Quantifier — Matches exactly one time */
 patternID = prxparse('/\d{2}|\w{1}|\W{1}/io');

   array col[*] $ col1-col12;
   grid_=grid;
   do i=1 to length(grid);
		call prxsubstr(patternID,grid,pos,len);
		col[i]=substr(grid,pos,len);
		grid=substr(grid,pos+len);
		if i eq 12 then leave;
	end;
drop grid patternID pos len i;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jun 2020 02:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/656747#M196951</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-06-11T02:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Split variable into columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/661743#M197757</link>
      <description>Many thanks!</description>
      <pubDate>Wed, 17 Jun 2020 14:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-variable-into-columns-with-conditions/m-p/661743#M197757</guid>
      <dc:creator>marianob</dc:creator>
      <dc:date>2020-06-17T14:15:12Z</dc:date>
    </item>
  </channel>
</rss>

