<?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 Getting hung up on a trivial CSV import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398629#M96451</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to import a CSV file. This is the first 5 rows with the header:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ACCTN,PURPOSE,VISIT_DATE,ENTITY,ID
12282,3,7/17/2012,5,API
20083,8,6/12/2012,5,LEO
20082,9,6/12/2012,5,LEO
20129,8,6/14/2012,5,LEO
20063,8,6/14/2012,5,LEO&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is my data step to bring it in:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
  INFILE "C:\test.csv" DLM=',' MISSOVER DSD FIRSTOBS=2;
  INPUT
    ACCTN $
    PURPOSE $
    VISIT_DATE $
    ENTITY $
    ID $;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is the output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 515px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15403i33C6C331B7AF1ECE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VISIT_DATE is cut off.&amp;nbsp; I guess I don't understand how SAS is working here.&amp;nbsp; I thought by specifying the delimiter character it would give the VISIT_DATE field a variable length but it always cuts it off at 8 length.&amp;nbsp; When I try changing the length to 10 it moves past the delimiter into the other field.&amp;nbsp; So I guess SAS can only read fixed width files?&amp;nbsp; What am I missing here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Sep 2017 17:34:57 GMT</pubDate>
    <dc:creator>tomcmacdonald</dc:creator>
    <dc:date>2017-09-25T17:34:57Z</dc:date>
    <item>
      <title>Getting hung up on a trivial CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398629#M96451</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to import a CSV file. This is the first 5 rows with the header:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ACCTN,PURPOSE,VISIT_DATE,ENTITY,ID
12282,3,7/17/2012,5,API
20083,8,6/12/2012,5,LEO
20082,9,6/12/2012,5,LEO
20129,8,6/14/2012,5,LEO
20063,8,6/14/2012,5,LEO&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is my data step to bring it in:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
  INFILE "C:\test.csv" DLM=',' MISSOVER DSD FIRSTOBS=2;
  INPUT
    ACCTN $
    PURPOSE $
    VISIT_DATE $
    ENTITY $
    ID $;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is the output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 515px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15403i33C6C331B7AF1ECE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VISIT_DATE is cut off.&amp;nbsp; I guess I don't understand how SAS is working here.&amp;nbsp; I thought by specifying the delimiter character it would give the VISIT_DATE field a variable length but it always cuts it off at 8 length.&amp;nbsp; When I try changing the length to 10 it moves past the delimiter into the other field.&amp;nbsp; So I guess SAS can only read fixed width files?&amp;nbsp; What am I missing here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 17:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398629#M96451</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2017-09-25T17:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting hung up on a trivial CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398630#M96452</link>
      <description>&lt;P&gt;Adding a length statement seems to do the trick&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA TEST;
  INFILE 'C:\test.csv' DLM=',' MISSOVER DSD FIRSTOBS=2;
  LENGTH VISIT_DATE $10;
  INPUT
    ACCTN $
    PURPOSE $
    VISIT_DATE $
    ENTITY $
    ID $;
RUN;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Sep 2017 17:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398630#M96452</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2017-09-25T17:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Getting hung up on a trivial CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398631#M96453</link>
      <description>&lt;P&gt;Without specific guidance from you SAS is assuming all the character vars are length $8.&amp;nbsp; You could change the&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; VISIT_DATE $&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;line to&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; VISIT_DATE :$10.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;telling SAS that visitdate can be up to 10 characters long.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you might want to convert it to a true date value, in which case use&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; VISIT_DATE :mmddyy10.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;accompanied elsewhere by a&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; format visit_date date9. ;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;statement&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 17:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398631#M96453</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-25T17:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Getting hung up on a trivial CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398637#M96454</link>
      <description>&lt;P&gt;That works too.&amp;nbsp; I guess the semicolon is a modifier to the length portion of the statement.&amp;nbsp; I sure do wish the documentation specified this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#chifoptfmain.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#chifoptfmain.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 17:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398637#M96454</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2017-09-25T17:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Getting hung up on a trivial CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398666#M96458</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142145"&gt;@tomcmacdonald&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;That works too.&amp;nbsp; I guess the semicolon is a modifier to the length portion of the statement.&amp;nbsp; I sure do wish the documentation specified this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#chifoptfmain.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#chifoptfmain.htm&lt;/A&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you use formatted mode input like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input visit_date mmddyy10. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then SAS will read EXACTLY the number of characters you specify in the informat.&lt;/P&gt;
&lt;P&gt;If you use list mode input&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input var1 var2 var3 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then SAS will use the number of characters that exist in the data line between the two delimiters.&lt;/P&gt;
&lt;P&gt;You have used a mixed mode that is a combination of reading some variables using list mode and one variable using formattted mode.&lt;/P&gt;
&lt;P&gt;Using the colon modifier allows you to specify an informat in the INPUT statement and still parse the line using normal list mode style. &amp;nbsp;This is called modified list mode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also just remove the informat from the INPUT statement and instead use an INFORMAT statement (or ATTRIB) statement to tell SAS what informat to use when reading the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general you will get better results if you define your variables before you use them. That is, do not force SAS to guess from how you first use the variable, whether in an INPUT, FORMAT, INFORMAT and assignment statement what type and length your variable should have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your program look like this instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  infile "c:\test.csv" dsd truncover firstobs=2;
  length acctn $8 purpose $8 visit_date 8 entity $8 id $8;
  input acctn--id;
  informat visit_date mmddyy. ;
  format visit_date yymmdd10. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    acctn    purpose    visit_date    entity    id

 1     12282       3       2012-07-17       5      API
 2     20083       8       2012-06-12       5      LEO
 3     20082       9       2012-06-12       5      LEO
 4     20129       8       2012-06-14       5      LEO
 5     20063       8       2012-06-14       5      LEO&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Sep 2017 20:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398666#M96458</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-25T20:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Getting hung up on a trivial CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398689#M96463</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142145"&gt;@tomcmacdonald&lt;/a&gt;&amp;nbsp;That's the documentation reference for the INFILE statement. The colon is used on the INPUT statement and it is documented under INPUT, LIST. I do kinda wish there weren't 5 (?) different pages for the INPUT statement though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#n0lrz3gb7m9e4rn137op544ddg0v.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#n0lrz3gb7m9e4rn137op544ddg0v.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - when all else fails with reading in a text file use PROC IMPORT with a large value for GUESSINGROWS and check the log for the code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 00:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-hung-up-on-a-trivial-CSV-import/m-p/398689#M96463</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-26T00:19:48Z</dc:date>
    </item>
  </channel>
</rss>

