<?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: Why proc sql and proc means produce different results? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550521#M8817</link>
    <description>&lt;P&gt;Note that the difference is very small. It is an artifact caused by how numbers are stored (8-byte real), the resulting limits in precision, and the fact that some (in fact quite a lot) of decimal fractions can't be represented exactly in binary at all.&lt;/P&gt;
&lt;P&gt;So a slightly different order of calculations can cause this slight imprecision in the result values.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Apr 2019 07:37:47 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-04-12T07:37:47Z</dc:date>
    <item>
      <title>Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550513#M8813</link>
      <description>&lt;P&gt;I happened to&amp;nbsp; find the following issue which confused me for several hours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input RandNo$ Trt$ Tmax;
	cards;
	K64	R	0.5
	K64	T	0.15
	K64	R	0.15
	K64	T	0.5
	K65	T	0.5
	K65	R	0.33
	K65	T	0.17
	K65	R	0.5
;
run;

proc sql noprint;
	create table SQL as 
	select RandNo, TRT, avg(Tmax) as Tmax_Mean
	from test
	group by RandNo, TRT
	;
quit;

ods output Summary = Means;
proc means data = test n mean;
	class RandNo TRT;
	var Tmax;
run;
ods output;

proc sql;
	select a.RandNo, a.TRT, a.Tmax_Mean as SQL,
		b.Tmax_Mean as Means,
		SQL - Means as Dif
	from SQL as a
	left join Means as b
	on a.RandNo = b.RandNo and a.TRT = b.TRT
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;PRE&gt;RandNo Trt SQL Mean Dif 
K64 R 0.325 0.325 0 
K64 T 0.325 0.325 -555E-19 
K65 R 0.415 0.415 0 
K65 T 0.335 0.335 -555E-19 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So why dose the results from proc means and proc sql differs from the other?&lt;/P&gt;&lt;P&gt;PS: I have tried deleting the observations of 'K64' or 'K65' and the difference just disappear this time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 07:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550513#M8813</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2019-04-12T07:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550515#M8814</link>
      <description>&lt;P&gt;SAS stores numbers in 8 bytes of memory which means it can hold a maximum of 15 digits accurately. The difference you are reporting is in the 16th digit and beyond, so it is meaningless. Apply the ROUND function if you want to get rid of the meaningless noise of tiny differences:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;round(SQL - Means, 0.000001)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 07:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550515#M8814</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-04-12T07:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550517#M8816</link>
      <description>&lt;P&gt;Thx, but I really want to know why.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 07:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550517#M8816</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2019-04-12T07:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550521#M8817</link>
      <description>&lt;P&gt;Note that the difference is very small. It is an artifact caused by how numbers are stored (8-byte real), the resulting limits in precision, and the fact that some (in fact quite a lot) of decimal fractions can't be represented exactly in binary at all.&lt;/P&gt;
&lt;P&gt;So a slightly different order of calculations can cause this slight imprecision in the result values.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 07:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550521#M8817</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-12T07:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550524#M8818</link>
      <description>&lt;P&gt;PS you don't have to go through ODS to create an output dataset from proc summary/means:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=test nway noprint;
class RandNo TRT;
var Tmax;
output
  out=means (drop=_type_ _freq_)
  mean(tmax)=tmax_mean
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Apr 2019 07:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550524#M8818</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-12T07:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550526#M8819</link>
      <description>&lt;P&gt;Thank you, kind man.&lt;BR /&gt;What I really want is comment on the difference between proc sql and proc means, do you think they process the numbers differently? And why this difference disappear when there is only one possible value of 'RandNo'?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 07:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550526#M8819</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2019-04-12T07:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550527#M8820</link>
      <description>Oh, that is very nice. I used to ods output statement because I can not remember how to write different output statement in different procedure. Do they differs in performance?</description>
      <pubDate>Fri, 12 Apr 2019 07:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550527#M8820</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2019-04-12T07:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550534#M8821</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270406"&gt;@whymath&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Oh, that is very nice. I used to ods output statement because I can not remember how to write different output statement in different procedure. Do they differs in performance?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would be&amp;nbsp;&lt;EM&gt;very&lt;/EM&gt; surprised if the direct output would not outperform the ODS method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the examples for Maxim 14 I will bring up in my upcoming presentation at SAS GF 2019 will be an example where using ODS CSV instead of a proc export to csv took about 100 times longer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And your other question: yes, slight changes in your logic will change the order of calculations; since some of the intermediate results will be afflicted by precision loss, and others not, you will get precision differences in the end result. That's why it is always sound technique to use round() before doing numerical comparisons in SAS where you test for equality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is true for all software that uses "real" (mantissa an exponent) storage. Integers don't have that problem, but you can't handle really big numbers with them.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 08:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550534#M8821</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-12T08:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550542#M8824</link>
      <description>Really detailed explanation.&lt;BR /&gt;I will follow you on GF.</description>
      <pubDate>Fri, 12 Apr 2019 08:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550542#M8824</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2019-04-12T08:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Why proc sql and proc means produce different results?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550687#M8842</link>
      <description>In general, this isn't really a SAS problem, it's a computer problem and Excel, Python, R all have similar issues. &lt;BR /&gt;&lt;BR /&gt;Here's the full documentation and explanation of why this occurs.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;</description>
      <pubDate>Fri, 12 Apr 2019 15:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-proc-sql-and-proc-means-produce-different-results/m-p/550687#M8842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-12T15:21:24Z</dc:date>
    </item>
  </channel>
</rss>

