<?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: Finding the mean in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/847012#M334870</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436771"&gt;@SASuser4321&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;how do I show this result separately as a table in the "Output Data" section? Because I would like to merge this table with other data sets eventually. I tried the following but it doesn't work:&lt;BR /&gt;&lt;BR /&gt;proc means data=have mean;&lt;BR /&gt;output out = weighted;&lt;BR /&gt;var Rating_a;&lt;BR /&gt;weight Weight;&lt;BR /&gt;run;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What about it doesn't work? Please provide more information. (IMPORTANT: when you tell us something doesn't work and give no other information, we can't help you. Always tell us what happened and explain waht part didn't work, or show us the log with errors)&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2022 10:54:20 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-11-30T10:54:20Z</dc:date>
    <item>
      <title>Finding the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846981#M334852</link>
      <description>&lt;ADDRESS&gt;I have a table with two columns and I wish to find the weighted mean.&lt;BR /&gt;So for example, in the following table, I would like my code to generate the following results:&amp;nbsp; 2.4&lt;BR /&gt;I got the above value of 2.4 through this:([(3*2) + (3*5) + (4*1) + (1*3) + (2*4)]/15&lt;BR /&gt;My actual table has thousands of rows and so I'm wondering what code could deal with this. Help would be appreciated.&amp;nbsp;&lt;BR /&gt;I tried the following code but it doesn't work:&lt;/ADDRESS&gt;&lt;ADDRESS&gt;proc sql;&lt;BR /&gt;select sum(Rating_a*Weights) / sum(Weights) from have;&lt;BR /&gt;quit;&lt;/ADDRESS&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="30px"&gt;Weights&lt;/TD&gt;
&lt;TD width="50%" height="30px"&gt;Rating_a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="50%" height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="30px"&gt;5&lt;/TD&gt;
&lt;TD width="50%" height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="50%" height="30px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="50%" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="50%" height="30px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 30 Nov 2022 06:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846981#M334852</guid>
      <dc:creator>SASuser4321</dc:creator>
      <dc:date>2022-11-30T06:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846986#M334853</link>
      <description>&lt;P&gt;Maxim 7 from &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_blank"&gt;Maxims of Maximally Efficient SAS Programmers&lt;/A&gt;&amp;nbsp; says: There is a procedure for it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So instead of using proc sql, use proc means:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have mean;
   var Rating_a;
   weight Weight;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Nov 2022 07:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846986#M334853</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-11-30T07:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846990#M334856</link>
      <description>how do I show this result separately as a table in the "Output Data" section? Because I would like to merge this table with other data sets eventually. I tried the following but it doesn't work:&lt;BR /&gt;&lt;BR /&gt;proc means data=have mean;&lt;BR /&gt;output out = weighted;&lt;BR /&gt;   var Rating_a;&lt;BR /&gt;   weight Weight;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 30 Nov 2022 07:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846990#M334856</guid>
      <dc:creator>SASuser4321</dc:creator>
      <dc:date>2022-11-30T07:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846995#M334860</link>
      <description>&lt;P&gt;Just add an output statement as documented at &lt;A href="https://documentation.sas.com/doc/de/pgmsascdc/9.4_3.5/proc/p04vbvpcjg2vrjn1v8wyf0daypfi.htm" target="_blank"&gt;https://documentation.sas.com/doc/de/pgmsascdc/9.4_3.5/proc/p04vbvpcjg2vrjn1v8wyf0daypfi.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 08:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846995#M334860</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-11-30T08:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846996#M334861</link>
      <description>I figured it out on my own &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ods select none;&lt;BR /&gt;proc means data=have mean;&lt;BR /&gt;var Rating_a;&lt;BR /&gt;weight Weight;&lt;BR /&gt;ods output summary= weighted;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;ods select all;</description>
      <pubDate>Wed, 30 Nov 2022 08:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/846996#M334861</guid>
      <dc:creator>SASuser4321</dc:creator>
      <dc:date>2022-11-30T08:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/847012#M334870</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436771"&gt;@SASuser4321&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;how do I show this result separately as a table in the "Output Data" section? Because I would like to merge this table with other data sets eventually. I tried the following but it doesn't work:&lt;BR /&gt;&lt;BR /&gt;proc means data=have mean;&lt;BR /&gt;output out = weighted;&lt;BR /&gt;var Rating_a;&lt;BR /&gt;weight Weight;&lt;BR /&gt;run;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What about it doesn't work? Please provide more information. (IMPORTANT: when you tell us something doesn't work and give no other information, we can't help you. Always tell us what happened and explain waht part didn't work, or show us the log with errors)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 10:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/847012#M334870</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-30T10:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/847014#M334872</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436771"&gt;@SASuser4321&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;ADDRESS&gt;I have a table with two columns and I wish to find the weighted mean.&lt;BR /&gt;So for example, in the following table, I would like my code to generate the following results:&amp;nbsp; 2.4&lt;BR /&gt;I got the above value of 2.4 through this:([(3*2) + (3*5) + (4*1) + (1*3) + (2*4)]/15&lt;BR /&gt;My actual table has thousands of rows and so I'm wondering what code could deal with this. Help would be appreciated.&amp;nbsp;&lt;BR /&gt;I tried the following code but it doesn't work:&lt;/ADDRESS&gt;&lt;ADDRESS&gt;proc sql;&lt;BR /&gt;select sum(Rating_a*Weights) / sum(Weights) from have;&lt;BR /&gt;quit;&lt;/ADDRESS&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This formula will fail and give you the wrong answer if you have missing values. Do not write your own code to compute means or other basic statistics, do not write your own code to compute anything is SAS has already programmed it. Instead, as suggested use PROC MEANS which has been thoroughly debugged and tested in a bazillion and 12 different applications.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 10:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-mean/m-p/847014#M334872</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-30T10:56:56Z</dc:date>
    </item>
  </channel>
</rss>

