<?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 a csv file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246113#M45999</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its probab;y a good idea to explain what is "not right" about the output. &amp;nbsp;For your code:&lt;/P&gt;
&lt;PRE&gt;data NV; 
  infile 'path\NVM_Data.csv' dsd firstobs =2 ; 
  input Item_Id Market_Id $ date mmddyy10. Sales Season XX YY ZZZ Age PlugIn D DM Scrap FPR RPR CP EP GP FP ST LC; &lt;BR /&gt;  format date mmddyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;You could try something like this:&lt;/P&gt;
&lt;PRE&gt;data NV; 
  infile 'path\NVM_Data.csv' dsd firstobs=2;&lt;BR /&gt;  informat date mmddyy10.;
  input Item_Id Market_Id $ date Sales Season XX YY ZZZ Age PlugIn D DM Scrap FPR RPR CP EP GP FP ST LC; &lt;BR /&gt;  format date mmddyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;But its hard to say without knowing what "is wrong"?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jan 2016 16:10:15 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-01-26T16:10:15Z</dc:date>
    <item>
      <title>Reading a csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246111#M45998</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to use the in-file statement to read a csv file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the code I've written is :&lt;/P&gt;
&lt;P&gt;data NV; infile 'path\NVM_Data.csv' dsd firstobs =2 ; input Item_Id Market_Id $ date mmddyy10. Sales Season XX YY ZZZ Age PlugIn D DM Scrap FPR RPR CP EP GP FP ST LC; format date mmddyy10.; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when I run the above program, the data doesn't get read properly.&lt;/P&gt;
&lt;P&gt;I've attached the input data (test.csv) and the output (output.csv) for your reference. The output clearly shows that SAS isn't reading the data correctly. Can you help?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Nimish&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS - the files that I'm trying to read are in csv format. But since, I'm unable to&amp;nbsp;upload them, I've saved&amp;nbsp;them in&amp;nbsp;excel format.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246111#M45998</guid>
      <dc:creator>Nimish_Vaddiparti</dc:creator>
      <dc:date>2016-01-26T16:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246113#M45999</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its probab;y a good idea to explain what is "not right" about the output. &amp;nbsp;For your code:&lt;/P&gt;
&lt;PRE&gt;data NV; 
  infile 'path\NVM_Data.csv' dsd firstobs =2 ; 
  input Item_Id Market_Id $ date mmddyy10. Sales Season XX YY ZZZ Age PlugIn D DM Scrap FPR RPR CP EP GP FP ST LC; &lt;BR /&gt;  format date mmddyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;You could try something like this:&lt;/P&gt;
&lt;PRE&gt;data NV; 
  infile 'path\NVM_Data.csv' dsd firstobs=2;&lt;BR /&gt;  informat date mmddyy10.;
  input Item_Id Market_Id $ date Sales Season XX YY ZZZ Age PlugIn D DM Scrap FPR RPR CP EP GP FP ST LC; &lt;BR /&gt;  format date mmddyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;But its hard to say without knowing what "is wrong"?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246113#M45999</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-26T16:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246118#M46002</link>
      <description>&lt;P&gt;Hi Nimish,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, the primary issue is that you forgot to specify the delimiter in the INFILE statement: dlm=';' (if semicolon is in fact the delimiter).&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246118#M46002</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-26T16:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246124#M46004</link>
      <description>&lt;P&gt;Change the extension on your CSV to .txt and upload that file please.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246124#M46004</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-26T16:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246126#M46005</link>
      <description>&lt;P&gt;Since CSV generally means at least some of the variables are differing lengths you seldom want to have the formats on the input statement as then SAS reads the length&amp;nbsp; specified by the format for every field. This behavior was very typical and the desired default when one of the main ways to deal with data was in fixed columns.&lt;/P&gt;
&lt;P&gt;So specify the INFORMATS before the INPUT and leave them out of the input statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NV; 
   infile 'path\NVM_Data.csv' dsd firstobs =2 ; 
   informat Market_Id $10. ;  /* You want to make sure that the width is set long enough for your largest expected value*/
   informat date mmddyy10. ;
   input Item_Id Market_Id  date  Sales Season XX YY ZZZ Age PlugIn D DM Scrap FPR RPR CP EP GP FP ST LC; 
   format date mmddyy10.; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another possibly problem is using $ as that defaults to 8 and you may have needed more characters. If I'm told that a field is supposed to be a specified length I usually add 1 or 2 to the informat "just in case" and if the value is name&amp;nbsp;or address then often lots more additional characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246126#M46005</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-26T16:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246132#M46009</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;pointed at, DSD considers the comma as the default list delimeter, even if it's not the case in your culture. Check your CSV file and tell SAS what the list delimiter character is in your file, if not the comma.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 16:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246132#M46009</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-26T16:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246146#M46020</link>
      <description>&lt;P&gt;Even if your date&amp;nbsp;field had exactly length 10 in all rows, so that your &lt;EM&gt;formatted input&lt;/EM&gt; "&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;date mmddyy10.&lt;/FONT&gt;" would work, it would cause an issue with the &lt;EM&gt;next&lt;/EM&gt; field to be read (Sales): After reading DATE, the pointer would stop immediately in front of the next delimiter, causing a missing value for SALES. Then, sales values&amp;nbsp;would go into variable SEASON, ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So, please use the colon modifier "&lt;FONT face="courier new,courier"&gt;date &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;:&lt;/STRONG&gt;&lt;/FONT&gt;mmddyy10.&lt;/FONT&gt;" or, alternatively, use the INFORMAT statement (and omit the informat specification in the INPUT statement), as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;,&amp;nbsp;to indicate &lt;EM&gt;modified list input.&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 17:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-csv-file/m-p/246146#M46020</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-26T17:11:42Z</dc:date>
    </item>
  </channel>
</rss>

