<?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: Difficulty with Informat in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396859#M95856</link>
    <description>&lt;P&gt;The first question is an easy one.&amp;nbsp; SAS knows how to read numbers.&amp;nbsp; Just remove COMMA17.15 from the INPUT statement.&amp;nbsp; Without going into the technical details, that's what changes the value on the first observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second question is insurmountable.&amp;nbsp; SAS is storing numerics in 8 bytes, and doing the best it can.&amp;nbsp; Once you get up to around 15 significant digits, SAS doesn't have enough room to store the exact value and loses some precision.&amp;nbsp; A sample program to illustrate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;data &lt;/FONT&gt;&lt;FONT face="Lucida Console" size="2"&gt;_null_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;x=0.996240902217826;&lt;/P&gt;
&lt;P&gt;put x 17.15;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Sep 2017 15:56:02 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-09-18T15:56:02Z</dc:date>
    <item>
      <title>Difficulty with Informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396854#M95852</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to read a file from a text file, which has data separated by spaces. I'm having difficulty reading the 2nd column of numeric values. Some numbers do not have decimal but others have up to 15 decimal points.&lt;/P&gt;
&lt;P&gt;See below for example of data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2017-08-01 1&lt;BR /&gt;2017-07-01 0.996240902217826&lt;BR /&gt;2017-06-01 0.992495935251788&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using the following data step to read this file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;data dataset1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile "&amp;amp;file_location./&amp;amp;file_name." dlm=" " &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;dsd missover firstobs=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data_Month : yymmdd10.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data_Value : comma17.15&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format data_Month &amp;nbsp;&amp;nbsp; &amp;nbsp;DDMMYY8.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data_Value comma17.15;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data read in "dataset1":&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;01/08/17&amp;nbsp;&amp;nbsp; &amp;nbsp;0.000000000000001&lt;BR /&gt;01/07/17&amp;nbsp;&amp;nbsp; &amp;nbsp;0.996240902217820&lt;BR /&gt;01/06/17&amp;nbsp;&amp;nbsp; &amp;nbsp;0.992495935251780&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am running into two problems:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;When the data value in 2nd column is just an integer, it is incorrectly read as a very small value. For example, "1" is read as "&amp;nbsp;0.000000000000001". How do I fix this?&lt;/LI&gt;
&lt;LI&gt;Also, for decimal values, the very last decimal point is not read. For example, the value "0.99624090221782&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;6&lt;/STRONG&gt;&lt;/FONT&gt;" is read as "0.99624090221782&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/FONT&gt;"&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Can you please guide me what I may be doing wrong?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 15:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396854#M95852</guid>
      <dc:creator>asimraja</dc:creator>
      <dc:date>2017-09-18T15:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with Informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396858#M95855</link>
      <description>&lt;P&gt;You have two issues going on. First is when you place a format on an input statement the format will be applied to the data and treating the data a fixed column in the width specified. Which does not work well when the lengths of your variables changes.&lt;/P&gt;
&lt;P&gt;Fix is a separate informat statement:&lt;/P&gt;
&lt;PRE&gt;data dataset1;
    infile "&amp;amp;file_location./&amp;amp;file_name." dlm=" " 
        dsd missover firstobs=1;
    informat 
        data_Month  yymmdd10.
        data_Value  17.15
        ;
    input 
        data_Month
        data_Value
        ;&lt;/PRE&gt;
&lt;P&gt;Second is the limit of precision that SAS has for storing&amp;nbsp;decimal values and 16 is the limit. but your informat only said to read 15 decimal places.&amp;nbsp;So try an informat of 18.16. Note that SAS does not really treat commas in decimal portions as valid so no reason to use comma unless you are reading values greater than 999.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 15:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396858#M95855</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-18T15:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with Informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396859#M95856</link>
      <description>&lt;P&gt;The first question is an easy one.&amp;nbsp; SAS knows how to read numbers.&amp;nbsp; Just remove COMMA17.15 from the INPUT statement.&amp;nbsp; Without going into the technical details, that's what changes the value on the first observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second question is insurmountable.&amp;nbsp; SAS is storing numerics in 8 bytes, and doing the best it can.&amp;nbsp; Once you get up to around 15 significant digits, SAS doesn't have enough room to store the exact value and loses some precision.&amp;nbsp; A sample program to illustrate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;data &lt;/FONT&gt;&lt;FONT face="Lucida Console" size="2"&gt;_null_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;x=0.996240902217826;&lt;/P&gt;
&lt;P&gt;put x 17.15;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 15:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396859#M95856</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-18T15:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with Informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396868#M95860</link>
      <description>&lt;P&gt;Do NOT specify decimal places on an INFORMAT, unless you want SAS to insert an implied decimal point when none is supplied in the input stream. &amp;nbsp;Try this example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input x 5.2 ;
  put x=Z5.2 ' Source=' _infile_;
cards;
123
2.3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also in general never use MISSOVER, instead use the newer and improved TRUNCOVER option. &amp;nbsp;With MISSOVER if you try to read 17 characters and the line only has 15 then you get a missing value. With TRUNCOVER SAS will just use the available characters. Your program is ok as is because you added the : modifier which will make SAS change the width of the informat to match the width of the available data stream.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your numbers are changing because you have exceeded the maximum number of digits that can be guaranteed to be exactly represented in IEEE 64 bit floating point numbers.&lt;/P&gt;
&lt;PRE&gt;75    data test;
76       x= constant('exactint') ;
77       put x comma23. ;
78    run;

  9,007,199,254,740,992
&lt;/PRE&gt;
&lt;P&gt;If you want to read the data then use code like this and just undestand that &amp;nbsp;some numbers will be truncated to fit.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset1;
    infile "&amp;amp;file_location./&amp;amp;file_name." truncover ;
    input 
        data_Month : yymmdd.
        data_Value : comma.
    ;
    format 
        data_Month yymmdd10.
        data_Value 17.15
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2017 16:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/396868#M95860</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-18T16:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with Informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/397100#M95941</link>
      <description>&lt;PRE&gt;
Don't use comma17.15 in INPUT, it will multiply 0.000000000000001 .




data have;
input x : $20. y : best32.;
format y 32.18;
cards;
2017-08-01 1
2017-07-01 0.996240902217826
2017-06-01 0.992495935251788
;
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Sep 2017 13:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/397100#M95941</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-19T13:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulty with Informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/397262#M96004</link>
      <description>&lt;P&gt;Thank you all for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2017 20:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difficulty-with-Informat/m-p/397262#M96004</guid>
      <dc:creator>asimraja</dc:creator>
      <dc:date>2017-09-19T20:55:46Z</dc:date>
    </item>
  </channel>
</rss>

