<?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: Data import with delimiter in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905880#M44013</link>
    <description>&lt;P&gt;Ideally such strings are in quotes. For a .csv that's "standard".&lt;/P&gt;
&lt;P&gt;Here two options - if neither of them work then you need to tells us in detail how we could identify "fake" delimiters&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  infile datalines dsd truncover;
  Input No Company :$20. Type :$2.;
Datalines;
1,"Barata,PT",A
2,Riley,A
3,,B
;

data demo;
  infile datalines dsd truncover;
  Input @;
  if countc(_infile_,',')=2 then
    do;
      input No Company :$20. Type :$2.;
    end;
  else
    do;
      input No _c1 :$20. _c2 :$20. Type :$2.;
      Company=catx(',',_c1,_c2);
      drop _c:;
    end;
Datalines;
1,Barata,PT,A
2,Riley,A
3,,B
;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Dec 2023 08:02:11 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-12-03T08:02:11Z</dc:date>
    <item>
      <title>Data import with delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905877#M44012</link>
      <description>Hi All,&lt;BR /&gt;Currently I'm working to import data that contain (",") as a delimiter.&lt;BR /&gt;Since the source data is coming from txt format then I'm using infile and setting the format, and it works.&lt;BR /&gt;But apparently, some data has a "fake" delimiter which it should be not counted as a delimiter value.&lt;BR /&gt;Can you please to help me to solve the issue?&lt;BR /&gt;&lt;BR /&gt;Here's the sample data:&lt;BR /&gt;Data test;&lt;BR /&gt;Delimiter=' , ' ;&lt;BR /&gt;Input No Company Type;&lt;BR /&gt;Datalines;&lt;BR /&gt;1,Barata,PT,A&lt;BR /&gt;2,Riley,A&lt;BR /&gt;3,,B&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;The expectation Barata,PT shouldn't being divided into 2 cells.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 03 Dec 2023 06:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905877#M44012</guid>
      <dc:creator>Ata62439</dc:creator>
      <dc:date>2023-12-03T06:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Data import with delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905880#M44013</link>
      <description>&lt;P&gt;Ideally such strings are in quotes. For a .csv that's "standard".&lt;/P&gt;
&lt;P&gt;Here two options - if neither of them work then you need to tells us in detail how we could identify "fake" delimiters&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  infile datalines dsd truncover;
  Input No Company :$20. Type :$2.;
Datalines;
1,"Barata,PT",A
2,Riley,A
3,,B
;

data demo;
  infile datalines dsd truncover;
  Input @;
  if countc(_infile_,',')=2 then
    do;
      input No Company :$20. Type :$2.;
    end;
  else
    do;
      input No _c1 :$20. _c2 :$20. Type :$2.;
      Company=catx(',',_c1,_c2);
      drop _c:;
    end;
Datalines;
1,Barata,PT,A
2,Riley,A
3,,B
;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Dec 2023 08:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905880#M44013</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-03T08:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Data import with delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905916#M44014</link>
      <description>&lt;P&gt;Your code as written cannot work since all you did was define a variable named DELIMITER that has ',' as the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To change the delimiter used when reading lines you need to use an INFILE statement.&amp;nbsp; You can use INFILE DATALINES to read from the in-line data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for the example lines you showed that will still not work because the line does not have quotes around the embedded delimiter. (What you called a fake delimiter).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the DSD option then SAS will allow quotes around a value to hide the "fake" delimiters and automatically remove those quotes from the value.&amp;nbsp; &amp;nbsp;The DSD option will also make comma the default delimiter.&amp;nbsp; And it will also treat adjacent delimiters (like in your last example line) as indicating a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you can fix your source data to be properly formatted then code like this will work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  infile datalines dsd truncover;
  Input No Company :$20. Type :$1.;
Datalines;
1,"Barata,PT",A
2,Riley,A
3,,B
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you cannot fix source data to properly quote the embedded delimiters it will be extremely difficult to parse the lines into the fields you want to read.&amp;nbsp; If , as in your example, there is only ONE field that could possibly have the embedded delimiter then you should be able to read it with some extra logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way based on knowing that you expect three fields on each line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  infile datalines dsd truncover;
  length No 8 Company $20 Type $1 ;
  input No Company :$20. @ ;
  do counter=1 to countw(_infile_,',','q')-3 ;
    input extra :$20. @;
    company=catx(',',company,extra);
  end;
  input Type :$1.;
  drop counter extra;
datalines;
1,Barata,PT,A
2,Riley,A
3,,B
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Dec 2023 20:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905916#M44014</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-03T20:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Data import with delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905930#M44015</link>
      <description>Yes agree, ideally there's should be a quote string. And this quote string has been in place on typing the address. As for company or other field name (which I'm not identified it yet) doesn't have any quote string at all.&lt;BR /&gt;But I get your point, thank you for helping and giving me an insight</description>
      <pubDate>Mon, 04 Dec 2023 02:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905930#M44015</guid>
      <dc:creator>Ata62439</dc:creator>
      <dc:date>2023-12-04T02:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Data import with delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905931#M44016</link>
      <description>I think it will never been solved either until the source data has been fixed by putting the quote string.&lt;BR /&gt;I have been searching for an article related to this and none can fix it thru the syntax.&lt;BR /&gt;Thanks Tom for your explanation, it really helps</description>
      <pubDate>Mon, 04 Dec 2023 02:21:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905931#M44016</guid>
      <dc:creator>Ata62439</dc:creator>
      <dc:date>2023-12-04T02:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Data import with delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905932#M44017</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Your question is very complicated,
You need to know which variable has this extra delimiter .
*/
data demo;
input;
call scan(_infile_,1,p1,l1,',','mq');
call scan(_infile_,-1,p2,l2,',','mq');
length no company type $ 200;
no=substrn(_infile_,p1,l1);
company=substrn(_infile_,p1+l1+1,p2-p1-l1-2);
type=substrn(_infile_,p2);
keep no company type;
Datalines;
1,Barata,PT,A
2,Riley,A
3,,B
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Dec 2023 02:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Data-import-with-delimiter/m-p/905932#M44017</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-12-04T02:26:31Z</dc:date>
    </item>
  </channel>
</rss>

