<?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: Most efficient way to get a bunch of means in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91713#M257446</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks to you both for your helpful suggestions.&amp;nbsp; As it turns out, the data comes out of the query in a different format (untransposed), then it is transposed into the format described in my question above for some other additional analyses.&amp;nbsp; So it made by far the most sense to simply do the Proc means by _NAME_ and level as a separate step before the data was transposed the first time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for the advice...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Jun 2013 21:12:38 GMT</pubDate>
    <dc:creator>AD</dc:creator>
    <dc:date>2013-06-04T21:12:38Z</dc:date>
    <item>
      <title>Most efficient way to get a bunch of means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91709#M257442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose I've a got a dataset with a some "V" variables (V1 - V3) that each can take on values A, B, or C (which I call "Options").&amp;nbsp; I've also got avariable called "Score" that is numeric. Here is an example of the data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data new;&lt;/P&gt;&lt;P&gt;Input V1$ V2$ V3$ Score;&lt;/P&gt;&lt;P&gt;Cards;&lt;/P&gt;&lt;P&gt;A B A 24&lt;/P&gt;&lt;P&gt;C C B 66&lt;/P&gt;&lt;P&gt;B A C 25&lt;/P&gt;&lt;P&gt;C A B 40&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to compute the average "Score" for all those who have a value of A on V1, a value of B on V1, a value of C on V1, a value of A on V2, a value of B on V2, a value of C on V2, a value of A on V3 a value of B on V3, and a value of C on V3, and I want to save all this information in a single dataset called "Final".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following code works and gets me the output dataset in the format I want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro OptionStats;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %Do i = 1 %To 3;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Proc Sort Data=new; By V&amp;amp;i; Run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Proc Means Data=New Mean Noprint; Var Score;&amp;nbsp; By V&amp;amp;i;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Output Out=Score_V&amp;amp;i (Drop=_TYPE_ _FREQ_)&amp;nbsp; Mean()=;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Data Score_V&amp;amp;i; Set Score_V&amp;amp;i; Rename V&amp;amp;i=Option Score=V&amp;amp;i; Run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %End;&lt;BR /&gt;%Mend;&lt;BR /&gt;%OptionStats;&lt;/P&gt;&lt;P&gt;Data Final;&amp;nbsp; Merge Score_V1 Score_V2 Score_V3;&amp;nbsp; Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;My question is whether there is a better, more efficient way to do this.&amp;nbsp; In the end, I will have a large dataset with hundreds of "V" variables (instead of just 3) and thousands of rows (instead of just 4), and it seems like it will be slow to have it go through an iterative process with a Proc Sort and a Proc Means for each V variable. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 May 2013 17:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91709#M257442</guid>
      <dc:creator>AD</dc:creator>
      <dc:date>2013-05-31T17:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to get a bunch of means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91710#M257443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe this will work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;Data&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; new;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;Input&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; V1$ V2$ V3$ Score;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;Cards&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffc0;"&gt;A B A 24&lt;BR /&gt;C C B 66&lt;BR /&gt;B A C 25&lt;BR /&gt;C A B 40&lt;BR /&gt;&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;Run&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;summary&lt;/STRONG&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=new &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;missing&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;chartype&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;class&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; v:;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;ways&lt;/SPAN&gt; &lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;1&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;output&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;out&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=ways1 &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;mean&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(score)=;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 May 2013 18:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91710#M257443</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-05-31T18:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to get a bunch of means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91711#M257444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With "hundreds" of V variables the combinations will likely exceed the combinations that Proc Summary or means will handle. You may want to examine the CLASSDATA= procedure option to identify the the combinations of V variables that you want output. It may still take a couple of passes through the data depending on the numbers of combinations you request but you would only need to change the Classdata data set and output set.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 May 2013 18:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91711#M257444</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-05-31T18:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to get a bunch of means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91712#M257445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe you should test it.&amp;nbsp; I think the OP wants 1 ways for many CLASS variables that should not "exceed" the limits maybe.&amp;nbsp; Otherwise just transpose and do the means by _NAME_ and level.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 May 2013 18:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91712#M257445</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-05-31T18:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to get a bunch of means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91713#M257446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks to you both for your helpful suggestions.&amp;nbsp; As it turns out, the data comes out of the query in a different format (untransposed), then it is transposed into the format described in my question above for some other additional analyses.&amp;nbsp; So it made by far the most sense to simply do the Proc means by _NAME_ and level as a separate step before the data was transposed the first time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for the advice...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jun 2013 21:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Most-efficient-way-to-get-a-bunch-of-means/m-p/91713#M257446</guid>
      <dc:creator>AD</dc:creator>
      <dc:date>2013-06-04T21:12:38Z</dc:date>
    </item>
  </channel>
</rss>

