<?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 How to find which numbers from a setadd up to a particular amount in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432604#M13408</link>
    <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’ve working on comparing transactions from two different sources that are supposed to share the same data as one is updated from the other but it seems that the one has been updated with subtotal &amp;nbsp;amounts and at different times. I’m looking for a way to find the numbers from a set sharing the same ID that equal a particular amount. For instance, let’s say I have a set of numbers from Variable X: 1,2,5,10,5,64,32,2 each in a different row all linked to a specific ID in variable Y and I want to know which sum from that set equals 34 which is indicated in each instance of varable z under that same ID. Is there a built in function to do this? I have tried running a cumulative sum upward and downward by indexing each instance of variable X under the same ID in variable Y but it never matches, however when I take a closer look I find that two or more amounts match the amount under that ID in variable Z. I hope you can help me figure this out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ‘m pretty new at SAS so excuse my ignorance. &amp;nbsp;I thought maybe a while loop would do it but I would need to do it in order, which I sort of already tried.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 04:31:57 GMT</pubDate>
    <dc:creator>SASonist</dc:creator>
    <dc:date>2018-01-31T04:31:57Z</dc:date>
    <item>
      <title>How to find which numbers from a setadd up to a particular amount</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432604#M13408</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’ve working on comparing transactions from two different sources that are supposed to share the same data as one is updated from the other but it seems that the one has been updated with subtotal &amp;nbsp;amounts and at different times. I’m looking for a way to find the numbers from a set sharing the same ID that equal a particular amount. For instance, let’s say I have a set of numbers from Variable X: 1,2,5,10,5,64,32,2 each in a different row all linked to a specific ID in variable Y and I want to know which sum from that set equals 34 which is indicated in each instance of varable z under that same ID. Is there a built in function to do this? I have tried running a cumulative sum upward and downward by indexing each instance of variable X under the same ID in variable Y but it never matches, however when I take a closer look I find that two or more amounts match the amount under that ID in variable Z. I hope you can help me figure this out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ‘m pretty new at SAS so excuse my ignorance. &amp;nbsp;I thought maybe a while loop would do it but I would need to do it in order, which I sort of already tried.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 04:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432604#M13408</guid>
      <dc:creator>SASonist</dc:creator>
      <dc:date>2018-01-31T04:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to find which numbers from a setadd up to a particular amount</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432617#M13409</link>
      <description>&lt;P&gt;it is little bit confusing. can you please illustrate with simple example with input you have and output you want to see.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 06:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432617#M13409</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-01-31T06:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to find which numbers from a setadd up to a particular amount</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432625#M13410</link>
      <description>&lt;P&gt;It's hard.&amp;nbsp; It can be done.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an approach, but not the full code that would get you there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Construct a temporary array holding all X for a single ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array xvals {30} _temporary_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fill it so that xvals{1} = 1, xvals{2}=2, ... , xvals{7} = 32, xvals{8} = 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As the number of elements increases, the processing takes quite a while&amp;nbsp; That's the reason I cut things off at 30.&amp;nbsp; Even that is probably more than you want to consider ... there would be 2**30 combinations to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Find the sum of each combination.&amp;nbsp; I'm going to hard-code the equation, without adding the complication of counting how many of the elements are actually filled.&amp;nbsp; That's just to show you the nature of the approach.&amp;nbsp; The programming does become complex at that point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do c1=0, 1;&lt;/P&gt;
&lt;P&gt;do c2=0, 1;&lt;/P&gt;
&lt;P&gt;do c3=0, 1;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;do c8=0, 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;total = c1 * xvals{1} + c2 * xvals{2} + ... + c8 * xval{8};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if total=34 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ** Figuring out what to do when a match is found is not that easy either!&amp;nbsp; More than 1 combination can total to 34 ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;end;end;end;end;&lt;/P&gt;
&lt;P&gt;end;end;end;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's at least the framework for the programming.&amp;nbsp; It's not easy, even for experienced programmers.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 07:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432625#M13410</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-31T07:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to find which numbers from a setadd up to a particular amount</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432798#M13413</link>
      <description>&lt;P&gt;Is there any other data involved such as a transaction&amp;nbsp;date, transaction type&amp;nbsp;or similar?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 15:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-find-which-numbers-from-a-setadd-up-to-a-particular/m-p/432798#M13413</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-31T15:44:53Z</dc:date>
    </item>
  </channel>
</rss>

