<?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 sum volume of contracts for product within volume ranges in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234418#M42868</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what i have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get information for interest levels for one product like this in a dataset1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Productcode&amp;nbsp;&amp;nbsp; Level in EUR&amp;nbsp;&amp;nbsp; Interestrate&lt;/P&gt;&lt;P&gt;123&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;&amp;nbsp;&amp;nbsp; 999.999.999&amp;nbsp;&amp;nbsp; 0,10&lt;/P&gt;&lt;P&gt;123&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100.000&amp;nbsp;&amp;nbsp; 0,20&lt;/P&gt;&lt;P&gt;123&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 50.000 &amp;nbsp; 0,30&lt;/P&gt;&lt;P&gt;123 &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; 10.000 &amp;nbsp; 0,50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this means i pay for the customer 0,50% up to 10.000 EUR between 10000 and 50000 I pay 0,30% and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another dateset2 with all the contracts and of course also with the Productcode 123.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to now how many volume is within my 4 interest buckets over all the contracts with code 123 so to calculate my avarage interest rate i pay vor the product in total.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&amp;nbsp;&lt;/P&gt;&lt;P&gt;contract1 with balance 75.000 schould end in sum 10000 for the 1st bucket 40000 for the 2nd bucket and 25000 for the 3rd bucket. I think you got the idea.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any usefill funktion in SAS Base 9.2 which kan help or do I need to programm a macro up from zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for some ideas.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Nov 2015 17:23:23 GMT</pubDate>
    <dc:creator>eberhard1945</dc:creator>
    <dc:date>2015-11-12T17:23:23Z</dc:date>
    <item>
      <title>sum volume of contracts for product within volume ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234418#M42868</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what i have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get information for interest levels for one product like this in a dataset1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Productcode&amp;nbsp;&amp;nbsp; Level in EUR&amp;nbsp;&amp;nbsp; Interestrate&lt;/P&gt;&lt;P&gt;123&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;&amp;nbsp;&amp;nbsp; 999.999.999&amp;nbsp;&amp;nbsp; 0,10&lt;/P&gt;&lt;P&gt;123&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100.000&amp;nbsp;&amp;nbsp; 0,20&lt;/P&gt;&lt;P&gt;123&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 50.000 &amp;nbsp; 0,30&lt;/P&gt;&lt;P&gt;123 &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; 10.000 &amp;nbsp; 0,50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this means i pay for the customer 0,50% up to 10.000 EUR between 10000 and 50000 I pay 0,30% and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another dateset2 with all the contracts and of course also with the Productcode 123.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to now how many volume is within my 4 interest buckets over all the contracts with code 123 so to calculate my avarage interest rate i pay vor the product in total.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&amp;nbsp;&lt;/P&gt;&lt;P&gt;contract1 with balance 75.000 schould end in sum 10000 for the 1st bucket 40000 for the 2nd bucket and 25000 for the 3rd bucket. I think you got the idea.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any usefill funktion in SAS Base 9.2 which kan help or do I need to programm a macro up from zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for some ideas.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 17:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234418#M42868</guid>
      <dc:creator>eberhard1945</dc:creator>
      <dc:date>2015-11-12T17:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: sum volume of contracts for product within volume ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234419#M42869</link>
      <description>I think you may be able to do a SQL merge. Can you provide some more sample data and preferably some sample output?</description>
      <pubDate>Thu, 12 Nov 2015 17:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234419#M42869</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-12T17:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: sum volume of contracts for product within volume ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234440#M42874</link>
      <description>&lt;P&gt;I think this will do the trick for you.&amp;nbsp; You can also use proc sql; instead of proc freq:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data;&lt;BR /&gt;infile cards dsd;&lt;BR /&gt;input Productcode$&amp;nbsp;&amp;nbsp; Level_in_EUR;&lt;BR /&gt;cards;&lt;BR /&gt;123,1&lt;BR /&gt;123,2&lt;BR /&gt;123,999999&lt;BR /&gt;123,58&lt;BR /&gt;123,35&lt;BR /&gt;123,27&lt;BR /&gt;123,15&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value eur low-10&amp;nbsp;&amp;nbsp;&amp;nbsp; = '50%'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11-50&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = '30%'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 51-100&amp;nbsp;&amp;nbsp;&amp;nbsp; = '20%'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 101-high&amp;nbsp; = '10%';&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set data;&lt;BR /&gt;new_val = level_in_eur;&lt;BR /&gt;format new_val eur.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc freq data= want;table new_val;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 18:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234440#M42874</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-11-12T18:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: sum volume of contracts for product within volume ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234441#M42875</link>
      <description>I don't think that will work, as it's a progressive implementation. For example a value of 75 has 50% on the first 10, 30% on the next 40 and 20% on the next 25.  At least that's the way I understood it. So each value has to be broken down into groups. &lt;BR /&gt;And I think the breakdown is different for each group.  &lt;BR /&gt;&lt;BR /&gt;Need more data to understand the issue I think.</description>
      <pubDate>Thu, 12 Nov 2015 18:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234441#M42875</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-12T18:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: sum volume of contracts for product within volume ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234465#M42879</link>
      <description>&lt;P&gt;Let us know if following is what you are looking for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
