<?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: How to summarize a column with combination of sum and product within a data column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771315#M244732</link>
    <description>&lt;P&gt;If I understand your requirement correctly, this should do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input count;
datalines;
2
3
5
6
8
9
;

proc sql noprint;
select nobs into :nobs from dictionary.tables
where libname = "WORK" and memname = "TEMP";
quit;

data want;
set temp;
array c {&amp;amp;nobs.} _temporary_;
c{_n_} = count;
sum = 0;
b = 0;
do i = 1 to _n_;
  do j = i + 1 to _n_;
    sum = sum + c{j};
  end;
  b = b + c{i} * sum;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 30 Sep 2021 07:21:09 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-09-30T07:21:09Z</dc:date>
    <item>
      <title>How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771284#M244713</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with two columns like the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;input item count;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;a1&amp;nbsp; &amp;nbsp;n1&lt;/P&gt;
&lt;P&gt;a2&amp;nbsp; &amp;nbsp;n2&lt;/P&gt;
&lt;P&gt;a3&amp;nbsp; &amp;nbsp;n3&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;ak&amp;nbsp; &amp;nbsp;nk&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, {n1, n2, ...,n k} are the counts of {a1,... ak}. I would like to compute the number b= (n1*n2 + n1*n3+ ... +n1*nk) + (n2*n3 + n2*n4+...n2*nk) + ...+&lt;/P&gt;
&lt;P&gt;(n_(k-1) *nk). Is there any efficient way to do it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 02:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771284#M244713</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2021-09-30T02:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771304#M244723</link>
      <description>&lt;P&gt;Suggest that you supply some actual numbers to the example data and the expected numeric result as a data set.&lt;/P&gt;
&lt;P&gt;Your data step doesn't run because of value type mismatch. N1 is not a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If by "&lt;/P&gt;
&lt;P&gt;Basically, {n1, n2, ...,n k} are the counts of {a1,... ak}. I would like to compute the number b= (n1*n2 + n1*n3+ ... +n1*nk) + (n2*n3 + n2*n4+...n2*nk) + ...+&lt;/P&gt;
&lt;P&gt;(n_(k-1) *nk). "&lt;/P&gt;
&lt;P&gt;If you actually want A in there somewhere you should use it. If A values have nothing to do with the calculation then don't bother to bring them into the data for the question.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 04:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771304#M244723</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-30T04:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771308#M244726</link>
      <description>&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;input count;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;6&lt;/P&gt;
&lt;P&gt;8&lt;/P&gt;
&lt;P&gt;9&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about this? This is actually abstract question, no data needed. but data may help the verification.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 04:20:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771308#M244726</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2021-09-30T04:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771315#M244732</link>
      <description>&lt;P&gt;If I understand your requirement correctly, this should do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input count;
datalines;
2
3
5
6
8
9
;

proc sql noprint;
select nobs into :nobs from dictionary.tables
where libname = "WORK" and memname = "TEMP";
quit;

data want;
set temp;
array c {&amp;amp;nobs.} _temporary_;
c{_n_} = count;
sum = 0;
b = 0;
do i = 1 to _n_;
  do j = i + 1 to _n_;
    sum = sum + c{j};
  end;
  b = b + c{i} * sum;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Sep 2021 07:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771315#M244732</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-30T07:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771324#M244739</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/42094"&gt;@Macro&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select (sum(count)**2-uss(count))/2 as b
from temp;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Sep 2021 08:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771324#M244739</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-30T08:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771330#M244751</link>
      <description>&lt;PRE&gt;data temp;
input id count;
datalines;
1 2
2 3
3 5
4 6
5 8
6 9
;
run;

proc sql;
select sum(a.count*b.count) as total
 from temp as a , temp as b
  where a.id&amp;lt;b.id;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Sep 2021 09:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771330#M244751</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-30T09:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771331#M244752</link>
      <description>COOL .</description>
      <pubDate>Thu, 30 Sep 2021 10:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771331#M244752</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-30T10:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771386#M244780</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Very neat solution using where statement of proc sql. In case my data temp does not have an ID column that is monotonic, but have an item column (numeric) that is not monotonic. How do we create an ID column, or can proc sql have an internal Id variable to make the where statement work, or other ways? Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 14:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771386#M244780</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2021-09-30T14:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771407#M244794</link>
      <description>&lt;P&gt;never knew what uss function was. I learn so much on this forum!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 15:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771407#M244794</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-09-30T15:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771415#M244800</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I learn so much on this forum!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks! So do I. In fact, this particular solution was inspired by some of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s posts where he cleverly used functions or even procedures to condense lengthy calculations.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 16:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771415#M244800</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-30T16:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771462#M244821</link>
      <description>&lt;P&gt;Thanks FreelanceReinhard. You really think mathematically in addition to programming, to recognize this sum is simply the sum of cross product terms from a complete square, and implement it with an existing function uss().&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 18:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771462#M244821</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2021-09-30T18:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771463#M244822</link>
      <description>&lt;P&gt;Thanks Kurt. This is the data step array way I am lookin for.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 18:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771463#M244822</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2021-09-30T18:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771485#M244835</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run your code, the data step way, I found I got different answer from other sql code. So what is the problem here? Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 20:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771485#M244835</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2021-09-30T20:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to summarize a column with combination of sum and product within a data column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771735#M244957</link>
      <description>Hi. You can make it easily by data step:&lt;BR /&gt;&lt;BR /&gt;data temp;&lt;BR /&gt;set temp;&lt;BR /&gt;id+1;&lt;BR /&gt;run;</description>
      <pubDate>Sat, 02 Oct 2021 06:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-summarize-a-column-with-combination-of-sum-and-product/m-p/771735#M244957</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-10-02T06:03:57Z</dc:date>
    </item>
  </channel>
</rss>

