<?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: How to convert comma delimited values to multiple rows when comma is present in values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877291#M346581</link>
    <description>I'm not sure if there is any easy way to do this. The options I can think of are either change your comma seperator/deliminator to another character eg: ";" OR remove the comma from "5,000"</description>
    <pubDate>Wed, 24 May 2023 15:22:13 GMT</pubDate>
    <dc:creator>Seadrago</dc:creator>
    <dc:date>2023-05-24T15:22:13Z</dc:date>
    <item>
      <title>How to convert comma delimited values to multiple rows when comma is present in values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877288#M346579</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help to achieve below :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting input values as comma separated values and again comma in the values as nested comma. I want to make multiple rows based on comma separated and not on based nested comma values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="604"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="331"&gt;Input&lt;/TD&gt;
&lt;TD width="273"&gt;Required&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="4" width="331"&gt;Business Meeting - Involved, MTNG - Meals &amp;gt; 5,000XYZ, XYZ &amp;amp; ABC &amp;gt; 5,000XYZ, XYZ - Meal &amp;gt; 5,000XYZ&lt;/TD&gt;
&lt;TD&gt;Business Meeting - Involved&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MTNG - Meals &amp;gt; 5,000XYZ&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;XYZ &amp;amp; ABC &amp;gt; 5,000XYZ&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;XYZ - Meal &amp;gt; 5,000XYZ&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 24 May 2023 15:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877288#M346579</guid>
      <dc:creator>Siva_Harish</dc:creator>
      <dc:date>2023-05-24T15:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert comma delimited values to multiple rows when comma is present in values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877291#M346581</link>
      <description>I'm not sure if there is any easy way to do this. The options I can think of are either change your comma seperator/deliminator to another character eg: ";" OR remove the comma from "5,000"</description>
      <pubDate>Wed, 24 May 2023 15:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877291#M346581</guid>
      <dc:creator>Seadrago</dc:creator>
      <dc:date>2023-05-24T15:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert comma delimited values to multiple rows when comma is present in values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877296#M346583</link>
      <description>&lt;P&gt;The surest way is to fix the process that generated the values so that it makes something that can be scanned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Either use a delimiter that cannot appear in the data.&lt;/LI&gt;
&lt;LI&gt;Or add quotes around the values (or at least the values that contain the delimiters).&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Then you can use the Q option on the SCAN() function to parse the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of the second option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  string='Business Meeting - Involved,"MTNG - Meals &amp;gt; 5,000XYZ","XYZ &amp;amp; ABC &amp;gt; 5,000XYZ","XYZ - Meal &amp;gt; 5,000XYZ"';
run;

data want;
  set have;
  do index=1 to countw(string,',','q');
    length value $40 ;
    value = dequote(scan(string,index,',','q'));
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    index               value

 1       1      Business Meeting - Involved
 2       2      MTNG - Meals &amp;gt; 5,000XYZ
 3       3      XYZ &amp;amp; ABC &amp;gt; 5,000XYZ
 4       4      XYZ - Meal &amp;gt; 5,000XYZ
&lt;/PRE&gt;
&lt;P&gt;If looks like you are actually using comma and space as the delimiter. So perhaps you can split on those.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  string='Business Meeting - Involved, MTNG - Meals &amp;gt; 5,000XYZ, XYZ &amp;amp; ABC &amp;gt; 5,000XYZ, XYZ - Meal &amp;gt; 5,000XYZ';
run;

data want;
  set have;
  loc=1;
  do index=1 by 1 until(nextloc=0);
    nextloc=find(string,', ',loc);
    length value $40 ;
    if nextloc then value=substrn(string,loc,nextloc-loc-1);
    else value=substrn(string,loc);
    output;
    loc=nextloc+2;
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise you might try to remove (or replace) the commas that appear between digits.&amp;nbsp; Perhaps use regular expressions. And then you can scan using comma as the delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 15:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877296#M346583</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-24T15:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert comma delimited values to multiple rows when comma is present in values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877297#M346584</link>
      <description>&lt;P&gt;Remove the comma's from the numbers is the easiest solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sample input data */
data have;
    input text $100.;
    datalines;
Business Meeting - Involved, MTNG - Meals &amp;gt; 5,000XYZ, XYZ &amp;amp; ABC &amp;gt; 5,000XYZ, XYZ - Meal &amp;gt; 5,000XYZ
;

data want;
    set have;
    *remove commas in numbers;
    new_text=prxchange('s/(\d+),(\d+)/$1$2/', -1, text);
    *count number of terms;
    nterms=countc(new_text, ",");
    *expand out;

    do i=1 to nterms+1;
        term=scan(new_text, i, ",");
        output;
    end;
run;

/* View the output */
proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 May 2023 15:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-comma-delimited-values-to-multiple-rows-when/m-p/877297#M346584</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-24T15:54:44Z</dc:date>
    </item>
  </channel>
</rss>

