<?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 scan string in comma seperated  string where column includes a comma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/scan-string-in-comma-seperated-string-where-column-includes-a/m-p/692479#M210979</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to&amp;nbsp; scan a string separated by comma where column text sometime contains a comma itself&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here i have extracted som text from a view definition on mssql and in that&amp;nbsp; def there is an expression&amp;nbsp;&lt;/P&gt;
&lt;P&gt;create view x as&lt;/P&gt;
&lt;P&gt;select&lt;/P&gt;
&lt;P&gt;Column1 as Column1,&lt;/P&gt;
&lt;P&gt;Column2 as Column2,&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ISNULL(Column3,' ') as Column3&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;from y&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When i try to split the string into word separated by comma it doesn't work well&amp;nbsp;&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 teststep; 
i=3;
	res ="Column1 as Column1, Column2 as Column2, ISNULL(Column3,' ') as Column3";
	coldef = scan(res, i, ',');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Gives the result&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ISNULL(Column3&lt;/P&gt;
&lt;P&gt;i want it to result in&amp;nbsp;&lt;CODE class=" language-sas"&gt;ISNULL(Column3,' ') as Column3&lt;/CODE&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;</description>
    <pubDate>Mon, 19 Oct 2020 11:13:25 GMT</pubDate>
    <dc:creator>havmaage</dc:creator>
    <dc:date>2020-10-19T11:13:25Z</dc:date>
    <item>
      <title>scan string in comma seperated  string where column includes a comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-string-in-comma-seperated-string-where-column-includes-a/m-p/692479#M210979</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to&amp;nbsp; scan a string separated by comma where column text sometime contains a comma itself&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here i have extracted som text from a view definition on mssql and in that&amp;nbsp; def there is an expression&amp;nbsp;&lt;/P&gt;
&lt;P&gt;create view x as&lt;/P&gt;
&lt;P&gt;select&lt;/P&gt;
&lt;P&gt;Column1 as Column1,&lt;/P&gt;
&lt;P&gt;Column2 as Column2,&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ISNULL(Column3,' ') as Column3&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;from y&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When i try to split the string into word separated by comma it doesn't work well&amp;nbsp;&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 teststep; 
i=3;
	res ="Column1 as Column1, Column2 as Column2, ISNULL(Column3,' ') as Column3";
	coldef = scan(res, i, ',');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Gives the result&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ISNULL(Column3&lt;/P&gt;
&lt;P&gt;i want it to result in&amp;nbsp;&lt;CODE class=" language-sas"&gt;ISNULL(Column3,' ') as Column3&lt;/CODE&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;</description>
      <pubDate>Mon, 19 Oct 2020 11:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-string-in-comma-seperated-string-where-column-includes-a/m-p/692479#M210979</guid>
      <dc:creator>havmaage</dc:creator>
      <dc:date>2020-10-19T11:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: scan string in comma seperated  string where column includes a comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-string-in-comma-seperated-string-where-column-includes-a/m-p/692502#M210989</link>
      <description>&lt;P&gt;If you look at RES, it contains 3 commas.&amp;nbsp; So you are getting everything between the second and third commas.&amp;nbsp; Here's something that will work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;coldef = catx(',', scan(res, i, ','), scan(res, i+1, ','));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That doesn't make it a good solution, however.&amp;nbsp; To write a good solution, we would need to know more about the problem ... how do you detect when you actually have a problem with one of the items in your list.&amp;nbsp; Probably simplest:&amp;nbsp; get rid of the situation where some commas are text and some are delimiters.&amp;nbsp; Use a different character as your delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 12:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-string-in-comma-seperated-string-where-column-includes-a/m-p/692502#M210989</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-10-19T12:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: scan string in comma seperated  string where column includes a comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scan-string-in-comma-seperated-string-where-column-includes-a/m-p/692569#M211000</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/257901"&gt;@havmaage&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To implement the rule "Don't treat commas between parentheses as delimiters," you could temporarily replace the other commas with some odd character (e.g. &lt;FONT face="courier new,courier"&gt;'ÿ'='FF'x&lt;/FONT&gt;) which doesn't occur elsewhere, then apply the SCAN function using that character as delimiter and eventually, if necessary, restore the replaced commas. There should be no unbalanced parentheses for this to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input res $80.;
cards;
Column1 as Column1, Column2 as Column2, ISNULL(Column3,' ') as Column3
f1(a, f2(b, c, d), e) as f, f2(,,0) as g, f3(((3,141),(2,718)),(1,618)) as h
;

data want(drop=_:);
set have;
do _i=1 to length(res);
  _c=char(res,_i);
  _p+(_c='(')-(_c=')');
  if _c=',' &amp;amp; ~_p then substr(res,_i,1)='ÿ';
end;
coldef1=scan(res,1,'ÿ');
coldef2=scan(res,2,'ÿ');
coldef3=scan(res,3,'ÿ');
res=translate(res,',','ÿ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Oct 2020 14:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scan-string-in-comma-seperated-string-where-column-includes-a/m-p/692569#M211000</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-19T14:01:23Z</dc:date>
    </item>
  </channel>
</rss>

