<?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: proc means giving weird values while calculating mean in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688956#M209396</link>
    <description>I want to display my mean values in the format as mean (sd) . And because of this i need to convert those numeric values of mean and standard deviation to character to display the values in the above format.&lt;BR /&gt;</description>
    <pubDate>Mon, 05 Oct 2020 17:32:33 GMT</pubDate>
    <dc:creator>shantanupl1</dc:creator>
    <dc:date>2020-10-05T17:32:33Z</dc:date>
    <item>
      <title>proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688910#M209372</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following dataset :&lt;/P&gt;&lt;P&gt;temp_values&lt;/P&gt;&lt;P&gt;35.3&lt;BR /&gt;36.1&lt;BR /&gt;36.2&lt;BR /&gt;36.6&lt;BR /&gt;36.5&lt;BR /&gt;36.5&lt;BR /&gt;36.6&lt;BR /&gt;36.2&lt;BR /&gt;36.2&lt;BR /&gt;36.2&lt;BR /&gt;35.9&lt;BR /&gt;36.5&lt;BR /&gt;36.3&lt;BR /&gt;36.4&lt;BR /&gt;36.2&lt;BR /&gt;36.3&lt;/P&gt;&lt;P&gt;I am calculating mean using proc means and the result in the output dataset for mean value appears to be 36.25. However if I filter mean value of 36.25 then this record is not appearing in filtered data and I checked that the value is actually less than 36.25. For the same data using proc sql i am getting mean as exact 36.25. I am unable to identify the cause why proc means is giving this weird value.&lt;/P&gt;&lt;P&gt;proc means data=r;&lt;BR /&gt;var temp_values;&lt;BR /&gt;output out=r1 mean=mean n=n;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also while converting the mean value to a character format of 5.1 the result is 36.2 but the result should be 36.3.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 15:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688910#M209372</guid>
      <dc:creator>shantanupl1</dc:creator>
      <dc:date>2020-10-05T15:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688914#M209374</link>
      <description>&lt;P&gt;This is called &lt;A href="https://en.wikipedia.org/wiki/Machine_epsilon" target="_self"&gt;machine precision&lt;/A&gt;, where a binary computer cannot represent fractions exactly and so mathematical calculations such as summing or averaging (or really, any other mathematical calculation) and so the results can be off by a tiny value (sometimes called epsilon) very close to zero ... and there's nothing wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So PROC MEANS produces a result that is (for this data) a tiny little bit less than 36.25. How much less than 36.25? Well you can subtract 36.25 from the answer given by PROC MEANS and find out that the difference is&amp;nbsp;-7.105427357601E-15, which is nothing to worry about and cannot be avoided with binary computers, and perfectly normal.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 16:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688914#M209374</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-05T16:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688938#M209384</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;However if I filter mean value of 36.25 then this record is not appearing in filtered data and I checked that the value is actually less than 36.25&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Your mean data does not need to be an observation in the data set. If you're referring to the output from PROC MEANS then it's likely that you have 36.2500001 or something so you need to round it before you compare it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if round(mean, 0.01) = 36.25 then do....;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Also while converting the mean value to a character format of 5.1 the result is 36.2 but the result should be 36.3.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Without the code you used we have no idea if that was done correctly or not. Also, check beyond 1 decimal place. If the number is very close to the boundary the difference could be smaller and causes it to round incorrectly.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 16:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688938#M209384</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-05T16:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688942#M209387</link>
      <description>&lt;P&gt;Thank you very much for the solution.&lt;/P&gt;&lt;P&gt;But if i round the value to 1 decimal then the result is 36.3 and&amp;nbsp;when we are using put function we are getting 36.2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the value is little bit less than 36.25 then why the round function is giving 36.3?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this was noticed because while using proc sql/proc univariate we are getting the result as exact 36.25 and I am getting the difference 0.1.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 16:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688942#M209387</guid>
      <dc:creator>shantanupl1</dc:creator>
      <dc:date>2020-10-05T16:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688943#M209388</link>
      <description>&lt;P&gt;Why are you using the PUT function here?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 16:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688943#M209388</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-05T16:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688945#M209389</link>
      <description>&lt;P&gt;I want to convert the numeric value to character value for display purpose.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 16:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688945#M209389</guid>
      <dc:creator>shantanupl1</dc:creator>
      <dc:date>2020-10-05T16:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688947#M209390</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/199867"&gt;@shantanupl1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to convert the numeric value to character value for display purpose.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This was not part of your original problem statement, and so I do not understand what the question or problem is regarding PUT.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 17:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688947#M209390</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-05T17:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688950#M209391</link>
      <description>I mentioned in the last statement that while converting the value to a character format of 5.1 I am getting the value as 36.2.</description>
      <pubDate>Mon, 05 Oct 2020 17:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688950#M209391</guid>
      <dc:creator>shantanupl1</dc:creator>
      <dc:date>2020-10-05T17:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688953#M209393</link>
      <description>&lt;P&gt;But why are you using the PUT function in the first place? How does that help anything? Why do you want to display numbers as character? I am totally lost here, as your original problem had nothing to do with displaying as character.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 17:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688953#M209393</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-05T17:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688956#M209396</link>
      <description>I want to display my mean values in the format as mean (sd) . And because of this i need to convert those numeric values of mean and standard deviation to character to display the values in the above format.&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Oct 2020 17:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688956#M209396</guid>
      <dc:creator>shantanupl1</dc:creator>
      <dc:date>2020-10-05T17:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688958#M209397</link>
      <description>My problem was always the same. The mean value for the above data should be 36.25. But the proc means procedure is giving the value little less than 36.25(reason mentioned by you). So when i was converting that value into a character format using put function(which generally works similarly as round function) the result is 36.2. But when i am using round function the result i am getting is 36.3.&lt;BR /&gt;a1=put(mean,5.1)&lt;BR /&gt;a2=round(mean,0.1)&lt;BR /&gt;Also when I am using proc sql or proc univariate on the same data i am getting the mean as exact 36.25.&lt;BR /&gt;So i am curious about the working of those functions.</description>
      <pubDate>Mon, 05 Oct 2020 17:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688958#M209397</guid>
      <dc:creator>shantanupl1</dc:creator>
      <dc:date>2020-10-05T17:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688959#M209398</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;So when i was converting that value into a character format using put function(which generally works similarly as round function) the result is 36.2.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the part I don't understand. Why? Most people do not (except in rare situations) convert numbers to characters to display them. You have explained that you want to do it, you have not explained why you are doing this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do the proper rounding on numbers, now that you know what the issue is. The ROUND function will round your nearly 36.25 to exactly 36.25, and then if you really want, you can round it again to one decimal point. I add that the usual rule of thumb is that if your data is measured to one decimal place, then the average is reported with one more decimal place, in other words, two decimal places. None of which require character values or converting to character, which will not solve the problem you have with the number very close to (but not exactly equal to) 36.25.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 18:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688959#M209398</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-05T18:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: proc means giving weird values while calculating mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688971#M209404</link>
      <description>&lt;P&gt;PUT() truncates at the decimal point requested 36.25 -&amp;gt; 36.2&lt;/P&gt;
&lt;P&gt;ROUND() rounds at the decimal point requested 36.25 -&amp;gt; 36.3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/199867"&gt;@shantanupl1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;My problem was always the same. The mean value for the above data should be 36.25. But the proc means procedure is giving the value little less than 36.25(reason mentioned by you). So when i was converting that value into a character format using put function(which generally works similarly as round function) the result is 36.2. But when i am using round function the result i am getting is 36.3.&lt;BR /&gt;a1=put(mean,5.1)&lt;BR /&gt;a2=round(mean,0.1)&lt;BR /&gt;Also when I am using proc sql or proc univariate on the same data i am getting the mean as exact 36.25.&lt;BR /&gt;So i am curious about the working of those functions.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 19:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-giving-weird-values-while-calculating-mean/m-p/688971#M209404</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-05T19:16:19Z</dc:date>
    </item>
  </channel>
</rss>

