<?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: import csv file with CRLF in text field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951159#M371860</link>
    <description>Can you post some real data? It is depend on the pattern that start a new line .&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Input-a-CSV-file-with-text-fields-that-contain-line-breaks/m-p/821603" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Input-a-CSV-file-with-text-fields-that-contain-line-breaks/m-p/821603&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Proc-import-issue-where-the-data-is-both-comma-separated-amp/m-p/833697" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Proc-import-issue-where-the-data-is-both-comma-separated-amp/m-p/833697&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-properly-read-a-csv-file/m-p/855247" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-properly-read-a-csv-file/m-p/855247&lt;/A&gt;</description>
    <pubDate>Tue, 19 Nov 2024 00:48:42 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-11-19T00:48:42Z</dc:date>
    <item>
      <title>import csv file with CRLF in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951124#M371848</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an csv file with around 9 fields, one of this field (field 7) is an free text column in the source system.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I.E., user can type an message in it, so this field has carriage return value, special char, quotes, alt+enter.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Below you can see one record. Most of the records are without CR in the text field and is one row in the csv file. But some are with and appear as below.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AnnLyn_0-1731949860203.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102326i6B1130C37ADA465F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AnnLyn_0-1731949860203.png" alt="AnnLyn_0-1731949860203.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can i import it in a easy way (we are using standard SAS integration studio) in a file reader? or programming? is there an option which can help me?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Ann&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 17:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951124#M371848</guid>
      <dc:creator>AnnLyn</dc:creator>
      <dc:date>2024-11-18T17:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: import csv file with CRLF in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951130#M371849</link>
      <description>&lt;P&gt;This works&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename CSV "~/aa.txt";
data WANT;
  infile CSV dsd dlm=';' flowover termstr=crlf;
  informat A B C $8.;
  input A B C;
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;for file&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"aa";"aa
aa";"zz"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE class="table" style="border-spacing: 0;" aria-label="Table WORK.WANT"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="col"&gt;A&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;B&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;C&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;aa&lt;/TD&gt;
&lt;TD class="data"&gt;aa aa&lt;/TD&gt;
&lt;TD class="data"&gt;zz&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 17:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951130#M371849</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-11-18T17:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: import csv file with CRLF in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951132#M371851</link>
      <description>&lt;P&gt;If the lines are ended with CR+LF, which is normal for a DOS/Windows file, and the values have only CR or LF then the file should work fine if you just make sure to use the TERMSTR=CRLF option on the INFILE statement.&amp;nbsp; If you want to use PROC IMPORT to guess how to read the file than make a fileref that points to the file so you can add the TERMSTR=CRLF option to the FILENAME statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the embedded characters are exactly the same as the normal end of line characters then you will need to first preprocess the file to fix that.&amp;nbsp; When the values are quoted that can be done by just counting how many quotes you have seen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is macro that will do that for you:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/replace_crlf.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/replace_crlf.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 18:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951132#M371851</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-18T18:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: import csv file with CRLF in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951134#M371852</link>
      <description>&lt;P&gt;Ah this in on Linux though. I suppose you're on Windows?&lt;/P&gt;
&lt;P&gt;The EOL character is different.&lt;/P&gt;
&lt;P&gt;Never mind.&lt;/P&gt;
&lt;P&gt;You need to read one character at at a time.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 18:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951134#M371852</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-11-18T18:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: import csv file with CRLF in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951144#M371856</link>
      <description>&lt;P&gt;Here's an example of how you can process the data as you read it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename CSV "~/aa.txt";

data _null_;
  file CSV;
  put '"aa";"bb' '0d0a'x 'bb";"cc"' '0d0a'x '"xx";"yy";"zz"';
  put '"11";"22";"33"';
run;

data WANT;
  infile CSV recfm=n eof=EOF;%* Read the file in stream mode;
  length A B C TMP $8 ;      %* Declare variables;
  retain A B TMP;            %* Retain variables
  input X $1. @@;            %* Save one character of data;
  if X='"' then do;          %* Look for quote in data;
    Q+1;                     %* Count quotes;
    if Q=2 then do;          %* Second quote: End of string; 
      VARNO+1;               %* Count variables ; 
      if VARNO=1 then A=TMP; %* Save value into variable;
      if VARNO=2 then B=TMP; %* Save value into variable;
      if VARNO=3 then do;    %* Last variable: Save record; 
        C=TMP;               %* Save value into variable;
        output;              %* Save record;
        VARNO=-1;            %* Reset variable counter;
      end;  
      else do;               %* Not last variable: skip to next data character;
        do until (X not in (';','"','0d'x,'0a'x));
          input X $1. @@;   
        end;  
        TMP=X;               %* Save first character of data;
      end;
      Q=1;                   %* Second quote processed, reset quote counter;
    end;  
  end;
  else 
    TMP=catt(TMP,X);        %* Character is not a quote: Append it into value;
  return;                   %* Go to top to read next character;
  eof:                      %* EOF found;
  stop;                     %* Stop the data step;
  keep A B C;
run;
proc print noobs;
run;  
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE class="table" style="border-spacing: 0; border-style: solid; background-color: cxcccccc;" aria-label="Table WORK.WANT"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="col"&gt;A&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;B&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;C&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;aa&lt;/TD&gt;
&lt;TD class="data"&gt;bb bb&lt;/TD&gt;
&lt;TD class="data"&gt;cc&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;xx&lt;/TD&gt;
&lt;TD class="data"&gt;yy&lt;/TD&gt;
&lt;TD class="data"&gt;zz&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;11&lt;/TD&gt;
&lt;TD class="data"&gt;22&lt;/TD&gt;
&lt;TD class="data"&gt;33&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 21:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951144#M371856</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-11-18T21:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: import csv file with CRLF in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951159#M371860</link>
      <description>Can you post some real data? It is depend on the pattern that start a new line .&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Input-a-CSV-file-with-text-fields-that-contain-line-breaks/m-p/821603" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Input-a-CSV-file-with-text-fields-that-contain-line-breaks/m-p/821603&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Proc-import-issue-where-the-data-is-both-comma-separated-amp/m-p/833697" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Proc-import-issue-where-the-data-is-both-comma-separated-amp/m-p/833697&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-properly-read-a-csv-file/m-p/855247" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-properly-read-a-csv-file/m-p/855247&lt;/A&gt;</description>
      <pubDate>Tue, 19 Nov 2024 00:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-csv-file-with-CRLF-in-text-field/m-p/951159#M371860</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-19T00:48:42Z</dc:date>
    </item>
  </channel>
</rss>

