<?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 Separate string and convert it to rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Separate-string-and-convert-it-to-rows/m-p/889332#M351358</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would ask for help on the below please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset in the following format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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=',' DSD;
input Branch $ Employee Products $50.;
datalines;
A, 1, Ball, Paper, Pen, Glass, Car,
B, 1, Dog, Cat, Bird, Water, Pencil,
B, 2, Ball, Paper, Pen, Glass, Car,
A, 2, Dog, Cat, Bird, Water, Pencil,
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The column "Products" contains values separated by commas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a new row with each of these values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The new structure should be as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input Branch $ Employee Products $50.;
datalines;
A 1 Ball
A 1 Paper
A 1 Pen
A 1 Glass
A 1 Car
B 1 Dog
B 1 Cat
B 1 Bird
B 1 Water
B 1 Pencil
A 2 Ball
A 2 Paper
A 2 Pen
A 2 Glass
A 2 Car
B 2 Dog
B 2 Cat
B 2 Bird
B 2 Water
B 2 Pencil
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any help please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Aug 2023 12:25:40 GMT</pubDate>
    <dc:creator>Zatere</dc:creator>
    <dc:date>2023-08-15T12:25:40Z</dc:date>
    <item>
      <title>Separate string and convert it to rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-string-and-convert-it-to-rows/m-p/889332#M351358</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would ask for help on the below please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset in the following format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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=',' DSD;
input Branch $ Employee Products $50.;
datalines;
A, 1, Ball, Paper, Pen, Glass, Car,
B, 1, Dog, Cat, Bird, Water, Pencil,
B, 2, Ball, Paper, Pen, Glass, Car,
A, 2, Dog, Cat, Bird, Water, Pencil,
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The column "Products" contains values separated by commas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a new row with each of these values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The new structure should be as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input Branch $ Employee Products $50.;
datalines;
A 1 Ball
A 1 Paper
A 1 Pen
A 1 Glass
A 1 Car
B 1 Dog
B 1 Cat
B 1 Bird
B 1 Water
B 1 Pencil
A 2 Ball
A 2 Paper
A 2 Pen
A 2 Glass
A 2 Car
B 2 Dog
B 2 Cat
B 2 Bird
B 2 Water
B 2 Pencil
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any help please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 12:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-string-and-convert-it-to-rows/m-p/889332#M351358</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2023-08-15T12:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Separate string and convert it to rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-string-and-convert-it-to-rows/m-p/889335#M351359</link>
      <description>&lt;P&gt;This is a pretty simple DO loop where you use the SCAN function to find the i-th "word", where "word" is delimited by a comma.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    do i=1 to countw(products,',');
        product=scan(products,i,',');
        if not missing(product) then output;
    end;
    drop i products;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 12:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-string-and-convert-it-to-rows/m-p/889335#M351359</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-15T12:37:10Z</dc:date>
    </item>
  </channel>
</rss>

