<?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 Merging Observations In A DataSet in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33198#M6448</link>
    <description>Disclaimer:  I had a hard time coming up with a title for this thread, so my apologies if the title is misleading and/or this is not posted in the appropriate section of the forums.&lt;BR /&gt;
&lt;BR /&gt;
My Question:&lt;BR /&gt;
&lt;BR /&gt;
In my example data set I have multiple observations for 'orange'  'apple'  'banana' etc... and next to these I hava varaibles 'taste' 'flavor'.  And the values for taste and flavor are numeric (1-5) based on survey feedback.   So, my data set might look like this:&lt;BR /&gt;
&lt;BR /&gt;
Fruit        Taste   Flavor&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;
I would like to be able to combine all observations for 'apple', 'banana', etc. into a single observation where 'taste' and 'flavor' now contain the average of the responses to taste and flavor for 'apple' for all survey responses.  &lt;BR /&gt;
&lt;BR /&gt;
For example, I want my dataset to now look like this (a single row for each type of fruit, and the responses for taste and flavor now averaged):&lt;BR /&gt;
&lt;BR /&gt;
Fruit       Taste   Flavor&lt;BR /&gt;
Apple     1.5       4&lt;BR /&gt;
Banana   2         4.5&lt;BR /&gt;
Orange   3.33     2.66&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
All help is greatly appreciated!  Yes, I'm pretty new to this!&lt;BR /&gt;
&lt;BR /&gt;
Thanks all!</description>
    <pubDate>Mon, 18 May 2009 12:03:43 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-05-18T12:03:43Z</dc:date>
    <item>
      <title>Merging Observations In A DataSet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33198#M6448</link>
      <description>Disclaimer:  I had a hard time coming up with a title for this thread, so my apologies if the title is misleading and/or this is not posted in the appropriate section of the forums.&lt;BR /&gt;
&lt;BR /&gt;
My Question:&lt;BR /&gt;
&lt;BR /&gt;
In my example data set I have multiple observations for 'orange'  'apple'  'banana' etc... and next to these I hava varaibles 'taste' 'flavor'.  And the values for taste and flavor are numeric (1-5) based on survey feedback.   So, my data set might look like this:&lt;BR /&gt;
&lt;BR /&gt;
Fruit        Taste   Flavor&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;
I would like to be able to combine all observations for 'apple', 'banana', etc. into a single observation where 'taste' and 'flavor' now contain the average of the responses to taste and flavor for 'apple' for all survey responses.  &lt;BR /&gt;
&lt;BR /&gt;
For example, I want my dataset to now look like this (a single row for each type of fruit, and the responses for taste and flavor now averaged):&lt;BR /&gt;
&lt;BR /&gt;
Fruit       Taste   Flavor&lt;BR /&gt;
Apple     1.5       4&lt;BR /&gt;
Banana   2         4.5&lt;BR /&gt;
Orange   3.33     2.66&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
All help is greatly appreciated!  Yes, I'm pretty new to this!&lt;BR /&gt;
&lt;BR /&gt;
Thanks all!</description>
      <pubDate>Mon, 18 May 2009 12:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33198#M6448</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-18T12:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Observations In A DataSet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33199#M6449</link>
      <description>data a;&lt;BR /&gt;
input x $ y z;&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;
proc sort;&lt;BR /&gt;
by x;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc means data=a noprint;&lt;BR /&gt;
by x;&lt;BR /&gt;
output out=b(drop=_type_ _freq_) mean=;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 18 May 2009 12:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33199#M6449</guid>
      <dc:creator>Pavan_SAS</dc:creator>
      <dc:date>2009-05-18T12:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Observations In A DataSet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33200#M6450</link>
      <description>Pavan, &lt;BR /&gt;
&lt;BR /&gt;
Thank you for your time and the example.  My data is already in a dataset, so it is my understanding that I will just leave off the data step you included.  &lt;BR /&gt;
&lt;BR /&gt;
My example was a very simplistic one which captured the problem I am facing with a much larger dataset.  &lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;I&gt;To take this example a step further, I have another question:&lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
How would I go about creating a 4th variable (we'll call it Overall Taste), which would essentially just be an average of y and z (from your example)?  So, in your example, in the proc  means step y and z are an 'average' in the output dataset... I would like a 4th variable (we'll call it 'a')... which is the average of y and z.&lt;BR /&gt;
&lt;BR /&gt;
All help is GREATLY appreciated!</description>
      <pubDate>Mon, 18 May 2009 13:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33200#M6450</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-18T13:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Observations In A DataSet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33201#M6451</link>
      <description>To summarise the summary, you need two steps.&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
  input Fruit $ Taste Flavor;&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;
proc means data=a noprint nway;&lt;BR /&gt;
  class fruit;&lt;BR /&gt;
  output out=b(drop=_type_ _freq_) mean=;&lt;BR /&gt;
run; &lt;BR /&gt;
data c;&lt;BR /&gt;
 set b;&lt;BR /&gt;
 overall=mean(Taste,Flavor);&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
Note that you could have 2000 oranges and 2 apples, and their respective mean would weight the same. Ask yourself if you really want the mean of the mean, or whether you want to weigh the averages.</description>
      <pubDate>Wed, 20 May 2009 05:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33201#M6451</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-05-20T05:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Observations In A DataSet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33202#M6452</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Please try this, hope this will help you&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
input Fruit $ Taste Flavor;&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;
proc sql;&lt;BR /&gt;
select fruit,mean(taste) as taste,mean(flavor) as flavour, mean(mean(taste),mean(flavor)) as AVG_TASTE_FLAVOUR&lt;BR /&gt;
from a&lt;BR /&gt;
group by fruit;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
skm</description>
      <pubDate>Wed, 20 May 2009 11:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Observations-In-A-DataSet/m-p/33202#M6452</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-20T11:14:57Z</dc:date>
    </item>
  </channel>
</rss>

