<?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: How to read in from an external data file in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17783#M3423</link>
    <description>Please clarify "the problem still didn’t go away" - share your actual SAS log output for a run where you had firstobs=2.  Also, consider adding either or both of these SAS debugging statements for some self-initiated desk-checking:&lt;BR /&gt;
&lt;BR /&gt;
LIST;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Tue, 21 Jun 2011 02:37:13 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2011-06-21T02:37:13Z</dc:date>
    <item>
      <title>How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17782#M3422</link>
      <description>I wanted to read it an external dataset (&amp;gt;100,000 records). It is tab delimited, with missing variables entered as “.”. I could read in fine if I use dataline. (The data was aligned fine in SAS, but appear misaligned here. &lt;BR /&gt;
data want;&lt;BR /&gt;
    input  Year 1-4 date 6-14 Type $ 16-20 ID1 $ 22-30 ID2 $32-41 Status1 $ 43 status2 $ 45-46 amount 47-51;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008 .         ACUT1 580035688 0093509933 A EP 1&lt;BR /&gt;
2009 01-Jun-08 ACUT2 506920875 7294393694 B FP 7&lt;BR /&gt;
2009 13-Apr-09 ACUT3 506925992 7863803113 C AC 10&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
But if I read in from an external file, it is giving me error messages. The first row has variable names. I tried using firstobs=2 or removing the first line, but the problem still didn’t go away. I also tried missover or not specifying column numbers, etc., and still didn't help.&lt;BR /&gt;
&lt;BR /&gt;
DATA want;&lt;BR /&gt;
     INFILE "D:\data.txt" ;&lt;BR /&gt;
    input  Year 1-4 date date9. 6-14 Type $ 16-20 ID1 $ 22-30 ID2 $32-41 Status1 $ 43 status2 $ 45-46 amount 47-51;&lt;BR /&gt;
run;&lt;BR /&gt;
**************************************************************;&lt;BR /&gt;
Data in the external file "Data.txt"&lt;BR /&gt;
Year   date  type     ID1        ID2      Status1     Status2   amount&lt;BR /&gt;
2008 .         ACUT1 580035688 0093509933 A EP 1&lt;BR /&gt;
2009 01-Jun-08 ACUT2 506920875 7294393694 B FP 7&lt;BR /&gt;
2009 13-Apr-09 ACUT3 506925992 7863803113 C AC 10&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks very much in advance.</description>
      <pubDate>Mon, 20 Jun 2011 22:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17782#M3422</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2011-06-20T22:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17783#M3423</link>
      <description>Please clarify "the problem still didn’t go away" - share your actual SAS log output for a run where you had firstobs=2.  Also, consider adding either or both of these SAS debugging statements for some self-initiated desk-checking:&lt;BR /&gt;
&lt;BR /&gt;
LIST;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 21 Jun 2011 02:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17783#M3423</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-06-21T02:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17784#M3424</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
You're saying your data is tab delimited but the code you've posed uses fixed width.&lt;BR /&gt;
&lt;BR /&gt;
May be you have to amend your infile statement.&lt;BR /&gt;
&lt;BR /&gt;
With SAS EG you could use the import wizard (file/import data) which should help you to create valid code. Just make sure that in the first screen of the import wizard (EG 4.3, not sure about other versions) you click button "performance..." and then check "limit amount of source data examined..." and choose something like a 100 lines. Else the whole file will be analysed which could take a while.&lt;BR /&gt;
&lt;BR /&gt;
You can then in later screens changes the length, format and informat of your variables according to what you expect them to be.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Tue, 21 Jun 2011 03:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17784#M3424</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-06-21T03:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17785#M3425</link>
      <description>Duplicate post removed</description>
      <pubDate>Tue, 21 Jun 2011 03:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17785#M3425</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-06-21T03:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17786#M3426</link>
      <description>How about:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
INFILE "D:\data.txt" expandtabs firstobs=2;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 21 Jun 2011 05:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17786#M3426</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-06-21T05:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17787#M3427</link>
      <description>Just had time to thanks you all for the replies.&lt;BR /&gt;
&lt;BR /&gt;
Tried Infile ... EXPANDTABS FIRSTOBS=2 and it didn't work.&lt;BR /&gt;
Tried importing using SAS EG (I think mine is 4.3), but I didn't see the option of "performance..." and "limit amount of source data examined...".&lt;BR /&gt;
&lt;BR /&gt;
I found a way to read in data from tab delimited files using DELIMITER='09'x though.&lt;BR /&gt;
&lt;BR /&gt;
DATA want;&lt;BR /&gt;
LENGTH type $5. ID1 $9. ID2 $10. date $9.;&lt;BR /&gt;
INFILE "D:\data.txt"  DELIMITER='09'x FIRSTOBS=2 MISSOVER;&lt;BR /&gt;
INPUT Year date $  Type $ ID1 $ ID2 $ Status1 $ status2 $ amount;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
There are a few issues though.&lt;BR /&gt;
1. In SAS Base, defining DATE as a string variable is the only way I could read in the data without any error and MISSOVER in or out doesn't matter. I tried in the INPUT statement DATE date9., but it gave me errors instead. &lt;BR /&gt;
2. In SAS EG (available at work), if I recall correctly it I could define DATE as a date format fine, but it gave me warning or error messages on records with missing date variable. Fortunately there are only 17 cases and I just gave them up.&lt;BR /&gt;
&lt;BR /&gt;
If anyone has quick answers, let me know. Otherwise I'll just live with the errors. It's quite exhausting reading in data. Thanks.</description>
      <pubDate>Thu, 23 Jun 2011 01:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17787#M3427</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2011-06-23T01:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17788#M3428</link>
      <description>Hi &lt;BR /&gt;
&lt;BR /&gt;
You probabely should use an INFORMAT to read your date strings.&lt;BR /&gt;
&lt;BR /&gt;
input date:date9.     .....;&lt;BR /&gt;
&lt;BR /&gt;
or:&lt;BR /&gt;
data ....&lt;BR /&gt;
attrib date format=date9. informat=date9.;&lt;BR /&gt;
&lt;BR /&gt;
input date         .....&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
For cases where there is no data in a cell and you might have two consecutive tabs. In order to avoid issues you might want to add 'DSD' to your infile statement:&lt;BR /&gt;
&lt;BR /&gt;
INFILE "D:\data.txt" DSD DELIMITER='09'x FIRSTOBS=2 TRUNCOVER;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 23 Jun 2011 02:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17788#M3428</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-06-23T02:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17789#M3429</link>
      <description>Thanks Both worked and there is no need to specify variable length or to use DSD TRUNCOVER.&lt;BR /&gt;
1)&lt;BR /&gt;
DATA want;&lt;BR /&gt;
format date date9.;&lt;BR /&gt;
INFILE "D:\data.txt" DELIMITER='09'x FIRSTOBS=2 MISSOVER;&lt;BR /&gt;
INPUT Year date:date9. Type $ ID1 $ ID2 $ Status1 $ status2 $ amount;&lt;BR /&gt;
RUN;&lt;BR /&gt;
2)&lt;BR /&gt;
DATA want;&lt;BR /&gt;
ATTRIB  date format=date9. informat=date9.;&lt;BR /&gt;
INFILE "D:\data.txt" DELIMITER='09'x FIRSTOBS=2 MISSOVER;&lt;BR /&gt;
INPUT Year date $ Type $ ID1 $ ID2 $ Status1 $ status2 $ amount;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
I have another question though. For some reasons if the value for AMOUNT exceeds 999, the data becomes a comma style with quotes wrapped around say "13,099" instead of just 13099. Is there is a quick way to fix it? Or I'll have to open the text file to replace " with Null and use the comma format(?)? Or read in as a text variable and get rid of the quotes and commas before converting it into a numerical variable?</description>
      <pubDate>Thu, 23 Jun 2011 05:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17789#M3429</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2011-06-23T05:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17790#M3430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DSD option will take care of&amp;nbsp; this situation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Jun 2011 05:21:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17790#M3430</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-06-24T05:21:52Z</dc:date>
    </item>
    <item>
      <title>How to read in from an external data file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17791#M3431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Add the DSD option on the INFILE statement to handle the quotes.&lt;/P&gt;&lt;P&gt;Use the COMMA informat for the AMOUNT variable to handle the embedded commas.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Jul 2011 17:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-read-in-from-an-external-data-file/m-p/17791#M3431</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-07-09T17:30:59Z</dc:date>
    </item>
  </channel>
</rss>

