<?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: Losing precision in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322643#M271114</link>
    <description>&lt;P&gt;I don't know the answer, but guessing it has to do with the macro processor as you're assigning the values in %LET.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let date1= "05JAN2017:09:58:57.822"dt;
%let date1bin = %sysfunc(putn(&amp;amp;date1.,binary64.));
%Let date2= 1799229537.822;
%let date2bin = %sysfunc(putn(&amp;amp;date2.,binary64.));

%put &amp;amp;=date1;
%put &amp;amp;=date1bin;
%put &amp;amp;=date2;
%put &amp;amp;=date2bin;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yields two different values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;36         %put &amp;amp;=date1;
DATE1="05JAN2017:09:58:57.822"dt
37         %put &amp;amp;=date1bin;
DATE1BIN=0100000111011010110011111000010000011000011100110011001100110011
38         %put &amp;amp;=date2;
DATE2=1799229537.822
39         %put &amp;amp;=date2bin;
DATE2BIN=0100000111011010110011111000010000011000011101001001101110100110&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compare to DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 date1a= "05JAN2017:09:58:57.822"dt;
 date1b= 1799229537.822;

 put date1a=  binary64.;
 put date1b=  binary64.;

 date2a = sum(date1a,-10);
 date2b = sum(date1b,-10);

 put date2a=  binary64.;
 put date2b=  binary64.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output (two pairs of identical values, initial values then the sum values):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;date1a=0100000111011010110011111000010000011000011101001001101110100110
date1b=0100000111011010110011111000010000011000011101001001101110100110&lt;BR /&gt;
date2a=0100000111011010110011111000010000010101111101001001101110100110
date2b=0100000111011010110011111000010000010101111101001001101110100110&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jan 2017 12:52:21 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2017-01-05T12:52:21Z</dc:date>
    <item>
      <title>Losing precision</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322621#M271113</link>
      <description>&lt;P&gt;Does anyone have an explanation why in version 1 in the code below I'm losing precision but things work for version 2?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* version 1 */
%Let date1= "05JAN2017:09:58:57.822"dt;
%let date2=%sysfunc(sum(&amp;amp;date1,-10),datetime26.3);
%put &amp;amp;=date1;
%put Losing precision:  &amp;amp;=date2;

/* version 2 */
%Let date1= 1799229537.822;
%let date2=%sysfunc(sum(&amp;amp;date1,-10),datetime26.3);
%put &amp;amp;=date1;
%put Full precision:  &amp;amp;=date2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Jan 2017 21:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322621#M271113</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-08T21:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Losing precision</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322643#M271114</link>
      <description>&lt;P&gt;I don't know the answer, but guessing it has to do with the macro processor as you're assigning the values in %LET.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let date1= "05JAN2017:09:58:57.822"dt;
%let date1bin = %sysfunc(putn(&amp;amp;date1.,binary64.));
%Let date2= 1799229537.822;
%let date2bin = %sysfunc(putn(&amp;amp;date2.,binary64.));

%put &amp;amp;=date1;
%put &amp;amp;=date1bin;
%put &amp;amp;=date2;
%put &amp;amp;=date2bin;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yields two different values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;36         %put &amp;amp;=date1;
DATE1="05JAN2017:09:58:57.822"dt
37         %put &amp;amp;=date1bin;
DATE1BIN=0100000111011010110011111000010000011000011100110011001100110011
38         %put &amp;amp;=date2;
DATE2=1799229537.822
39         %put &amp;amp;=date2bin;
DATE2BIN=0100000111011010110011111000010000011000011101001001101110100110&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compare to DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 date1a= "05JAN2017:09:58:57.822"dt;
 date1b= 1799229537.822;

 put date1a=  binary64.;
 put date1b=  binary64.;

 date2a = sum(date1a,-10);
 date2b = sum(date1b,-10);

 put date2a=  binary64.;
 put date2b=  binary64.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output (two pairs of identical values, initial values then the sum values):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;date1a=0100000111011010110011111000010000011000011101001001101110100110
