<?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: Reading CSV file with embedded double quotes, comma &amp;amp; CRLF(multiple lines) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313740#M68220</link>
    <description>&lt;PRE&gt;
Can you attach a TEXT file to let us test the code.



&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Nov 2016 10:55:40 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-11-23T10:55:40Z</dc:date>
    <item>
      <title>Reading CSV file with embedded double quotes, comma &amp; CRLF(multiple lines)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313666#M68200</link>
      <description>&lt;P&gt;I'm having trouble in importing a csv with embedded double quotes, comma &amp;amp; CRLF.&lt;/P&gt;&lt;P&gt;The file was generated by source system and able to import into Microsoft Access without any problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I attempt to import into SAS, the output is not correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample File Content (4 varables &amp;amp; 3 observations:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;a,b,c,d&amp;lt;CRLF&amp;gt;&lt;/P&gt;&lt;P&gt;"a1&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;2&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;3&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;4",,c,d&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;"aaa a a,""&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;a a &lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;a&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;a","bb""bb"", b .&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;b&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;b&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;b&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;b&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;b&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;b&lt;SPAN&gt;&amp;lt;CRLF&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;b",c,d&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;My program:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;DATA test;&lt;BR /&gt;INFILE 'D:\sas_data\test.csv'&lt;BR /&gt;LRECL=32767&lt;BR /&gt;ENCODING="UTF-8"&lt;BR /&gt;DLM=','&lt;BR /&gt;DSD termstr=CRLF;&lt;BR /&gt;INPUT&lt;BR /&gt;col1 : $CHAR100.&lt;BR /&gt;col2 : $CHAR100.&lt;BR /&gt;col3 : $CHAR100.&lt;BR /&gt;col4 : $CHAR100.&lt;BR /&gt;@@;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone have any suggestion for resolving this issue?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 05:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313666#M68200</guid>
      <dc:creator>chinyong</dc:creator>
      <dc:date>2016-11-23T05:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reading CSV file with embedded double quotes, comma &amp; CRLF(multiple lines)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313701#M68207</link>
      <description>&lt;P&gt;In my experience, SAS can't really deal with linebreaks in quoted strings. The linebreak overrides the quotes. This might be an issue how the operating system treats files through the "read next record" system call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My solution has been to write a C program that replaces linebreaks with a &amp;lt;BR&amp;gt; tag at places where the count of quotes is uneven.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 08:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313701#M68207</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-23T08:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reading CSV file with embedded double quotes, comma &amp; CRLF(multiple lines)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313740#M68220</link>
      <description>&lt;PRE&gt;
Can you attach a TEXT file to let us test the code.



&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 10:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313740#M68220</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-23T10:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reading CSV file with embedded double quotes, comma &amp; CRLF(multiple lines)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313747#M68222</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your reply. I had attached the file into this post.&lt;/P&gt;&lt;P&gt;The "test.csv" is a sample file that I created to simulate the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original file is about 900MB and it is automatically generated by system in UNIX and FTP to Windows file server in ascii mode (LF converted to CRLF).&lt;/P&gt;&lt;P&gt;There is one column with multiple lines free text format (10000 characters and this is the problematic part).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the file has been used in Microsoft Access without any problem for the past 2 years.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Challanges faced:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;There is no differenciation of LF and CRLF pattern similar to Excel generated CSV. If the multiple lines are generated by Microsoft Excel, we can use&amp;nbsp;termstr=CRLF. But in this case, all New Lines are end with CRLF.&lt;/LI&gt;&lt;LI&gt;There will be embedded comma, double quotation marks as well.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 11:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313747#M68222</guid>
      <dc:creator>chinyong</dc:creator>
      <dc:date>2016-11-23T11:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Reading CSV file with embedded double quotes, comma &amp; CRLF(multiple lines)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313954#M68306</link>
      <description>&lt;PRE&gt;
That is way too messed up.
How do I know 

"aaa a a,""&lt;CRLF&gt;
a a &lt;CRLF&gt;
a&lt;CRLF&gt;
a",

belong to A
while

"aaa a a,""&lt;CRLF&gt;
a a &lt;CRLF&gt;
a&lt;CRLF&gt;
a","bb""bb"", 

not belong to A ?


&lt;/CRLF&gt;&lt;/CRLF&gt;&lt;/CRLF&gt;&lt;/CRLF&gt;&lt;/CRLF&gt;&lt;/CRLF&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Nov 2016 04:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/313954#M68306</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-24T04:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Reading CSV file with embedded double quotes, comma &amp; CRLF(multiple lines)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/314710#M68578</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yes, it look way too messed up but surprisingly, Microsoft Access is able to handle it well and it has been used for years before I attempt to import into SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you may look at the attached screenshot for how it arranged in Microsoft Access.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13191i186F28CA1DA6A63A/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;</description>
      <pubDate>Mon, 28 Nov 2016 03:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/314710#M68578</guid>
      <dc:creator>chinyong</dc:creator>
      <dc:date>2016-11-28T03:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading CSV file with embedded double quotes, comma &amp; CRLF(multiple lines)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/314738#M68594</link>
      <description>&lt;PRE&gt;

data x;
infile '/folders/myfolders/test.txt' termstr=lf;
input x $1. @@;
run;
data x;
n=0;
do until(last.x);
 set x;
 by x notsorted;
 n+1;
end;

do until(last.x);
 set x;
 by x notsorted;
 if x='"' then count=n;
 output;
end;
drop n;
run;


data x;
 set x;
 mod=mod(count,2);
run;
data x;
 set x;
 array xx{0:1} $ 4 _temporary_ ('off' 'on');
 length flag $ 4;
 retain flag 'off';
 by x notsorted;
 if last.x and mod=1 then do;
  n+1; flag=xx{mod(n,2)};
  group+1;
 end;
 if flag='off' and x=',' then group+1;
drop n;
run;
data temp;
length value $ 200;
 do until(last.group);
  set x;
  by group notsorted;
  value=cats(value,x);
 end;
 value=prxchange('s/^[",]+//',1,value);
 if value not in (' ' '0D'x) then output;
run;
data temp;
 set temp;
 if mod(_n_,4)=1 then obs+1;
run;
proc transpose data=temp out=want(drop=_name_);
by obs;
var value;
run;
&lt;/PRE&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13192i35F926C392D09A3A/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="x.png" title="x.png" /&gt;</description>
      <pubDate>Mon, 28 Nov 2016 06:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-CSV-file-with-embedded-double-quotes-comma-amp-CRLF/m-p/314738#M68594</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-28T06:07:15Z</dc:date>
    </item>
  </channel>
</rss>

