title: Reading csv with newlines in some fields, termstr=crlf doesn't work
body: <p>I have a csv file which has user entered comments, that occasionally end in newlines. This causes errors when using <code>infile</code>, and results in rows with mis-ordered variables.</p>
  
  <p>I've tried <code>termstr=crlf</code> or <code>cr</code> or <code>lf</code>. With <code>lf</code> or <code>crlf</code> I get zero observations read in, and with <code>cr</code>, I get the same error as if I leave it out.</p>
  
  <p>If I open the file in excel and do a Replace ctrl-j (e.g. <a href="http://blog.contextures.com/archives/2013/05/28/find-and-replace-line-breaks-in-excel/" rel="nofollow">http://blog.contextures.com/archives/2013/05/28/find-and-replace-line-breaks-in-excel/</a>), it solves the problem and the data reads in perfectly.</p>
  
  <p>The file is coming from backendless, and the original data is from smart phones.</p>
  
  <p>edit: I solved this using <a href="http://support.sas.com/kb/41/116.html" rel="nofollow">http://support.sas.com/kb/41/116.html</a> as a source, and ended up with the following</p>
  
  <pre><code>data _null_;
    infile 'test.csv' recfm=n lrecl=50000;
    file 'testout.csv' recfm=n;
    input a $char1.;
    if a = '"' then do;
      d+1;
      if d = 2 then d = 0;
    end;
    if a = "," and d = 0 then do;
      c+1;
    end;
    if a = '0A'x then do;
      if c = 2 then do;
        c = 0;
        put '0A'x;
      end;
    end;
    else put a $char1.;
  run;
  </code></pre>
  
  <p>The first conditional tracks whether the delimiters I'm seeing (<code>,</code>) are true delimiters or just inside a string, the second conditional counts the number of variables I've seen so far. The last conditional deletes all <code>lf</code>'s except for after I've seen the proper number of variables (<code>c=2</code>).</p>