<?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 raw file pipe enclosed separated by comma exceeding 257 length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926741#M364708</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I tested with your simplified code, I got some warnings about invalid data for the Date format columns. I read the columns first as DATETIME then format them as DATEAMPM.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data of the date format columns that I got warnings from:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;01-JUN-2001 10.16.09.000000 AM&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 May 2024 07:39:41 GMT</pubDate>
    <dc:creator>angel17th</dc:creator>
    <dc:date>2024-05-02T07:39:41Z</dc:date>
    <item>
      <title>Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926717#M364694</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to ask for your help regarding the issue on subject. I already tried the solution provided in the&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Read-in-raw-pipe-enclosed-data-separated-by-commas-SAS-9-4/td-p/552481" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Read-in-raw-pipe-enclosed-data-separated-by-commas-SAS-9-4/td-p/552481&lt;/A&gt;&amp;nbsp;solved by&amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;but the records exceeding the 257 length are truncated causing for misaligned imported records. I've tried changing the lrecl value from 1 to 32767 and the char1 to char32767 but it still doesn't solved the issue with truncation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another issue with the raw data is that the empty records are not pipe enclosed. Hope that someone can help me with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and advance!&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 02:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926717#M364694</guid>
      <dc:creator>angel17th</dc:creator>
      <dc:date>2024-05-02T02:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926719#M364696</link>
      <description>&lt;P&gt;Why would records longer than 257 bytes be truncated?&lt;/P&gt;
&lt;P&gt;If you cannot supply some example lines from the file then perform your own analysis of the file to see if it is well formed.&lt;/P&gt;
&lt;P&gt;For example if you just read in the file without trying to save it you should see the record count and the min and max record length.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile 'myfile.csv' lrecl=1000000 ;
  input;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;50   data _null_;
51     infile csv lrecl=1000000;
52     input;
53   run;

NOTE: The infile CSV is:
      (system-specific pathname),
      (system-specific file attributes)

NOTE: 20 records were read from the infile (system-specific pathname).
      The minimum record length was 17.
      The maximum record length was 26.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2024 03:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926719#M364696</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-02T03:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926724#M364698</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response, and apologies for the lack of details. Here is the sample data I'm reading:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;|11081990|,|41|,|X04|,|N-XYXYXYXY/SAMPLE DUMMY DATA TO T|,|05311999|,|1|,|08-JAN-2001 04.28.19.546000 AM|,|1|,|29-APR-2001 04.55.35.938000 PM|,|08182001|,,,,
|09201978|,|42|,|Y05|,|N-XYXYXY/SAMPLE DUMMY DATA TO TEST THE TRUNCATION OF IMPORTED RECORDS DUE TO THE LONG DATA SAMPLE DUMMY DATA TO TEST THE TRUNCATION OF IMPORTED RECORDS DUE TO THE LONG DATA SAMPLE DUMMY DATA TO TEST THE TRUNCATION OF |,|04211988|,|1|,|10-MAY-1989 05.28.30.550000 AM|,|1|,|20-JUN-1989 03.52.35.942000 PM|,|03031989|,,,,
|12031985|,|43|,|Z06|,|K-XYXYXYXYXYXYXYXY/ SAMPLE DUMMY DATA TO TEST THE TRUNCATION OF IMPORTED RECORDS DUE TO THE L|,|09131988|,|1|,|19-SEP-1988 15.28.19.552000 AM|,|1|,|02-OCT-1988 13.44.15.944000 PM|,|03191988|,,,,&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I use the your modified code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;filename original "IMPORT_DATA.csv";
filename fixed "FIXED_IMPORT_DATA.csv";
data _null_;
  infile original lrecl=1 recfm=f ;
  file fixed termstr=crlf;
  input char $char1.;
  numpipe + (char='|');
  if char='0D'x then return;
  else if char='0A'x then do;
    if mod(numpipe,2)=1 then put '|' @;
    else do;
       numpipe=0;
       put;
    end;
  end;
  else if char='|' then put '"' @;
  else if char='"' then put '""' @;
  else put char $char1. @;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The&amp;nbsp;FIXED_IMPORT_DATA.CSV will be created with the following records:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;"11081990","41","X04","N-XYXYXYXY/SAMPLE DUMMY DATA TO T","05311999","1","08-JAN-2001 04.28.19.546000 AM","1","29-APR-2001 04.55.35.938000 PM","08182001",,,,
"09201978","42","Y05","N-XYXYXY/SAMPLE DUMMY DATA TO TEST THE TRUNCATION OF IMPORTED RECORDS DUE TO THE LONG DATA SAMPLE DUMMY DATA TO TEST THE TRUNCATION OF IMPORTED RECORDS DUE TO THE LONG DATA SAMPLE DUMMY DATA TO TEST THE TRUNCATION OF ","04211988","1","10-MAY-1989 05.28.30.550000 AM"
"1","02-OCT-1988 13.44.15.944000 PM","03191988",,,,&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You may notice that the second record was truncated and the third record was changed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 04:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926724#M364698</guid>
      <dc:creator>angel17th</dc:creator>
      <dc:date>2024-05-02T04:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926728#M364699</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465381"&gt;@angel17th&lt;/a&gt;&amp;nbsp;Your code works as it should in my Windows environment.&lt;/P&gt;
