<?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: Compare SUM of any 2 or more values from one dataset with SUM of any 2 or more values from anoth in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-SUM-of-any-2-or-more-values-from-one-dataset-with-SUM-of/m-p/563438#M33884</link>
    <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;Yes, the GRAYCODE() could be useful for this problem.&lt;/P&gt;&lt;P&gt;Let’s simplify it to one value being matched with two or more:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;data TEST.A_TWO;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; input TRANSACTION_ID AMOUNT &lt;STRONG&gt;MULTI_CNT&lt;/STRONG&gt; &lt;STRONG&gt;CNT&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 100 2.10 1 1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 100 3.10 2 2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 200 3.00 1 3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 200 2.50 2 &lt;FONT color="#FF0000"&gt;4&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 200 2.50 3 &lt;FONT color="#FF0000"&gt;5&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 200 1.00 4 6&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let val_1=5;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* value to be matched &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let transaction_id=&lt;STRONG&gt;200&lt;/STRONG&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* within this transaction_id &amp;nbsp;*/&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; select count(*) into: MAX_NUM_OF_TRANS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; from TEST.A_TWO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; where TRANSACTION_ID = &amp;amp;transaction_id;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now we know that there are &lt;STRONG&gt;4&lt;/STRONG&gt; transactions of &lt;STRONG&gt;transaction_id&lt;/STRONG&gt;=&lt;STRONG&gt;200&lt;/STRONG&gt; and we can use &lt;STRONG&gt;MULTI_CNT&lt;/STRONG&gt; to identify them. The task remains to produce combinations: 1,2; 2,3;. . .; 1,2,3,4 to finally get combination '2,3' that leads to &lt;STRONG&gt;CNT &lt;FONT color="#FF0000"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt; and &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;5&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;that uniquely identify the matches:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let range=2,3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; select SUM(AMOUNT) from TEST.A_TWO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; where TRANSACTION_ID = &amp;amp;transaction_id&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; and MULTI_CNT IN (&amp;amp;range);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;If there are multiple combinations that produce the same SUM, the first one is sufficient.&lt;BR /&gt;Thanks a lot for the ideas.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jun 2019 04:36:28 GMT</pubDate>
    <dc:creator>Dawn3</dc:creator>
    <dc:date>2019-06-04T04:36:28Z</dc:date>
    <item>
      <title>Compare SUM of any 2 or more values from one dataset with SUM of any 2 or more values from another</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-SUM-of-any-2-or-more-values-from-one-dataset-with-SUM-of/m-p/563140#M33861</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;How to find if &lt;STRONG&gt;SUM of any&lt;/STRONG&gt; &lt;STRONG&gt;2 or more values&lt;/STRONG&gt; from one dataset &lt;STRONG&gt;matches SUM of any 2 or more values&lt;/STRONG&gt; from another dataset?&lt;BR /&gt;There are always at least two values (VAR1 and VAR2) in each dataset, and number of VARs are not necessarily the same.&lt;/P&gt;&lt;P&gt;Currently I am using this table to drive the process:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data TEST.COMBINATIONS;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; input VAR1 VAR2 VAR3 VAR4 VAR5 &lt;STRONG&gt;MAX_VAR_NUM&lt;/STRONG&gt; CNT;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 2 . . . 2 1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 3 . . . 3 2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 3 . . . 3 3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 2 3 . . 3 4&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 4 . . . 4 5&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 4 . . . 4 6&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 3 4 . . . 4 7&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 3 4 . . 4 8&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 2 3 4 . 4 9&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 5 . . . 5 10&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 5 . . . 5 11&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 3 5 . . . 5 12&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 4 5 . . . 5 13&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 3 4 5 . . 5 14&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 3 4 5 . 5 15&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 4 5 . . 5 16&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 2 3 4 5 5 17&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;For example, if there are only two values in 1st dataset &lt;STRONG&gt;(MAX_VAR_NUM=2)&lt;/STRONG&gt; than only &lt;STRONG&gt;SUM(VAR1, VAR2)&lt;/STRONG&gt; is to be used.&lt;BR /&gt;If there are 3 values in 2nd dataset (&lt;STRONG&gt;MAX_VAR_NUM=3&lt;/STRONG&gt;) than all combinations up to &lt;STRONG&gt;CNT 4&lt;/STRONG&gt; are to be compared with SUM(VAR1, VAR2) from 1st dataset:&lt;/P&gt;&lt;P&gt;SUM(VAR1, VAR2),&lt;BR /&gt;SUM(VAR1, VAR3),&lt;BR /&gt;SUM(VAR2, VAR3),&lt;BR /&gt;SUM(VAR1, VAR2, VAR3).&lt;/P&gt;&lt;P&gt;Is there a better way that hardcoding? The solution above is limited by the number of hardcoded combinations in the COMBINATIONS table.&lt;BR /&gt;Since SUM(&lt;STRONG&gt;VAR1, VAR2)&lt;/STRONG&gt; = SUM(&lt;STRONG&gt;VAR2, VAR1&lt;/STRONG&gt;) function &lt;STRONG&gt;LEXPERM&lt;/STRONG&gt; was not helpful for this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jun 2019 21:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-SUM-of-any-2-or-more-values-from-one-dataset-with-SUM-of/m-p/563140#M33861</guid>
      <dc:creator>Dawn3</dc:creator>
      <dc:date>2019-06-02T21:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Compare SUM of any 2 or more values from one dataset with SUM of any 2 or more values from anoth</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-SUM-of-any-2-or-more-values-from-one-dataset-with-SUM-of/m-p/563254#M33866</link>
      <description>&lt;P&gt;Try function GRAYCODE() .&lt;/P&gt;
