<?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: Reading in CSV using INFILE and INPUT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572675#M161632</link>
    <description>&lt;P&gt;Either use positions, or a delimiter; using both is redundant and causing problems, as you can see.&lt;/P&gt;
&lt;P&gt;Use this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rep_sur2;
infile datalines delimiter = "," firstobs = 2;
input
  Survey_Name :$11.
  Response_Date :mmddyy10.
  Response_Timestamp :mmddyy10.
;
format
  Response_Date :mmddyy10.
  Response_Timestamp :mmddyy10.
;
datalines;
Survey_Name,Response_Date,Response_Timestamp
p1864475747,07/10/2019,07/10/2019
p1864475747,07/10/2019,07/10/2019
p1864475747,07/10/2019,07/10/2019
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that date values must always be handled as such, using proper data type (numeric), and proper informats/formats.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jul 2019 12:00:51 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-07-11T12:00:51Z</dc:date>
    <item>
      <title>Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572671#M161629</link>
      <description>&lt;P&gt;I'm trying to read a dataset into SAS using the below code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   data REPAIRS.rep_sur2;
   infile 'C:\Name\data.csv' delimiter = "," FIRSTOBS = 2 LRECL=32;
     INPUT
      @1 Survey_Name $11.
      @12 Response_Date $10.
      @22 Response_Timestamp $10.;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But it doesn't seem to recognize that the commas are delimiters as it reads in as below:&lt;/P&gt;&lt;P&gt;Can anyone help me with why this isn't reading in properly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Survey_Name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response_Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response_Timestamp&lt;BR /&gt;p1864475747&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,07/10/201&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9,10 Jul 2&lt;BR /&gt;p1864475747&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,07/10/201&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9,10 Jul 2&lt;BR /&gt;p1864475747&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,07/10/201&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9,10 Jul 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 11 Jul 2019 11:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572671#M161629</guid>
      <dc:creator>manonlyn</dc:creator>
      <dc:date>2019-07-11T11:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572675#M161632</link>
      <description>&lt;P&gt;Either use positions, or a delimiter; using both is redundant and causing problems, as you can see.&lt;/P&gt;
&lt;P&gt;Use this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rep_sur2;
infile datalines delimiter = "," firstobs = 2;
input
  Survey_Name :$11.
  Response_Date :mmddyy10.
  Response_Timestamp :mmddyy10.
;
format
  Response_Date :mmddyy10.
  Response_Timestamp :mmddyy10.
;
datalines;
Survey_Name,Response_Date,Response_Timestamp
p1864475747,07/10/2019,07/10/2019
p1864475747,07/10/2019,07/10/2019
p1864475747,07/10/2019,07/10/2019
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that date values must always be handled as such, using proper data type (numeric), and proper informats/formats.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 12:00:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572675#M161632</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-11T12:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572677#M161634</link>
      <description>&lt;P&gt;Try reading with modified list input rather than formatted input&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data REPAIRS.rep_sur2;
   infile 'C:\Name\data.csv' delimiter = "," FIRSTOBS = 2 LRECL=32;
     INPUT
       Survey_Name : $11.
      Response_Date : $10.
 Response_Timestamp : $10.;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jul 2019 12:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572677#M161634</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-11T12:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572689#M161644</link>
      <description>&lt;P&gt;Thanks this seems to have solved the issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although when I applied this to the whole dataset including 100+ other columns I found another issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below as part of a cell in a free text field&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Very polite engineer and not scared of having a laugh.&lt;BR /&gt;I like them to bring a coverup sheet to minimize the dirt when they do the work.&lt;BR /&gt;That’s what I used to do when I was healthy i used to work as a handyman.&lt;BR /&gt;The risen for this is that people like me disabled person I cannot clean after they live the place.&lt;BR /&gt;Overall great ."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is separated into separate columns instead of all being within the Free Text column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know how to correct this?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 12:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572689#M161644</guid>
      <dc:creator>manonlyn</dc:creator>
      <dc:date>2019-07-11T12:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572719#M161648</link>
      <description>&lt;P&gt;Is it separated into&amp;nbsp;&lt;EM&gt;columns&lt;/EM&gt; or&amp;nbsp;&lt;EM&gt;rows&lt;/EM&gt;?&lt;/P&gt;
&lt;P&gt;A string that contains linefeeds (or CRLF if Windows) is always broken into lines there, and scrambles the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If, OTOH, you only suffer from having delimiters in your long string,&amp;nbsp;&lt;EM&gt;and&amp;nbsp;&lt;/EM&gt;the long string is encapsulated in quotes (as it should be), then the dsd option in the infile statement will handle this.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 13:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572719#M161648</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-11T13:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572721#M161650</link>
      <description>&lt;P&gt;It's separating each sentence into a new column , but the amount of words from the sentence depends on the column length.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think this happens when ALT+ENTER has been used within Excel to write in a cell. I want these sentences to stay within one column if possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the DSD within the infile statement and I still have the same issue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 13:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572721#M161650</guid>
      <dc:creator>manonlyn</dc:creator>
      <dc:date>2019-07-11T13:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572727#M161651</link>
      <description>&lt;P&gt;I'm going to open up in Excel and get rid of the line breaks like that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all your help!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 13:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572727#M161651</guid>
      <dc:creator>manonlyn</dc:creator>
      <dc:date>2019-07-11T13:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572730#M161652</link>
      <description>&lt;P&gt;Please show an example of the actual line from the CSV file that is causing the issue.&lt;/P&gt;
&lt;P&gt;If the value has embedded line breaks then it will create multiple lines in the CSV file and hence multiple observations in the SAS dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do have embedded line breaks and your are lucky enough that the CSV has actual end-of-lines marked with CRLF pairs and the embedded line breaks are just single LF or single CR then you can try adding the TERMSTR=CRLF option to your infile statement.&amp;nbsp; Otherwise you will need to preprocess the CSV file to fix those broken lines.&amp;nbsp; I have posted code to fix that issue many times on this forum.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 13:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572730#M161652</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-11T13:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572733#M161654</link>
      <description>&lt;P&gt;I've posted the actual cell that's caused the issue in the first reply. I think I might have to preprocess the CSV. Thanks for your time looking into this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 13:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572733#M161654</guid>
      <dc:creator>manonlyn</dc:creator>
      <dc:date>2019-07-11T13:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572819#M161671</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/275242"&gt;@manonlyn&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm going to open up in Excel and get rid of the line breaks like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for all your help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Be very careful doing such. Quite often Excel will CHANGE values of a CSV and they will not be correct when saved as CSV.&lt;/P&gt;
&lt;P&gt;If you want to edit CSV files then a text editor, such as WORDPAD or similar, are much safer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Values like "5-1" in a CSV sometimes get interpreted as DATES by Excel. Other oddities depend on cell content.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 16:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572819#M161671</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-11T16:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572824#M161673</link>
      <description>&lt;P&gt;Please go up vote my enhancement request Ballot item.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhancements-to-INFILE-FILE-to-handle-delimited-file-variations/idi-p/435977" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhancements-to-INFILE-FILE-to-handle-delimited-file-variations/idi-p/435977&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 16:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572824#M161673</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-11T16:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in CSV using INFILE and INPUT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572857#M161681</link>
      <description>&lt;P&gt;Done.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 17:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-CSV-using-INFILE-and-INPUT/m-p/572857#M161681</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-11T17:15:12Z</dc:date>
    </item>
  </channel>
</rss>

