<?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: Average Multiple Variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39665#M10253</link>
    <description>Oh..You said you wanted the average of sum of ques1 and quest2.  Average of both the responses give the result 6 as per the data. Is not that you wanted ??  Am I misisng some thing ?? How about the other results 3, 4 ??&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
    <pubDate>Mon, 01 Jun 2009 19:18:10 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-06-01T19:18:10Z</dc:date>
    <item>
      <title>Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39657#M10245</link>
      <description>Hello All,&lt;BR /&gt;
&lt;BR /&gt;
This is a bit of continuation of a question, I previously answered, so please bear with me.&lt;BR /&gt;
&lt;BR /&gt;
1)  Here is my example dataset:&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
input Fruit $ Ques1 Quest2;&lt;BR /&gt;
cards;&lt;BR /&gt;
Apple 1 4&lt;BR /&gt;
Banana 1 5&lt;BR /&gt;
Banana 3 4&lt;BR /&gt;
Apple 2 4&lt;BR /&gt;
Orange 5 1&lt;BR /&gt;
Orange 2 4&lt;BR /&gt;
Orange 3 3&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
2)  I would like to find the average for all responses responses to Ques1 &amp;amp; Quest2 (combined).  Think of this as the average response for all all the questions of all fruits combined.&lt;BR /&gt;
&lt;BR /&gt;
3)  I would like to find the average for all responses where Fruit='Apple' or Fruit='Banana' etc.  Think of this as where I want the average question response to all questions for just bananas, then just apples, etc.&lt;BR /&gt;
&lt;BR /&gt;
4.  How could I limit this to just particular variables?  For instance if I wanted the average response to only Ques1 for *just* bananas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks to all of you again for your time.&lt;BR /&gt;
&lt;BR /&gt;
_jeff_</description>
      <pubDate>Mon, 01 Jun 2009 17:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39657#M10245</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T17:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39658#M10246</link>
      <description>Have a look at using PROC MEANS with NOPRINT, a CLASS statement, and an OUTPUT statement, and review the generated results with focus on _TYPE_ variable.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 01 Jun 2009 18:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39658#M10246</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-01T18:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39659#M10247</link>
      <description>Hi Jeff, have you tried Proc Means? Here are examples, in order of your questions.&lt;BR /&gt;
&lt;BR /&gt;
(2) &lt;BR /&gt;
&lt;BR /&gt;
Proc Means data=a;&lt;BR /&gt;
output out=means mean=;&lt;BR /&gt;
Run; Quit;&lt;BR /&gt;
&lt;BR /&gt;
(3)&lt;BR /&gt;
&lt;BR /&gt;
Proc Sort data=a; by fruit; run;&lt;BR /&gt;
Proc Means data=a;&lt;BR /&gt;
by fruit;&lt;BR /&gt;
output out=means mean=;&lt;BR /&gt;
Run; Quit;&lt;BR /&gt;
&lt;BR /&gt;
(4)&lt;BR /&gt;
&lt;BR /&gt;
Proc Means data=a;&lt;BR /&gt;
var ques1 quest2;&lt;BR /&gt;
where fruit='Banana';&lt;BR /&gt;
output out=means mean=;&lt;BR /&gt;
Run; Quit;&lt;BR /&gt;
&lt;BR /&gt;
Happy SASsing! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Tricia

