<?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 the value in the same cell to different cells but in the same column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671635#M201705</link>
    <description>&lt;P&gt;You can loop over all substrings in your "code" variable separated by semicolon using the countw and scan functions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=',';
length no $2 code $200;
input no $ code $;
datalines4;
1, XTRA:TLB; OTCPK:TLMO.F; LSE:0R0N; WBAG:TLB; DB:TLB
2, NYSE:IAB; DB:3NL
;;;;
run;

data want(keep=no code);
   set have(rename = code = input_code);
   do i = 1 to countw(input_code,";");
      code = left(scan(input_code,i,";"));
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Jul 2020 22:56:54 GMT</pubDate>
    <dc:creator>jeppesj</dc:creator>
    <dc:date>2020-07-22T22:56:54Z</dc:date>
    <item>
      <title>split the value in the same cell to different cells but in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671628#M201702</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to split the value in the same cell to different cells but in the same column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, for table 1&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;TD&gt;Code&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;XTRA:TLB; OTCPK:TLMO.F; LSE:0R0N; WBAG:TLB; DB:TLB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;NYSE:IAB; DB:3NL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to have table 2&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;TD&gt;Code&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;XTRA:TLB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;OTCPK:TLMO.F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;LSE:0R0N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;WBAG:TLB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;DB:TLB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;NYSE:IAB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;DB:3NL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the strings in table 1 are separated by ";", however, I do not know how to convert them as table 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please give me some suggestion about this? Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data table1;
infile cards dlm=,;
input 
No: $2.	
Code: $20.;
cards;
"1","XTRA:TLB; OTCPK:TLMO.F; LSE:0R0N; WBAG:TLB; DB:TLB"
"2","NYSE:IAB; DB:3NL"
;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jul 2020 21:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671628#M201702</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-07-22T21:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: split the value in the same cell to different cells but in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671635#M201705</link>
      <description>&lt;P&gt;You can loop over all substrings in your "code" variable separated by semicolon using the countw and scan functions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=',';
length no $2 code $200;
input no $ code $;
datalines4;
1, XTRA:TLB; OTCPK:TLMO.F; LSE:0R0N; WBAG:TLB; DB:TLB
2, NYSE:IAB; DB:3NL
;;;;
run;

data want(keep=no code);
   set have(rename = code = input_code);
   do i = 1 to countw(input_code,";");
      code = left(scan(input_code,i,";"));
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jul 2020 22:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671635#M201705</guid>
      <dc:creator>jeppesj</dc:creator>
      <dc:date>2020-07-22T22:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: split the value in the same cell to different cells but in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671636#M201706</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/125772"&gt;@jeppesj&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You can loop over all substrings in your "code" variable separated by semicolon using the count and scan functions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines delimiter=',';
length no $2 code $200;
input no $ code $;
datalines4;
1, XTRA:TLB; OTCPK:TLMO.F; LSE:0R0N; WBAG:TLB; DB:TLB;
2, NYSE:IAB; DB:3NL;
;;;;
run;

data want(keep=no code);
   set have(rename = code = input_code);
   do i = 1 to count(input_code,";");
      code = left(scan(input_code,i,";"));
      output;
   end;
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think you meant COUNTW instead of COUNT.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 22:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671636#M201706</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-22T22:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: split the value in the same cell to different cells but in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671637#M201707</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I think you meant COUNTW instead of COUNT.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I do, and I have edited my response to reflect this. I had first by mistake included a semicolon at the end of each "code" in the input dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 22:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671637#M201707</guid>
      <dc:creator>jeppesj</dc:creator>
      <dc:date>2020-07-22T22:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: split the value in the same cell to different cells but in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671639#M201709</link>
      <description>&lt;P&gt;Your code results in syntax error and would not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may run next cpde&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
infile cards truncover;
input 
     var1 $4.	
     var2 $200.
 ;
    length Code $20;
    No = compress(var1,'",');
    var2 = compress(var2,'"');
    do i=1 to countw(var2,';');
       Code = scan(var2,i,';');
       output;
    end;
    keep No Code;
cards4;
"1","XTRA:TLB; OTCPK:TLMO.F; LSE:0R0N; WBAG:TLB; DB:TLB"
"2","NYSE:IAB; DB:3NL"
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or alternatively change your input rows as in next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
infile cards truncover;
input 
     No 	
     var2 $200.
 ;
    length Code $20;
    do i=1 to countw(var2,';');
       Code = scan(var2,i,';');
       output;
    end;
    keep No Code;
cards4;
1 XTRA:TLB; OTCPK:TLMO.F; LSE:0R0N; WBAG:TLB; DB:TLB
2 NYSE:IAB; DB:3NL
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 22:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671639#M201709</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-22T22:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: split the value in the same cell to different cells but in the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671730#M201746</link>
      <description>&lt;P&gt;You can simplify the first code by using DLM= and DSD:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
infile cards dlm="," dsd truncover;
input 
  no :$4. 
  var2 :$200.
;
length Code $20;
do i = 1 to countw(var2,';');
  Code = scan(var2,i,';');
  output;
end;
keep No Code;
cards4;
"1","XTRA:TLB; OTCPK:TLMO.F; LSE:0R0N; WBAG:TLB; DB:TLB"
"2","NYSE:IAB; DB:3NL"
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jul 2020 09:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-the-value-in-the-same-cell-to-different-cells-but-in-the/m-p/671730#M201746</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-23T09:35:59Z</dc:date>
    </item>
  </channel>
</rss>

