<?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 raw data from external files or from datalines written in the program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215494#M39772</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SAS stores numbers as 8 byte floating point numbers.&amp;nbsp; But the length of the informat used when reading from text has nothing to do with the amount of storage that a number takes.&amp;nbsp; The problem the original programmer had was when trying to read more characters (5.) than were available in the input stream.&amp;nbsp; Removing the informat and letting SAS just use the default conversion from digits to numbers would work.&amp;nbsp; Also adding TRUNCOVER to the INFILE statement or putting a colon in front of the INFORMAT (: 5.) would also prevent SAS from trying to read past the end of the line.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 02 Aug 2015 23:39:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2015-08-02T23:39:04Z</dc:date>
    <item>
      <title>Reading raw data from external files or from datalines written in the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215491#M39769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does it matter when SAS reads raw data from external file or from datalines written in program? I thought it makes no difference at first, but I am not sure after I tried the example below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, an external files contains variable-length records:&lt;/P&gt;&lt;P&gt;----+----1----+----2&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;333&lt;/P&gt;&lt;P&gt;4444&lt;/P&gt;&lt;P&gt;55&lt;/P&gt;&lt;P&gt;66666&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The DATA step uses a numeric informat 5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data numbers;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile '/folders/myfolders/Crackman/external files.txt';&lt;/P&gt;&lt;P&gt;&amp;nbsp; input TestNumber 5.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=numbers;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; title 'Test DATA Step on External Files';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When SAS read raw data from external file, the result is:&lt;/P&gt;&lt;P&gt;Obs TestNumber&lt;/P&gt;&lt;P&gt;1 333&lt;/P&gt;&lt;P&gt;2 55&lt;/P&gt;&lt;P&gt;3 55555&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if SAS reads raw data from datalines written in the program, it has different results. &lt;/P&gt;&lt;P&gt;data numbers;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; infile datalines;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input TestNumber 5.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;333&lt;/P&gt;&lt;P&gt;4444&lt;/P&gt;&lt;P&gt;55&lt;/P&gt;&lt;P&gt;66666&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;proc print data=numbers;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; title 'Test DATA Step';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The result is &lt;/P&gt;&lt;P&gt;Obs TestNumber&lt;/P&gt;&lt;P&gt;1 22&lt;/P&gt;&lt;P&gt;2 333&lt;/P&gt;&lt;P&gt;3 4444&lt;/P&gt;&lt;P&gt;4 55&lt;/P&gt;&lt;P&gt;5 66666&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, what makes the difference in the results?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 08:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215491#M39769</guid>
      <dc:creator>MieMie</dc:creator>
      <dc:date>2015-08-02T08:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from external files or from datalines written in the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215492#M39770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When reading from inline data (CARDS or DATALINES) SAS will pad the records to a multiple of 80.&amp;nbsp; I assume that is a side effect of being developed in the 70's using IBM mainframes.&amp;nbsp; They have probably kept it that way to prevent breaking older programs.&amp;nbsp; Try this program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data x ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile cards length=l ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put l=3. +1 _infile_ ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1234567890&lt;/P&gt;&lt;P&gt;123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890&lt;/P&gt;&lt;P&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the TRUNCOVER option on the INFILE statement to make SAS not care if you try to read past the end of the line.&amp;nbsp; Or use the : modifier on the INPUT statement to prevent it from reading more characters than are present.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 14:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215492#M39770</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-08-02T14:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from external files or from datalines written in the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215493#M39771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The number in SAS has always 8 bytes. The use of 5 is for writing out the output data set. So reading into SAS from&lt;/P&gt;&lt;P&gt;TXT file needs no Informat for a number. Try without 5 in your Input Statement. Tom has explained the reading through&lt;/P&gt;&lt;P&gt;datalines statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 15:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215493#M39771</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2015-08-02T15:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from external files or from datalines written in the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215494#M39772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SAS stores numbers as 8 byte floating point numbers.&amp;nbsp; But the length of the informat used when reading from text has nothing to do with the amount of storage that a number takes.&amp;nbsp; The problem the original programmer had was when trying to read more characters (5.) than were available in the input stream.&amp;nbsp; Removing the informat and letting SAS just use the default conversion from digits to numbers would work.&amp;nbsp; Also adding TRUNCOVER to the INFILE statement or putting a colon in front of the INFORMAT (: 5.) would also prevent SAS from trying to read past the end of the line.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 23:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215494#M39772</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-08-02T23:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from external files or from datalines written in the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215495#M39773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks very much for your explanation. However, it didn't answer my question. I guess my question was not clear. Sorry for confusion. Let me re-phrase the question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The same records was stored in different place, an external text file or datalilnes in program. I used the same code to read and print data, and I was expecting the same results since they read from the same records. However, the results were quite different. I was wondering what causes the difference?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Aug 2015 07:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215495#M39773</guid>
      <dc:creator>MieMie</dc:creator>
      <dc:date>2015-08-04T07:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from external files or from datalines written in the program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215496#M39774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first line in my first response explains why they are different.&amp;nbsp; Because SAS treats lines read from an external file differently than it treats lines processed as CARDS you are NOT reading the same data.&amp;nbsp; In the external file there are no trailing blanks after the numbers and when read from CARDS there are.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Aug 2015 12:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-external-files-or-from-datalines-written/m-p/215496#M39774</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-08-04T12:26:16Z</dc:date>
    </item>
  </channel>
</rss>