&lt;P&gt;Can you post these two datasets ?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 13:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-SUM-of-any-2-or-more-values-from-one-dataset-with-SUM-of/m-p/563254#M33866</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-03T13:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Compare SUM of any 2 or more values from one dataset with SUM of any 2 or more values from anoth</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-SUM-of-any-2-or-more-values-from-one-dataset-with-SUM-of/m-p/563438#M33884</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;Yes, the GRAYCODE() could be useful for this problem.&lt;/P&gt;&lt;P&gt;Let’s simplify it to one value being matched with two or more:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;data TEST.A_TWO;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; input TRANSACTION_ID AMOUNT &lt;STRONG&gt;MULTI_CNT&lt;/STRONG&gt; &lt;STRONG&gt;CNT&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 100 2.10 1 1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 100 3.10 2 2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 200 3.00 1 3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 200 2.50 2 &lt;FONT color="#FF0000"&gt;4&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 200 2.50 3 &lt;FONT color="#FF0000"&gt;5&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 200 1.00 4 6&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let val_1=5;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* value to be matched &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let transaction_id=&lt;STRONG&gt;200&lt;/STRONG&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* within this transaction_id &amp;nbsp;*/&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; select count(*) into: MAX_NUM_OF_TRANS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; from TEST.A_TWO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; where TRANSACTION_ID = &amp;amp;transaction_id;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now we know that there are &lt;STRONG&gt;4&lt;/STRONG&gt; transactions of &lt;STRONG&gt;transaction_id&lt;/STRONG&gt;=&lt;STRONG&gt;200&lt;/STRONG&gt; and we can use &lt;STRONG&gt;MULTI_CNT&lt;/STRONG&gt; to identify them. The task remains to produce combinations: 1,2; 2,3;. . .; 1,2,3,4 to finally get combination '2,3' that leads to &lt;STRONG&gt;CNT &lt;FONT color="#FF0000"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt; and &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;5&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;that uniquely identify the matches:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%let range=2,3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; select SUM(AMOUNT) from TEST.A_TWO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; where TRANSACTION_ID = &amp;amp;transaction_id&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; and MULTI_CNT IN (&amp;amp;range);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;If there are multiple combinations that produce the same SUM, the first one is sufficient.&lt;BR /&gt;Thanks a lot for the ideas.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 04:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-SUM-of-any-2-or-more-values-from-one-dataset-with-SUM-of/m-p/563438#M33884</guid>
      <dc:creator>Dawn3</dc:creator>
      <dc:date>2019-06-04T04:36:28Z</dc:date>
    </item>
  </channel>
</rss>

