<?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 How to Read a single quote as data value from a tab-delimited text file? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/360934#M85046</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to read from a tab-delimited text file&amp;nbsp;and running into issues with single quote as a data value. Below is the data set I am working on-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Col1 &amp;nbsp; Col2 &amp;nbsp; Col3 &amp;nbsp; Col4 &amp;nbsp; Col5&lt;/P&gt;&lt;P&gt;Apple &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;Pear &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Grapes &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Code I used -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test_file;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Infile "&amp;amp;mydir/data_file.txt" &amp;nbsp;DLM='09'x &amp;nbsp;DSD &amp;nbsp;MISSOVER;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Input Col1 :$Char20.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col2 :$Char20.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col3 :$Char20.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col4 :$Char20.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col5 :$Char20.;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem: My code is reading the tab between the consecutive single quotes as the data value, instead of the single quotes as individual data value (for col3 and col4).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to read single quote as a data value when I do not use "DSD" option. However, with missing values in my raw data, I need to use DSD.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest a solution to resolve this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 May 2017 21:30:04 GMT</pubDate>
    <dc:creator>Kaos</dc:creator>
    <dc:date>2017-05-23T21:30:04Z</dc:date>
    <item>
      <title>How to Read a single quote as data value from a tab-delimited text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/360934#M85046</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to read from a tab-delimited text file&amp;nbsp;and running into issues with single quote as a data value. Below is the data set I am working on-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Col1 &amp;nbsp; Col2 &amp;nbsp; Col3 &amp;nbsp; Col4 &amp;nbsp; Col5&lt;/P&gt;&lt;P&gt;Apple &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;Pear &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Grapes &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Code I used -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test_file;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Infile "&amp;amp;mydir/data_file.txt" &amp;nbsp;DLM='09'x &amp;nbsp;DSD &amp;nbsp;MISSOVER;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Input Col1 :$Char20.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col2 :$Char20.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col3 :$Char20.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col4 :$Char20.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col5 :$Char20.;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem: My code is reading the tab between the consecutive single quotes as the data value, instead of the single quotes as individual data value (for col3 and col4).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to read single quote as a data value when I do not use "DSD" option. However, with missing values in my raw data, I need to use DSD.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest a solution to resolve this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 21:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/360934#M85046</guid>
      <dc:creator>Kaos</dc:creator>
      <dc:date>2017-05-23T21:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read a single quote as data value from a tab-delimited text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/360939#M85049</link>
      <description>&lt;P&gt;How many files like this are you going to have to read?&lt;/P&gt;
&lt;P&gt;If it is only a few then a kludge is to replace the single quote with another uncommon character such as ~ with a text editor before reading and then replace after reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I am not quite understanding&amp;nbsp;why you are using char20 or did you leave that from your real program but&amp;nbsp;didn't realize that may not work for your example data? Also have you tried using an INFORMAT statement instead of including the informat on the input statement?&lt;/P&gt;
&lt;P&gt;Such as:&lt;/P&gt;
&lt;PRE&gt;Data test_file;
    Infile "&amp;amp;mydir/data_file.txt"  DLM='09'x  DSD  MISSOVER;
    informat Col1 - Col5  $Char20. ;
    Input Col1 
          Col2 
          Col3 
          Col4 
          Col5 ;
Run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to attach a text file with a few lines of example data as the forum reformats stuff, especially when pasted into the main windows and we cannot test code against what you post very well.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 21:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/360939#M85049</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-23T21:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read a single quote as data value from a tab-delimited text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/360948#M85055</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/128653"&gt;@Kaos&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;That's a tricky one. Best idea I could come up with is to add a single blank between consecutive delimiters so you don't need option DSD.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  Infile "C:\temp\test.txt"  DLM='09'x MISSOVER;

  /* modify input buffer: add blanks between consecutive delimiters */
  input @;
  _infile_=prxchange("s/(\t)(?=\t)/\1 /",-1,_infile_);

  input 
    Col1 :$Char20.
    Col2 :$Char20.
    Col3 :$Char20.
    Col4 :$Char20.
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8996i5F5EB82273A4AF5B/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 22:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/360948#M85055</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-05-23T22:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read a single quote as data value from a tab-delimited text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/361134#M85128</link>
      <description>&lt;P&gt;Basically, you will want to replace the single quotes with something else before reading - but it is quite easy to have SAS do that, by manipulating the automatic variable _INFILE_ - I used "¤" here:&lt;/P&gt;&lt;PRE&gt;Data test_file;
    Infile "&amp;amp;mydir/data_file.txt"  DLM='09'x  DSD  MISSOVER;
    _infile_=transwrd(_infile_,'09'x!!"'"!!'09'x,'09'x!!'¤'!!'09'x);
    if substr(_infile_,1,2)="'"!!'09'x then
      substr(_infile_,1,1)='¤'; /* first cell is single quote */
    if substrn(_infile_,length(_infile_)-1)='09'x!!"'" then
      substr(_infile_,length(_infile_))='¤'; /* last cell is a single quote */
    Input Col1 :$Char20.
             Col2 :$Char20.
             Col3 :$Char20.
             Col4 :$Char20.
             Col5 :$Char20.;
    array cols col1-col5;
    do _N_=1 to dim(cols);
      if cols(_N_)='¤' then
        cols(_N_)="'";
      end;
Run;&lt;/PRE&gt;&lt;P&gt;If you do not have any text that is quoted using single quotes, you can simplify the initial translation:&lt;/P&gt;&lt;PRE&gt;Data test_file;
    Infile "&amp;amp;mydir/data_file.txt"  DLM='09'x  DSD  MISSOVER;
    _infile_=translate(_infile_,'¤',"'");
    Input Col1 :$Char20.
             Col2 :$Char20.
             Col3 :$Char20.
             Col4 :$Char20.
             Col5 :$Char20.;
    array cols col1-col5;
    do _N_=1 to dim(cols);
      cols(_N_)=translate(cols(_N_),"'",'¤');
      end;
Run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 10:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/361134#M85128</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-05-24T10:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read a single quote as data value from a tab-delimited text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/361174#M85139</link>
      <description>&lt;P&gt;Why not translate it into other character and translate it back ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data test_file;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Infile "&amp;amp;mydir/data_file.txt" &amp;nbsp;DLM='09'x &amp;nbsp;DSD &amp;nbsp;MISSOVER;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input&amp;nbsp;@;&lt;/P&gt;
&lt;P&gt;_infile_=translate(_infile_,'.',"'");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Input Col1 :$Char20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col2 :$Char20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col3 :$Char20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col4 :$Char20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Col5 :$Char20.;&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 12:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/361174#M85139</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-24T12:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read a single quote as data value from a tab-delimited text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/361272#M85175</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response. I used your second solution, and that worked with a minor change i.e. I had to include "Input&amp;nbsp;@;" before translating single quote to a different special character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 17:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/361272#M85175</guid>
      <dc:creator>Kaos</dc:creator>
      <dc:date>2017-05-24T17:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read a single quote as data value from a tab-delimited text file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/361274#M85176</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to read one file every day that may have single quote in some of the columns. This file is usually 2GB in size with about ~20 MM records so can't really open in text editor. However, I used _infile_ to replace the single quote with a different special character and that worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your input!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 17:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Read-a-single-quote-as-data-value-from-a-tab-delimited/m-p/361274#M85176</guid>
      <dc:creator>Kaos</dc:creator>
      <dc:date>2017-05-24T17:09:19Z</dc:date>
    </item>
  </channel>
</rss>

