<?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: INFILE problem in combination with DSD when reading CSV with quotes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445819#M111776</link>
    <description>&lt;P&gt;Thanks RW9 but I do not have the possibility to change the export to a 'valid' CSV. It is delivered by an external party. What is a 'valid' CSV file. I don't think there is a formal definition regulating the form of a CSV-file. Therefore there are a lot of variations in CSV-files. Parsing is an alternative but that's the last rescue I want to use. SAS can read 'everything' so I hope there is a better solution.&lt;/P&gt;&lt;P&gt;Ronald&lt;/P&gt;</description>
    <pubDate>Thu, 15 Mar 2018 13:07:01 GMT</pubDate>
    <dc:creator>RonaldHof</dc:creator>
    <dc:date>2018-03-15T13:07:01Z</dc:date>
    <item>
      <title>INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445805#M111766</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have troubles reading CSV files in with the following situation occurs:&lt;/P&gt;&lt;P&gt;&amp;lt;xx&amp;gt;&amp;lt;delim&amp;gt;&amp;lt;quote&amp;gt;&amp;lt;……..&amp;gt;&amp;lt;quote&amp;gt;&amp;lt;delim&amp;gt;&amp;lt;delim&amp;gt;&amp;lt;xx&amp;gt;. So some ware in a recordline there is a delimiter, followed with a quote, then one or more fields, then some characters closed with a quote before the next delimiter. I tried to solve it with the DSD option but that doesn’t work. The DSD skips the delimiter between the quotes. Without DSD two delimiters behind each others are transformed to one delimiter. Double delimiters can occur because it represents a missing value for that variable. The problem is the last quote directly followed by a delimiter.&lt;/P&gt;&lt;P&gt;Who can help me to solve this problem?&lt;/P&gt;&lt;P&gt;Following below are two identical examples. The first is with DSD, the second without.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Infile with DSD. Record 3 (KEY='C') fails because the string 's Gravenhage,Mataw' leads to one variable;
data work.OPER_A_DSD; 
   infile datalines  delimiter = ","  MISSOVER DSD;
   attrib KEY length = $12; 
   attrib CITY length = $60; 
   attrib NAME length = $50;
   attrib EMPTY length =$1;
   attrib EX length = $1; 
   input KEY CITY NAME EMPTY EX $; 
   put _all_;
datalines;
A,Utrecht,James,,X
B,'s Gravenhage,Scott,N,X
C,'s Gravenhage,Mataw',N,X
D,'s Gravenhage,Mataw',,X
E,'s Gravenhage,Mata'w,,X
;
run; 
* Infile without DSD. Record 1 (KEY='A') fails because 2 cancatenated delimitters (,,) is converted to one. The value X is placed in the variable EMPTY instead of EX;
data work.OPER_A_NODSD; 
   infile datalines  delimiter = ","  MISSOVER ;
   attrib KEY length = $12; 
   attrib CITY length = $60; 
   attrib NAME length = $50;
   attrib EMPTY length =$1;
   attrib EX length = $1; 
   input KEY CITY NAME EMPTY EX $; 
   put _all_;
datalines;
A,Utrecht,James,,X
B,'s Gravenhage,Scott,N,X
C,'s Gravenhage,Mataw',N,X
D,'s Gravenhage,Mataw',,X
E,'s Gravenhage,Mata'w,,X
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Mar 2018 12:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445805#M111766</guid>
      <dc:creator>RonaldHof</dc:creator>
      <dc:date>2018-03-15T12:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445811#M111772</link>
      <description>&lt;P&gt;Neither of these are valid CSV files.&amp;nbsp; If a CSV file's data item contains a quote, then the whole column should be enclosed in quotes (preferably double to avoid single quotes):&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;A,"Utrecht,James",,X
