<?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 Issues reading piped txt file with quotes using proc import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657775#M197151</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34372"&gt;@RichardinOz&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&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;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/48158"&gt;@weizhongma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to read in the attached .txt pipe delimited file using proc import. But the quotes prevents me from reading it properly . Please find attached sample file .&lt;/P&gt;
&lt;P&gt;Any help will be deeply appreciated&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	proc import
								datafile="Filename" 
								out=test dbms=DLM replace;
								getnames=yes;
								Delimiter='|';
								Datarow=2;

						run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jun 2020 01:42:17 GMT</pubDate>
    <dc:creator>dennis_oz</dc:creator>
    <dc:date>2020-06-12T01:42:17Z</dc:date>
    <item>
      <title>Issues reading piped txt file with quotes using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657775#M197151</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34372"&gt;@RichardinOz&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&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;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/48158"&gt;@weizhongma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to read in the attached .txt pipe delimited file using proc import. But the quotes prevents me from reading it properly . Please find attached sample file .&lt;/P&gt;
&lt;P&gt;Any help will be deeply appreciated&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	proc import
								datafile="Filename" 
								out=test dbms=DLM replace;
								getnames=yes;
								Delimiter='|';
								Datarow=2;

						run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 01:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657775#M197151</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2020-06-12T01:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Issues reading piped txt file with quotes using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657815#M197153</link>
      <description>&lt;P&gt;The quotes don't look like they are going to be an issue.&amp;nbsp; The issue appears to be that you have end of line characters in the middle of the values of one of the fields.&amp;nbsp; If you cannot get those removed you might be able to use one of the many methods posted on this forum to pre-process the file to remove the embedded end of line characters.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 02:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657815#M197153</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-12T02:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Issues reading piped txt file with quotes using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657863#M197154</link>
      <description>&lt;P&gt;The issue is records broken by a CRLF.&lt;/P&gt;
&lt;P&gt;proc import cannot handle these.&lt;/P&gt;
&lt;P&gt;This data step reads the data provided:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT; 
  infile F delimiter='|' pad firstobs=2;
  input ID $ REASON : $200. ;
  if REASON =: '"'  and char(REASON, length(REASON)) ne '"' then do until(STOP);
    input @; 
    REASON=catt(REASON,compress(_INFILE_,'|'));       
    if char(REASON, length(REASON))='"' then STOP=1;
    else input @1;
  end;
  REASON=dequote(REASON);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.T" width="1297px" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col" width="74.4444px"&gt;ID&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="1221.11px"&gt;REASON&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="74.4444px" class="l data"&gt;1234567&lt;/TD&gt;
&lt;TD width="1221.11px" class="l data"&gt;Xxx has alway been great. I have alway been a xxxxxx member.Always supportive of financial struggles too&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="74.4444px" class="l data"&gt;1234567&lt;/TD&gt;
&lt;TD width="1221.11px" class="l data"&gt;You’ re amazing.You asdasdasr, and the brown fox jumped over the fence to re-instate him, so that’s the positive score.On the plus side he gets the all the best faciliteis for.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 02:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657863#M197154</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-12T02:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Issues reading piped txt file with quotes using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657870#M197157</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294547"&gt;@Emma8&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214340"&gt;@smantha&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi , many thanks for your reply&amp;nbsp; .. I would ideally like to use proc import .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found this post&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Import-text-file-into-SAS/m-p/657300#M196977" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Import-text-file-into-SAS/m-p/657300#M196977&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;When I executed this piece of code I was able to read the fiels.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But whats happened is there are other fields that are numeric in the file and because of that&amp;nbsp; I get the error as below .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Error:

NOTE: Invalid data for &lt;FONT color="#FF0000"&gt;EXDT&lt;/FONT&gt; in line 472 295-304.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

&lt;FONT color="#FF0000"&gt;EXDT=.&lt;/FONT&gt;



%let repA=' '; /* replacement character LF */
%let repD=' '; /* replacement character CR */
%let dsnnme="XXX_yyyy.txt"; /* use full path of CSV file */
data _null_;
/* RECFM=N reads the file in binary format. The file consists */
/* of a stream of bytes with no record boundaries. SHAREBUFFERS */
/* specifies that the FILE statement and the INFILE statement */
/* share the same buffer. */
infile &amp;amp;dsnnme recfm=n sharebuffers;
file &amp;amp;dsnnme recfm=n;
/* OPEN is a flag variable used to determine if the CR/LF is within */
/* double quotes or not. Retain this value. */
retain open 0;
input a $char1.;
/* If the character is a double quote, set OPEN to its opposite value. */
if a = '"' then open = ^(open);
/* If the CR or LF is after an open double quote, replace the byte with */
/* the appropriate value. */
if open then do;
if a = '0D'x then put &amp;amp;repD;
else if a = '0A'x then put &amp;amp;repA;
end;
run;





proc import
datafile="XXX_yyyy.txt" 
out=work dbms=DLM replace;
getnames=yes;
Delimiter='|';
Datarow=2;
guessingrows=20000;

run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 03:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657870#M197157</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2020-06-12T03:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Issues reading piped txt file with quotes using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657873#M197160</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19264"&gt;@dennis_oz&lt;/a&gt;&amp;nbsp;Sure you can read the data with a data step, fix it, write it out, and read it again via proc import.&lt;/P&gt;
&lt;P&gt;But why?&lt;/P&gt;
&lt;P&gt;A data step is the only way you can totally control how data is read.&lt;/P&gt;
&lt;P&gt;Just use the most appropriate tool is my recommendation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 04:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/657873#M197160</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-12T04:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Issues reading piped txt file with quotes using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/658344#M197309</link>
      <description>&lt;P&gt;Hi Chris,&lt;/P&gt;
&lt;P&gt;You are correct by saying infile has greater control&amp;nbsp; when reading the file .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="line-height: 1.71429; font-family: Arial, Helvetica, sans-serif;"&gt;Project requirement is to use Proc Import as the file is coming from an external party and sometimes they can increase the number of columns they send without notice. Hence do not want the code to fail in such a scenario.&lt;/P&gt;
&lt;P style="line-height: 1.71429; font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code is amazing and will definitely put it into use .&amp;nbsp; Thank you for the prpmpt reply and appreciate your help !!!&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jun 2020 11:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-reading-piped-txt-file-with-quotes-using-proc-import/m-p/658344#M197309</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2020-06-14T11:17:14Z</dc:date>
    </item>
  </channel>
</rss>