infile cards dsd;
input Productcode$   level rate;
cards;
123,10,10
123,50,20
123,100,30
123,999999,50
;

data data2;
infile cards dsd;
input contract Productcode$   balance;
cards;
1,123,75
2,123,12
3,123,175
;
run;

proc sql noprint;
	create table want as
	select a.*,b.level, b.rate
	from data2 as a left join data1 as b
	on a.Productcode=b.Productcode
	order by a.Productcode, a.contract, b.level;
quit;

data want;
	set want;
	by Productcode contract level;
	retain diff;
	if first.contract and balance-level&amp;gt;=0 then do; balbylevel=level; diff=balance-level; end;
	else if first.contract and balance-level&amp;lt;0 then do; balbylevel=balance; diff=0; end;
	else do;
		if diff=0 then balbylevel=0;
		else if diff&amp;gt;level then do; balbylevel=level-(balance-diff); diff=balance-level; end;
		else do; balbylevel=diff; diff=0; end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Nov 2015 20:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234465#M42879</guid>
      <dc:creator>ndp</dc:creator>
      <dc:date>2015-11-12T20:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: sum volume of contracts for product within volume ranges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234564#M42891</link>
      <description>&lt;P&gt;Thank you all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess working on the way ndp recommended will lead to success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I test it and identify one issue with the&amp;nbsp;code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set want;
	by Productcode contract level;
	retain diff;
	if first.contract and balance-level&amp;gt;=0 then do; balbylevel=level; diff=balance-level; end;
	else if first.contract and balance-level&amp;lt;0 then do; balbylevel=balance; diff=0; end;
	else do;
		if diff=0 then balbylevel=0;
		else if diff&amp;gt;level then do; balbylevel=level-(balance-diff); diff=balance-level; end;
		else do; balbylevel=diff; diff=0; end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;line&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;else if diff&amp;gt;level then do; balbylevel=level-(balance-diff); diff=balance-level; end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;leads to wrong results if you only compare the current diff value with the current level value. you have to compare the current diff value with the (current level value - the previous level value). &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So i think i need another retaining variable I call "prelevel" for the last lavel value to substract from the actual level value for that check which leads to 100% correct results for every of my contracts:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set want;
	by Productcode contract level;
	retain diff;
	retain prelevel;
	if first.contract and balance-level&amp;gt;=0 then do; balbylevel=level; diff=balance-level; prelevel=level; end;
	else if first.contract and balance-level&amp;lt;0 then do; balbylevel=balance; diff=0; end;
	else do;
		if diff=0 then balbylevel=0;
		else if diff&amp;gt;(level-prelevel) then do; balbylevel=level-(balance-diff); diff=balance-level; prelevel=level; end;
		else do; balbylevel=diff; diff=0; end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At least a simple summary query shows the total volume at each&amp;nbsp;interest level of the product making calculating the avarage interest rate also very easy.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2015 11:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-volume-of-contracts-for-product-within-volume-ranges/m-p/234564#M42891</guid>
      <dc:creator>eberhard1945</dc:creator>
      <dc:date>2015-11-13T11:23:22Z</dc:date>
    </item>
  </channel>
</rss>