B,"'s Gravenhage,Scott",N,X
C,"'s Gravenhage,Mataw'",N,X
D,"'s Gravenhage,Mataw'",,X
E,"'s Gravenhage,Mata'w",,X&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Fix the export of data would be my suggestion.&amp;nbsp; Otherwise you would need to do some parsing on the file yourself.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 12:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445811#M111772</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-15T12:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445819#M111776</link>
      <description>&lt;P&gt;Thanks RW9 but I do not have the possibility to change the export to a 'valid' CSV. It is delivered by an external party. What is a 'valid' CSV file. I don't think there is a formal definition regulating the form of a CSV-file. Therefore there are a lot of variations in CSV-files. Parsing is an alternative but that's the last rescue I want to use. SAS can read 'everything' so I hope there is a better solution.&lt;/P&gt;&lt;P&gt;Ronald&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 13:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445819#M111776</guid>
      <dc:creator>RonaldHof</dc:creator>
      <dc:date>2018-03-15T13:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445821#M111778</link>
      <description>&lt;P&gt;One possibility would be to correct the file on the fly. e.g.:&lt;/P&gt;
&lt;PRE&gt;data work.OPER_A_NODSD;
  input @;
  _infile_= translate(_infile_,'~',"'");
   infile datalines  delimiter = "," dsd MISSOVER ;
   attrib KEY length = $12; 
   attrib CITY length = $60; 
   attrib NAME length = $50;
   attrib EMPTY length =$1;
   attrib EX length = $1; 
   input KEY CITY NAME EMPTY EX $; 
   city=translate(city,"'",'~');
   name=translate(name,"'",'~');
   put _all_;
datalines;
A,Utrecht,James,,X
B,'s Gravenhage,Scott,N,X
C,'s Gravenhage,Mataw',N,X
D,'s Gravenhage,Mataw',,X
E,'s Gravenhage,Mata'w,,X
;
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 13:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445821#M111778</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-15T13:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445828#M111784</link>
      <description>Hi:&lt;BR /&gt;  Aside from all other issues, how do you envision the row for E to be read? Do you envision it like this:&lt;BR /&gt;Key=E&lt;BR /&gt;City='s Granvenhage&lt;BR /&gt;Name=Mata'w&lt;BR /&gt;Empty=(blank)&lt;BR /&gt;EX = X&lt;BR /&gt;&lt;BR /&gt;Do you eventually want to strip the single quotes out of the variable values, are they correct? Are they incorrect? Are the quotes in the file like this ALWAYS single quotes?&lt;BR /&gt;&lt;BR /&gt;cynthia&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Mar 2018 13:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445828#M111784</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-03-15T13:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445838#M111789</link>
      <description>&lt;P&gt;&lt;A href="https://en.wikipedia.org/wiki/Comma-separated_values" target="_blank"&gt;https://en.wikipedia.org/wiki/Comma-separated_values&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;RFC-4180&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, irrespective of a standard or not, you need to have in the data some clear way of identifying when a quote or delimiter is part of a variable or is a quote or delimiter.&lt;/P&gt;
&lt;P&gt;In this instance:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;A,Utrecht,James,,X
B,'s Gravenhage,Scott,N,X
C,'s Gravenhage,Mataw',N,X
D,'s Gravenhage,Mataw',,X
E,'s Gravenhage,Mata'w,,X&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;'s Gravenhage,Scott - is the comma part of the text or a delimiter?&amp;nbsp; You may be able to look at this and make some decision, however to write a generic import to cover these types of things is pretty difficult - your assumption is not going to be universal.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 13:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445838#M111789</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-15T13:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445839#M111790</link>
      <description>&lt;P&gt;Hey Cyntia,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your assumption is correct. Variable EMPTY shout be missing and EX the value 'X'. The first dataset with DSD reads this record correct in because there is a character between quote and the delimiter (letter w). Without DSD it goes wrong in my example because the value 'X' appears in EMPTY.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 14:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445839#M111790</guid>
      <dc:creator>RonaldHof</dc:creator>
      <dc:date>2018-03-15T14:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445841#M111792</link>
      <description>&lt;P&gt;I forgot something. The single quotes are part of the delivered data and shoud not be skipped.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 14:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445841#M111792</guid>
      <dc:creator>RonaldHof</dc:creator>
      <dc:date>2018-03-15T14:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445842#M111793</link>
      <description>&lt;P&gt;There is a standard, RCF-4180.&amp;nbsp; &amp;nbsp;&lt;A href="https://www.ietf.org/rfc/rfc4180.txt" target="_blank"&gt;https://www.ietf.org/rfc/rfc4180.txt&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only change from that you need to tell them to make is to not send any end of line markers in the value of character variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 14:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445842#M111793</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-15T14:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445845#M111795</link>
      <description>&lt;P&gt;Did you try the solution I proposed? I think it does what you want!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 14:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445845#M111795</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-15T14:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445847#M111796</link>
      <description>&lt;P&gt;Hi Art,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Parsing every file, what you suggest,will work but is not what I want. Only as a last rescue. Reason for that is that the solution must be implemented in the File Reader transformation in SAS/DI Studio. That is possible but than you have created for every External File that you ant to read a user writen code. Within the File Reader it is not possible to parse then _infile_ lines. That is why I hope that there is an other option in f.i. the infile statement that I can use.&lt;/P&gt;&lt;P&gt;Ronald&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 14:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445847#M111796</guid>
      <dc:creator>RonaldHof</dc:creator>
      <dc:date>2018-03-15T14:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445849#M111797</link>
      <description>&lt;P&gt;If you want to process without DSD option then add a period between the adjacent commas.&amp;nbsp; Here is how you could do it in the data step that reads the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one ;
  infile cards dlm=',' truncover ;
  input @;
  if _infile_=:',' then _infile_='.'||_infile_;
  do while (index(_infile_,',,'));_infile_=tranwrd(_infile_,',,',',.,'); end;
  input (x1-x6) (:$20.) ;
  put _infile_ @40 (x1-x6) (=) ;