&lt;P&gt;Are you sure this is not just a display issue? When I opened the generated file with Notepad++ and Word Wrapping selected I've seen exactly the same as you shared. But even though the 2nd record gets displayed on two lines it's still a single record (one CRLF).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1714624868095.png" style="width: 1174px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96122i06D2998CC1054141/image-dimensions/1174x71?v=v2" width="1174" height="71" role="button" title="Patrick_0-1714624868095.png" alt="Patrick_0-1714624868095.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And here some code to compare source with target that also confirms that things appear to work as desired.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let source=c:\temp\IMPORT_DATA.csv;
%let target=c:\temp\FIXED_IMPORT_DATA.csv;

filename original "&amp;amp;source";
filename fixed "&amp;amp;target";
data _null_;
  infile original lrecl=1 recfm=f ;
  file fixed termstr=crlf;
  input char $char1.;
  numpipe + (char='|');
  if char='0D'x then return;
  else if char='0A'x then do;
    if mod(numpipe,2)=1 then put '|' @;
    else do;
       numpipe=0;
       put;
    end;
  end;
  else if char='|' then put '"' @;
  else if char='"' then put '""' @;
  else put char $char1. @;
run;

data source;
  infile "&amp;amp;source" truncover;
  input line:$1000.;
run;
data target;
  infile "&amp;amp;target" truncover;
  input  line:$1000.;
  line=translate(line,'|','"');
run;

proc compare data=source comp=target;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1714625726593.png" style="width: 578px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96123i37580577564DB88D/image-dimensions/578x250?v=v2" width="578" height="250" role="button" title="Patrick_0-1714625726593.png" alt="Patrick_0-1714625726593.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 04:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926728#M364699</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-02T04:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926735#M364702</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried to import the three dummy records to SAS but it outputted four rows, and it seems that it cuts the 2nd record and the remaining parts of that record were inserted to the 3rd row.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test csv.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96125i7FD6AAD1DE9622C1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="test csv.png" alt="test csv.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that I'm using the SAS9 9.3 version, maybe there are some codes that are not compatible?&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 05:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926735#M364702</guid>
      <dc:creator>angel17th</dc:creator>
      <dc:date>2024-05-02T05:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926736#M364703</link>
      <description>&lt;P&gt;SAS is highly backward compatible and if your code works in 9.3 then later SAS versions should return the same result. Normally such differences are caused by environmental differences like different options settings and the like.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my environment option lrecl is set to 32767. If in your env the value is lower than the length of the string you want to write then the default (flowover) will write the not fitting bit to the next line.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test the theory you could define lrecl for your output file (value at least as long as the max string length you want to write onto a single line).&lt;/P&gt;
&lt;PRE&gt;filename fixed "&amp;amp;target" lrecl=32767;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 05:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926736#M364703</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-02T05:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926737#M364704</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your suggestion worked! Thank you so much! I changed the lrecl for the output file and also added the lrecl=32767 option when importing it to the SAS dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 05:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926737#M364704</guid>
      <dc:creator>angel17th</dc:creator>
      <dc:date>2024-05-02T05:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926738#M364705</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465381"&gt;@angel17th&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you could simplify your current code using syntax like below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile original;
  file fixed termstr=crlf;
  input;
  _infile_=tranwrd(_infile_,'"','""');
  _infile_=tranwrd(_infile_,'|','"');
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2024 06:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926738#M364705</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-02T06:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926741#M364708</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I tested with your simplified code, I got some warnings about invalid data for the Date format columns. I read the columns first as DATETIME then format them as DATEAMPM.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data of the date format columns that I got warnings from:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;01-JUN-2001 10.16.09.000000 AM&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2024 07:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926741#M364708</guid>
      <dc:creator>angel17th</dc:creator>
      <dc:date>2024-05-02T07:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926742#M364709</link>
      <description>&lt;P&gt;Are you changing the source file for the sole person of import into a SAS table? If that's the case then below code to directly read your source file into a SAS table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let source=c:\temp\IMPORT_DATA.csv;

data work.out;
  infile "&amp;amp;source"
    lrecl=500
    dlm=','
    truncover
    dsd;

  input @;
  _infile_=compress(_infile_,"|");

  input
    var_1  : mmddyy8.
    var_2  : best32.
    var_3  : $3.
    var_4  : $300.
    var_5  : mmddyy8.
    var_6  : best32.
    var_7  : datetime30.
    var_8  : best32.
    var_9  : datetime30.
    var_10 : mmddyy8.
    ;

  format
    var_1    date9.
    var_5    date9.
    var_7    datetime30.6
    var_9    datetime30.6
    var_10   date9.
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2024 08:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926742#M364709</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-02T08:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Import raw file pipe enclosed separated by comma exceeding 257 length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926865#M364774</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes I'm reading the CSV to a SAS table, however, that data of the CSV is a pipe enclosed with a comma delimiter. That is why I initially referenced the solution from Tom when reading the raw CSV. I added replaced the compress with the following code and it also worked:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 02:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-raw-file-pipe-enclosed-separated-by-comma-exceeding-257/m-p/926865#M364774</guid>
      <dc:creator>angel17th</dc:creator>
      <dc:date>2024-05-03T02:48:50Z</dc:date>
    </item>
  </channel>
</rss>