(Added Proc Sort to #3.)&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: sassygrl</description>
      <pubDate>Mon, 01 Jun 2009 18:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39659#M10247</guid>
      <dc:creator>sassygrl</dc:creator>
      <dc:date>2009-06-01T18:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39660#M10248</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's Note: This solution, along with the addition of the following in a later post:&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Change the statement to avg(ques1+quest2) as avg to avg(ques+quest2)/2 as avg in select statement in 2 and 3...&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;provide answers to all questions asked. Thanks also to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15363"&gt;@SteveDenham&lt;/a&gt;&amp;nbsp;for providing a PROC MEANS alternative.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use Proc Sql with Group by and Having clauses, if you are good with Proc Sql;&lt;BR /&gt; &lt;BR /&gt; Below is the code for the your questions 2,3 4 in the order:&lt;BR /&gt; &lt;BR /&gt; proc sql;&lt;BR /&gt; create table b as&lt;BR /&gt; select fruit, ques1, quest2, avg(ques1+quest2) as avg&lt;BR /&gt; from a;&lt;BR /&gt; quit;&lt;BR /&gt; &lt;BR /&gt; proc sql;&lt;BR /&gt; create table c as&lt;BR /&gt; select fruit, ques1 , quest2, avg(ques1+quest2) as avg1&lt;BR /&gt; from a&lt;BR /&gt; group by fruit&lt;BR /&gt; having fruit in ('Banana', 'Apple');&lt;BR /&gt; quit;&lt;BR /&gt; &lt;BR /&gt; proc sql;&lt;BR /&gt; create table d as&lt;BR /&gt; select fruit, ques1 , quest2, avg(ques1) as avg2&lt;BR /&gt; from a&lt;BR /&gt; group by fruit&lt;BR /&gt; having fruit in ('Banana');&lt;BR /&gt; quit;&lt;BR /&gt; &lt;BR /&gt; ~ Sukanya E&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 18:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39660#M10248</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2017-08-31T18:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39661#M10249</link>
      <description>Hello Jeff,&lt;BR /&gt;
&lt;BR /&gt;
Try the following code, after what you have:&lt;BR /&gt;
&lt;BR /&gt;
data long;&lt;BR /&gt;
	set a;&lt;BR /&gt;
	ques=1;response=ques1;output;&lt;BR /&gt;
	ques=2;response=quest2;output;&lt;BR /&gt;
	drop ques1 quest2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc means data=long noprint;&lt;BR /&gt;
class fruit ques;&lt;BR /&gt;
var response;&lt;BR /&gt;
output out=manymeans mean=mean;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Now take a look at the dataset manymeans.  In it is a variable called _TYPE_.  By looking at the appropriate value of _TYPE_, you will get exactly the kinds of averages you were talking about.&lt;BR /&gt;
&lt;BR /&gt;
_TYPE_=0 gives the grand mean across all questions and fruit types. (your point #2)&lt;BR /&gt;
_TYPE_=1 gives the mean of each question (1 and 2), across all fruit types.&lt;BR /&gt;
_TYPE_=2 gives the mean of each fruit type, across both questions. (your point #3)&lt;BR /&gt;
_TYPE_=3 gives the mean of each question for each fruit type. (your point #4)&lt;BR /&gt;
&lt;BR /&gt;
Good luck with this.&lt;BR /&gt;
&lt;BR /&gt;
Steve Denham</description>
      <pubDate>Mon, 01 Jun 2009 18:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39661#M10249</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2009-06-01T18:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39662#M10250</link>
      <description>sasygirl - &lt;BR /&gt;
&lt;BR /&gt;
Thank you for your time and response.  I like the examples which you have provided, the only downside being that each of your solutions keeps the variables separate.  &lt;BR /&gt;
&lt;BR /&gt;
For instance, for #2, I want the mean for all responses to both Ques1 and Quest2 (combined) .  Not as separate values.  When running your solution to #2, I get the following:&lt;BR /&gt;
&lt;BR /&gt;
Ques1       7       2.4285714      &lt;BR /&gt;
Quest2      7       3.5714286&lt;BR /&gt;
&lt;BR /&gt;
What I want is one number/mean which represents the mean for all responses to both Quest1 and Quest2.  &lt;BR /&gt;
&lt;BR /&gt;
My 'real world' dataset is survey, where the first 5 questions represent the employees responses to 'Job related' questions... and I'm trying to create one number which is "Overall Job".  This number is the average response from all users to all questions.  This number will be used as a baseline to compare individual divisions against (hence #3 in my original post).&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Mon, 01 Jun 2009 19:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39662#M10250</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T19:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39663#M10251</link>
      <description>Sukanya,&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your time as well, however, your response to #2 creates incorrect results.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table b as&lt;BR /&gt;
select fruit, ques1, quest2, avg(ques1+quest2) as avg&lt;BR /&gt;
from a;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
It shows the 'avg' as being '6', which can't be correct given that my survey response values only range from 1-4.  &lt;BR /&gt;
&lt;BR /&gt;
Just wanted to share what I noticed.&lt;BR /&gt;
&lt;BR /&gt;
thanks!</description>
      <pubDate>Mon, 01 Jun 2009 19:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39663#M10251</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T19:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39664#M10252</link>
      <description>Using a DATA step, generate additional observations masking your BY variable as value "*ALL*" or something.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 01 Jun 2009 19:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39664#M10252</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-01T19:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39665#M10253</link>
      <description>Oh..You said you wanted the average of sum of ques1 and quest2.  Average of both the responses give the result 6 as per the data. Is not that you wanted ??  Am I misisng some thing ?? How about the other results 3, 4 ??&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
      <pubDate>Mon, 01 Jun 2009 19:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39665#M10253</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T19:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39666#M10254</link>
      <description>I apologize if I am not explaining my need very well.  Let me try an example&lt;BR /&gt;
&lt;BR /&gt;
If my dataset looked like this:&lt;BR /&gt;
&lt;BR /&gt;
Apple 1   2&lt;BR /&gt;
Banana  3   4&lt;BR /&gt;
Orange 2   3&lt;BR /&gt;
&lt;BR /&gt;
I want the 'average' of all responses.  So, in this dataset I have a total of 6 responses that have been recorded.  So the 'math' would look like this for this small dataset:&lt;BR /&gt;
&lt;BR /&gt;
1 + 2 + 3 + 4 + 2 + 3 = 15&lt;BR /&gt;
15  / 6 = 2.5&lt;BR /&gt;
&lt;BR /&gt;
So, my overall average is 2.5&lt;BR /&gt;
&lt;BR /&gt;
Does that help clarify?  Again, my apologies</description>
      <pubDate>Mon, 01 Jun 2009 19:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39666#M10254</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T19:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39667#M10255</link>
      <description>If you want the separate means for ques1 and quest2, then change the statement avg(ques1+quest2) as avg to avg(ques1) as qvg1, avg(quest2) as qvg2 in select statement.&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
      <pubDate>Mon, 01 Jun 2009 19:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39667#M10255</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T19:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39668#M10256</link>
      <description>Oh...I got it...Just divide by 2....Change the statement to avg(ques1+quest2) as avg to avg(ques+quest2)/2 as avg in select statement in 2 and 3...&lt;BR /&gt;
&lt;BR /&gt;
I hope this works for you now...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
      <pubDate>Mon, 01 Jun 2009 19:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39668#M10256</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T19:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39669#M10257</link>
      <description>Perfect!  Thank you for your time AND patience!  I haven't verified #4 yet, but by dividing by 2, all seems to work perfectly for #2 and #3.</description>
      <pubDate>Mon, 01 Jun 2009 19:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39669#M10257</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T19:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Average Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39670#M10258</link>
      <description>For #4, you don't have to divide by 2 as you are considering only for Ques1...&lt;BR /&gt;
Hope this makes sense..&lt;BR /&gt;
&lt;BR /&gt;
 ~ Sukanya E</description>
      <pubDate>Mon, 01 Jun 2009 19:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-Multiple-Variables/m-p/39670#M10258</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T19:46:08Z</dc:date>
    </item>
  </channel>
</rss>