cards4;
A,Utrecht,James,,X
B,'s Gravenhage,Scott,N,X
C,'s Gravenhage,Mataw',N,X
D,'s Gravenhage,Mataw',,X
E,'s Gravenhage,Mata'w,,X
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to use the DSD option then you need to convert those single quotes into something else so that values that start with a single quote don't cause it hunt for the closing quote. You could translate the quotes to something else and then process all of your character variables to reverse the translation. Make sure to use a character that is not in your data file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one ;
  infile cards dsd  truncover ;
  input @;
  _infile_=translate(_infile_,"`","'");
  input (x1-x6) (:$20.) ;
  array _c _character_;
  do over _c; _c=translate(_c,"'","`"); end;
  put _infile_ @40 (x1-x6) (=) ;
cards4;
A,Utrecht,James,,X
B,'s Gravenhage,Scott,N,X
C,'s Gravenhage,Mataw',N,X
D,'s Gravenhage,Mataw',,X
E,'s Gravenhage,Mata'w,,X
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Mar 2018 14:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445849#M111797</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-15T14:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445851#M111799</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;I see, there is some kind of standard. Next problem is how quick I can motivate the data-deliverer to change this export. That takes a lot of time because this export-format is used by a lot of customers.&lt;/P&gt;&lt;P&gt;'S Gravenhage&amp;nbsp; (with the quote) is the name of a city in the Netherlands. The comma is the delimiter so Scott is the value of the third column.&lt;/P&gt;&lt;P&gt;Ronald&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 14:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445851#M111799</guid>
      <dc:creator>RonaldHof</dc:creator>
      <dc:date>2018-03-15T14:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445854#M111800</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;This is a solution but difficult to implement in the File Reader in SAS/DI Studio. Most of the replies I get suggest to parse the file with the _infile_ buffer. Not ideal but maybe there is not an other solution.&lt;/P&gt;&lt;P&gt;Ronald&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 14:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445854#M111800</guid>
      <dc:creator>RonaldHof</dc:creator>
      <dc:date>2018-03-15T14:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: INFILE problem in combination with DSD when reading CSV with quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445879#M111809</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/7541"&gt;@RonaldHof&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;This is a solution but difficult to implement in the File Reader in SAS/DI Studio. Most of the replies I get suggest to parse the file with the _infile_ buffer. Not ideal but maybe there is not an other solution.&lt;/P&gt;
&lt;P&gt;Ronald&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Will DI studio allow you to create a code step that you could use to create a corrected version of the file that you could then read using normal process?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 16:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INFILE-problem-in-combination-with-DSD-when-reading-CSV-with/m-p/445879#M111809</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-15T16:01:12Z</dc:date>
    </item>
  </channel>
</rss>

