<?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: Combining Two datasets with a single data statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330775#M74277</link>
    <description>&lt;P&gt;Post test data in the form of a datastep. &amp;nbsp;Your example doesn't make sense either. &amp;nbsp;Why is number two split,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; $300 &amp;lt;= ($600-$500), then I divide the record into two new records:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But in your given test data neither 600 or 500 are present in that row of data, I suppose 600 could come from teh second example, but still don't see any 500 at all for that observation.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2017 10:35:11 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-02-08T10:35:11Z</dc:date>
    <item>
      <title>Combining Two datasets with a single data statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330768#M74274</link>
      <description>&lt;P&gt;Hello all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a bit problem, so here it goes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with the following records:&lt;/P&gt;&lt;P&gt;Fond &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Money &amp;nbsp; Cumulative_Money&lt;/P&gt;&lt;P&gt;Fond_1 &amp;nbsp; &amp;nbsp; $500 &amp;nbsp; &amp;nbsp; $500&lt;/P&gt;&lt;P&gt;Fond_2 &amp;nbsp; &amp;nbsp; $300 &amp;nbsp; &amp;nbsp; $800&lt;/P&gt;&lt;P&gt;Fond_3 &amp;nbsp; &amp;nbsp; $1000 &amp;nbsp; $1800&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, I have another dataset with the following information:&lt;/P&gt;&lt;P&gt;Dept &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Money_Dpt.&lt;/P&gt;&lt;P&gt;D_1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 600&lt;/P&gt;&lt;P&gt;D_2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 700&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I would need a loop, or a do-until sentence, in order to obtain the next result:&lt;/P&gt;&lt;P&gt;Fond &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Money &amp;nbsp; &amp;nbsp;Percentage_Money_Dpt &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dpt.&lt;/P&gt;&lt;P&gt;Fond_1 &amp;nbsp; &amp;nbsp; &amp;nbsp;$500 &amp;nbsp; &amp;nbsp; &amp;nbsp; $500 &amp;lt;= $600, then 100% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D_1&lt;/P&gt;&lt;P&gt;Fond_2 &amp;nbsp; &amp;nbsp; &amp;nbsp;$300 &amp;nbsp; &amp;nbsp; &amp;nbsp; $300 &amp;lt;= ($600-$500), then I divide the record into two new records:&lt;/P&gt;&lt;P&gt;Fond_2A &amp;nbsp; &amp;nbsp;$100 &amp;nbsp; &amp;nbsp; &amp;nbsp; $100 &amp;lt;= ($600-$500) then 100% &amp;nbsp; &amp;nbsp;D_1&lt;/P&gt;&lt;P&gt;Fond_2B &amp;nbsp; &amp;nbsp;$200 &amp;nbsp; &amp;nbsp; &amp;nbsp; $200 &amp;lt;= $700 &amp;nbsp; &amp;nbsp; &amp;nbsp;then 100% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D_2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate a lot your help! U rock!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance! Kind regards!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 10:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330768#M74274</guid>
      <dc:creator>Gcruzg</dc:creator>
      <dc:date>2017-02-08T10:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Two datasets with a single data statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330775#M74277</link>
      <description>&lt;P&gt;Post test data in the form of a datastep. &amp;nbsp;Your example doesn't make sense either. &amp;nbsp;Why is number two split,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; $300 &amp;lt;= ($600-$500), then I divide the record into two new records:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But in your given test data neither 600 or 500 are present in that row of data, I suppose 600 could come from teh second example, but still don't see any 500 at all for that observation.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 10:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330775#M74277</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-08T10:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Two datasets with a single data statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330778#M74279</link>
      <description>&lt;P&gt;You're right!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$600 comes from the second dataset, and $500 is the first money amount in the first data set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I explain to you. I need to divide the second record into two because $300 is not less or greater than $600 that I recieved from Department_1 minus $500 I spent. So, I divide into: a first record call Fond_2A where I say: the first $100 I have spent are from the first department, and the rest $200 I use the money from Department_2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 10:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330778#M74279</guid>
      <dc:creator>Gcruzg</dc:creator>
      <dc:date>2017-02-08T10:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Two datasets with a single data statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330877#M74302</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not totally sure of how this should working, as there seem to be some missing pieces...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, total Money_Dpt sums 1300, and you have 1800 in table FOND to distribute...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, here's a try that will load the DPT table into an hash table (in memory) and work from there to distribute the amounts of in the FOND table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
     set FOND;&lt;BR /&gt;     keep FOND Money Cumulative_Money Dept; * keep result vars;
     if 0 then set DEPS; * merge table layouts;
     if _N_ eq 1 then do;
        declare hash HD(dataset: 'DPT'); 
        _RC = HD.defineKey('Dept'); 
        _RC = HD.defineData(all:'yes'); 
        HD.defineDone(); * hash to load Depts;
        declare hiter HI('HD'); * iterator to traverse it;
     end;
     _Money=0;
     _RC=HI.first(); * get first Dept in iterator;
     do until (HI.next());
        if Money gt Money_Dpt then do; * check if enough;
           _Money=Money-Money_Dpt;
           Money=Money_Dpt;
        end;
        else _Money=0; * enough, set 100%;
        if Money gt 0 then output; * if done, output;
        Money_Dpt+(-Money); * adjust amount available for Dept;
        Money=_Money; * adjust to remaining money to fund;
        _RC = HD.replace(); * replace amount available for Dept;&lt;BR /&gt;     end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will get you&amp;nbsp;the following for the example you provided:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;FOND &amp;nbsp; &amp;nbsp;Money &amp;nbsp;Money &amp;nbsp;Dept&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Fond_1 &amp;nbsp;500 &amp;nbsp; &amp;nbsp;500 &amp;nbsp; &amp;nbsp;D_1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Fond_2 &amp;nbsp;100 &amp;nbsp; &amp;nbsp;800 &amp;nbsp; &amp;nbsp;D_1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Fond_2 &amp;nbsp;200 &amp;nbsp; &amp;nbsp;800 &amp;nbsp; &amp;nbsp;D_2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Fond_3 &amp;nbsp;500 &amp;nbsp; &amp;nbsp;1800 &amp;nbsp; D_2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Of course, Fond_3 gets only 500 of the (1000 needed) from D_2, since there is no more Money there.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Hope it helps.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 16:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330877#M74302</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-08T16:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Two datasets with a single data statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330881#M74303</link>
      <description>Thank you so much Daniel! It's exactly what I need, apart from some changes I will make...&lt;BR /&gt;&lt;BR /&gt;Dude, U rock!</description>
      <pubDate>Wed, 08 Feb 2017 16:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-Two-datasets-with-a-single-data-statement/m-p/330881#M74303</guid>
      <dc:creator>Gcruzg</dc:creator>
      <dc:date>2017-02-08T16:09:08Z</dc:date>
    </item>
  </channel>
</rss>

