<?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: Combinations means of dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348559#M273425</link>
    <description>&lt;P&gt;CALL SORTC I think?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 09 Apr 2017 21:46:20 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-04-09T21:46:20Z</dc:date>
    <item>
      <title>Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348538#M273422</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS and I am struggling with the following scenario.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of 20 valiables and each one has a value. I am trying to choose 3 of the 20 and compute the mean for each one of the rows. Basically there would be 1140 additional columns to my dataset and in this case order does not matter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example attached - my columns are from A-F and the combinations are ABC...BCE...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do the following and put statement seems to work fine but i can't figure out how to add those additional columns&lt;/P&gt;&lt;P&gt;and compute the mean. Right now ,it just adds columns x1 through x6, k, n, ncomb, j. &amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data combination;
   set comp4;
   by year gvkey;

   array x[6] $15 ('A' 'B' 'C' 'D' 'E' 'F');
   k=3;
   n=dim(x);
   ncomb=comb(n,k);
   do j=1 to ncomb+1;
      call allcomb(j, k, of x[*]);
	  AggRank = mean(x1,x2,x3);
	  /*put j 5. +3 x1-x3;*/
   end;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13682iF7DC0C1BDF3D435A/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="exampl3.PNG" title="exampl3.PNG" /&gt;</description>
      <pubDate>Sun, 09 Apr 2017 18:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348538#M273422</guid>
      <dc:creator>scrapex87</dc:creator>
      <dc:date>2017-04-09T18:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348548#M273423</link>
      <description>&lt;P&gt;You're close with your solution, but you need to convert the array names to variable values. Here's a long winded version of a solution, there's probably easier ways to simplify this code but each step helps to illustrate the issues while learning.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Key concepts:&lt;/P&gt;
&lt;P&gt;VVALUEX -&amp;gt; retrieve the value of a variable when you know the name&lt;/P&gt;
&lt;P&gt;CATT -&amp;gt; concatenate&amp;nbsp;variable values with no trailing spaces&lt;/P&gt;
&lt;P&gt;INPUT -&amp;gt; convert character value to a numeric value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When this step is&amp;nbsp;done you can transpose (PROC TRANSPOSE) your solution to get the wide data set you wanted.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data combination;
    set have;
    
    array x[6] A B C D E F;
    array nms(6) $  nms1-nms6 ('A' 'B' 'C' 'D' 'E' 'F');
    

    
    k=3;
    n=dim(x);
    ncomb=comb(n, k);

    do j=1 to ncomb+1;
        call allcomb(j, k, of nms[*]);
        comb = catt(of nms1-nms3);
        
        v1 = input(vvaluex(nms(1)), best12.);
        v2 = input(vvaluex(nms(2)), best12.);
        v3 = input(vvaluex(nms(3)), best12.);
        
        mean = mean(of v1-v3);

        output;

        /*put j 5. +3 x1-x3;*/
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - Please do not post data as an image. I will not type it out and you are more likely to get a response if people can work off sample data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2017 19:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348548#M273423</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-09T19:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348558#M273424</link>
      <description>&lt;P&gt;Hi Reeza,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply. It is basically giving me the data that I wanted. There is only one problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the dataset is created based on the test data set below, it will create 80 different rows of mean values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I still do 6 choose 3, that means 20 different combinations for each of the rows of data. Since i have 4 rows then the total is 80.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the dataset created has the right data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data testData;
infile datalines delimiter=','; 
INPUT A B C D E F;
DATALINES;
12,78,54,75,85,89
45,56,32,425,45,45
74,45,65,78,56,12
12,12,45,78,12,45
; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to transpose, I&amp;nbsp;only want to have 20 different mean values as columns. That means i have to transpose by "comb" column or group the values somehow. But "comb" has values 'ABC' or 'BCA' or 'CAB' or 'ACB'. So, instead of getting 20 columns, i am getting 80. Is there a way to either sort the value of "comb" when it is getting created. Something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;comb&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; sort(&lt;SPAN class="token function"&gt;catt&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of nms1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;nms3&lt;SPAN class="token punctuation"&gt;))&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;That way all combinations of A B C are "ABC" and not something else. Then i belive i can do the transpose by "comb".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully i didnt confuse you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for the help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2017 21:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348558#M273424</guid>
      <dc:creator>scrapex87</dc:creator>
      <dc:date>2017-04-09T21:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348559#M273425</link>
      <description>&lt;P&gt;CALL SORTC I think?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2017 21:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348559#M273425</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-09T21:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348565#M273427</link>
      <description>&lt;DIV class="Mu SP"&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;Reza&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;thank you for your help.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;Sortc is not helping much since im sorting nms1-nms3, and its not working correctly.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;PRE&gt;call allcomb(j, k, of nms[*]);

call sortc(of nms1-nms3);

comb = catt(of nms1-nms3);&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;what i am hoping to&amp;nbsp;do is the following&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;it would be great if we can have the do loop produce the means for 1 combination at a time&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;instead of looping throguh 20 combination&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;so what i am hopoing for is a 7th column labeled ABC&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;with the means of the 4 rows reported&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;then i hope for the loop to start doing ABD&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;aond compute the means of the 4 rows in each respective row&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;before moving to ABE&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;at present the code is running ABC, ABD, ABE and producing 80 lines of code and showing all interim mean computations&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;ideally the final output should be 20 columns (6 Choose 3)&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;and 4 rows that reports the averages of those those 3 columns&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="Mu SP"&gt;&lt;DIV class="xH"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;our dataset is large and it would be relatively inefficient if we perhaps continued this way&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 09 Apr 2017 22:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348565#M273427</guid>
      <dc:creator>scrapex87</dc:creator>
      <dc:date>2017-04-09T22:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348566#M273428</link>
      <description>&lt;P&gt;At this point I have no idea what you're looking for.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you'd like further help, post the sample solution - fully - for your sample data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, review the documentation for ALLCOMB. You'll notice they refer to LEXCOMB which will do it in order - though I have no idea why that matters at the moment. The TRANSPOSE should have reordered everything correctly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 00:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348566#M273428</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-10T00:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348876#M273429</link>
      <description>&lt;P&gt;Show what you want the data to look like for an example that includes your &lt;BR /&gt;&lt;SPAN class="tL8wMe EMoHub"&gt;"and 4 rows that reports the averages of those those 3 columns"&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, 10 Apr 2017 20:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348876#M273429</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-10T20:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348915#M273430</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;why did you do in the code&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;do j&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to ncomb&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of &amp;nbsp;"do j=1 to ncomb;"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran the code on a small sample data:&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input A B C D E F;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3 4 5 6&lt;BR /&gt;10 20 30 40 50 60&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and noticed that the 21st combination for each original observation is the exact copy of the 20th combination (and in this case ncomb = 20)?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 22:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348915#M273430</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-04-10T22:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Combinations means of dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348918#M273431</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12982"&gt;@ilikesas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;why did you do in the code&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;do j&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to ncomb&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of &amp;nbsp;"do j=1 to ncomb;"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran the code on a small sample data:&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input A B C D E F;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2 3 4 5 6&lt;BR /&gt;10 20 30 40 50 60&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and noticed that the 21st combination for each original observation is the exact copy of the 20th combination (and in this case ncomb = 20)?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I didn't check that logic to be honest, the OPs initial code used it and I left it in, but clearly that doesn't make sense. It should probably be ncomb.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 22:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combinations-means-of-dataset/m-p/348918#M273431</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-10T22:48:20Z</dc:date>
    </item>
  </channel>
</rss>