date1b=0100000111011010110011111000010000011000011101001001101110100110&lt;BR /&gt;
date2a=0100000111011010110011111000010000010101111101001001101110100110
date2b=0100000111011010110011111000010000010101111101001001101110100110&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 12:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322643#M271114</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-01-05T12:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Losing precision</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322651#M271115</link>
      <description>&lt;P&gt;A good question like this one is worth a thousand answers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Chris&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the same result when using the same input.&lt;/P&gt;&lt;P&gt;Computers are not decimal machines.&lt;BR /&gt;Decimal to Binary to Decimal is not reversible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* version 1 */&lt;BR /&gt;%Let date1= 41DACF8418749BA6;&lt;BR /&gt;%let date2=%sysfunc(sum(%sysfunc(inputn(41DACF8418749BA6,hex16.)),-10),datetime26.3);&lt;BR /&gt;%put &amp;amp;=date1;&lt;BR /&gt;%put Loosing precision: &amp;amp;=date2;&lt;/P&gt;&lt;P&gt;/* version 2 */&lt;BR /&gt;%Let date1= 41DACF8418749BA6;&lt;BR /&gt;%let date2=%sysfunc(sum(%sysfunc(inputn(41DACF8418749BA6,hex16.)),-10),datetime26.3);&lt;BR /&gt;%put &amp;amp;=date1;&lt;BR /&gt;%put Full precision: &amp;amp;=date2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG&lt;/P&gt;&lt;P&gt;108 /* version 1 */&lt;BR /&gt;109 %Let date1= 41DACF8418749BA6;&lt;BR /&gt;110 %let date2=%sysfunc(sum(%sysfunc(inputn(41DACF8418749BA6,hex16.)),-10),datetime26.3);&lt;BR /&gt;111 %put &amp;amp;=date1;&lt;BR /&gt;DATE1=41DACF8418749BA6&lt;BR /&gt;112 %put Loosing precision: &amp;amp;=date2;&lt;BR /&gt;Loosing precision: DATE2=05JAN2017:09:58:47.822&lt;BR /&gt;113 /* version 2 */&lt;BR /&gt;114 %Let date1= 41DACF8418749BA6;&lt;BR /&gt;115 %let date2=%sysfunc(sum(%sysfunc(inputn(41DACF8418749BA6,hex16.)),-10),datetime26.3);&lt;BR /&gt;116 %put &amp;amp;=date1;&lt;BR /&gt;DATE1=41DACF8418749BA6&lt;BR /&gt;117 %put Full precision: &amp;amp;=date2;&lt;BR /&gt;Full precision: DATE2=05JAN2017:09:58:47.822&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 13:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322651#M271115</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-01-05T13:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Losing precision</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322664#M271116</link>
      <description>&lt;P&gt;I don't know the reason but this rather SYSFUNC heavy expression does produce the correct result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let date3=%sysfunc(sum(%sysfunc(inputn(%sysfunc(dequote(&amp;amp;date1)),datetime,26)),-10),datetime26.3);

NOTE: DATE3=05JAN2017:09:58:47.822&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 14:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322664#M271116</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-01-05T14:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: Losing precision</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322696#M271117</link>
      <description>&lt;P&gt;It's in the conversion of the datetime constant I think:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%Let date1= %sysevalf("05JAN2017:09:58:57.822"dt);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That already loses the extra characters. &amp;nbsp;Probably a question for SAS tech support as to why it happens - however the datetime constant is resolved must only take one decimal place for some reason.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Interestingly, it's not truly losing precision: look at this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%Let date1= %sysevalf("05JAN2017:09:58:57.862342"dt+0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That rounds up - meaning SAS is doing this on purpose,&amp;nbsp;this isn't a loss of precision situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even more interestingly, I do not get the same results Chris does in the data step - at least, not when I go through CALL SYMPUTX:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;
  call symputx('date1',"05JAN2017:09:58:57.822"dt);
run;
%put &amp;amp;=date1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or even:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;
  x = "05JAN2017:09:58:57.822"dt;
  put x=;
  call symputx('date3',x);
run;
%put &amp;amp;=date3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Both `x` and `&amp;amp;date3` have the rounded value.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 16:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322696#M271117</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2017-01-05T16:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Losing precision</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322700#M271118</link>
      <description>&lt;P&gt;Actually - I think that is the pointer to the real problem...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;
 date1a= "05JAN2017:09:58:57.822"dt;
 date1b= 1799229537.822;

 put date1a=;
 put date1b=;

 put date1a= best32.;
 put date1b= best32.;

 put date1a=  binary64.;
 put date1b=  binary64.;

 date2a = sum(date1a,-10);
 date2b = sum(date1b,-10);

 put date2a=  binary64.;
 put date2b=  binary64.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Somewhere in the macro variable assignment, BEST12. is being used. &amp;nbsp;BEST12. will yield a rounded value to 1 place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see a way to get SAS to not do that; for example, even this won't listen:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let date1= %sysfunc(sum("05JAN2017:09:58:57.862342"dt),best32.);
%put &amp;amp;=date1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Presumably because the conversion happens immediately seeing the constant and resolving it and bringing it into the macro facility. &amp;nbsp;So you'll have to do a workaround like data _null_ says, or perhaps a bit simpler,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let date1= 05JAN2017:09:58:57.822;
%let date2= %sysfunc(inputn(&amp;amp;date1.,datetime,26));
%put &amp;amp;=date2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(easier if you leave off all the other stuff and just store the date-as-text in date1).&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 16:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/322700#M271118</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2017-01-05T16:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: Losing precision</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/323229#M271119</link>
      <description>&lt;P&gt;Thank you all for your valuable input. ...and also thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;for fixing my spelling.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even though I have very rarely to use fractional seconds in real life situations and there are multiple ways to code around this implicit rounding, I'm still going to raise a TechSupport track for this one. I'll keep you posted once I've got a "final" answer.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2017 21:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Losing-precision/m-p/323229#M271119</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-08T21:32:55Z</dc:date>
    </item>
  </channel>
</rss>

