<?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 use a lookup table using iterations? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618422#M181420</link>
    <description>&lt;P&gt;Code using a lookup table could look like below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data price;
  input quantity price;
  datalines;
1 5
2 9
3 13
4 16
;

data sample;
  input quantityBought;
  datalines;
9
25
5
;

data want(drop=_:);
  if _n_=1 then
    do;
      if 0 then set price;
      dcl hash h1(dataset:'price', ordered:'y', hashexp:4);
      dcl hiter hh1('h1');
      h1.defineKey('quantity');
      h1.defineData('quantity', 'price');
      h1.defineDone();
    end;

  set sample;
  _remain=quantityBought;
  _rc = hh1.last();
  do while (_rc = 0);
    _factor=int(_remain/quantity);
    if _factor&amp;gt;0 then
      do;
        PriceSum=sum(PriceSum, _factor*price);
        _remain=_remain-_factor*quantity;
        if _remain&amp;lt;=0 then leave;
      end;
    _rc = hh1.prev();
  end;
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 19 Jan 2020 23:31:59 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-01-19T23:31:59Z</dc:date>
    <item>
      <title>How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618412#M181413</link>
      <description>&lt;P&gt;I've been struggling with this for a while and thought I'd throw the question up here to see what happens.&lt;BR /&gt;&lt;BR /&gt;Consider this hypothetical.&amp;nbsp; I've got a company that sells widgets.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;1 for $5&lt;BR /&gt;2 for $9&lt;BR /&gt;3 for $13&lt;BR /&gt;4 for $16&lt;BR /&gt;&lt;BR /&gt;Customer A buys 1, Customer B buys 2, C buys 3, D buys 4.&amp;nbsp; This can be solved with a simple merge.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What if I have a customer who buys 9?&amp;nbsp; He would basically buy 4, 4, and 1 for 16 + 16 + 5 = $37.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Is there a way to do this with some sort of Do Until loop?&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've already solved this by hard coding the transformations with do until loops and if then statements, but I'd like to do it with a lookup tables so that I can change the prices later without having to change the program.&lt;BR /&gt;&lt;BR /&gt;I have also figured out how to do this by just coping and pasting the merge code and repeating the data step over and over again.&amp;nbsp; The problem there is I would have to guess what the maximum time I would ever need to do this would be.&amp;nbsp; For example, with this case I would run the code three times.&amp;nbsp; However, if a customer buys 17 widgets, I'd have to run the code 5 times.&lt;BR /&gt;&lt;BR /&gt;Any thoughts?&amp;nbsp; Thanks!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 22:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618412#M181413</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2020-01-19T22:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618415#M181415</link>
      <description>&lt;P&gt;Iterations don't seem necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about using math? If a customer buys 9, then 9 integer divide by 4 is 2, plus a remainder of 1. So the math is 2*(cost of 4) + (cost of 1). If your lookup table is an array which I shall creatively name COST, then for any quantity purchased n&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if mod(n, dim(cost)) = 0 then total_cost = floor(n/dim(cost)) * cost(dim(cost));
else total_cost = floor(n/dim(cost)) * cost(dim(cost)) + cost(mod(n, dim(cost)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 19 Jan 2020 23:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618415#M181415</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-19T23:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618422#M181420</link>
      <description>&lt;P&gt;Code using a lookup table could look like below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data price;
  input quantity price;
  datalines;
1 5
2 9
3 13
4 16
;

data sample;
  input quantityBought;
  datalines;
9
25
5
;

data want(drop=_:);
  if _n_=1 then
    do;
      if 0 then set price;
      dcl hash h1(dataset:'price', ordered:'y', hashexp:4);
      dcl hiter hh1('h1');
      h1.defineKey('quantity');
      h1.defineData('quantity', 'price');
      h1.defineDone();
    end;

  set sample;
  _remain=quantityBought;
  _rc = hh1.last();
  do while (_rc = 0);
    _factor=int(_remain/quantity);
    if _factor&amp;gt;0 then
      do;
        PriceSum=sum(PriceSum, _factor*price);
        _remain=_remain-_factor*quantity;
        if _remain&amp;lt;=0 then leave;
      end;
    _rc = hh1.prev();
  end;
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jan 2020 23:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618422#M181420</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-01-19T23:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618425#M181422</link>
      <description>&lt;P&gt;Hi Page, can you help me out with that a bit?&amp;nbsp; I thought that maybe an "array" might help.&amp;nbsp; I've taken the first 2 SAS programming classes and have about 2 years experience.&amp;nbsp; I'm sure there's a new technique I need do delve into.&lt;BR /&gt;&lt;BR /&gt;Can you give me a little more detail?&amp;nbsp; Thanks!&lt;BR /&gt;&lt;BR /&gt;FWIW, the way I would normally do this would be:&lt;BR /&gt;&lt;BR /&gt;GIVEN TABLES:&lt;BR /&gt;&lt;BR /&gt;Customer_Table:&lt;BR /&gt;&lt;BR /&gt;Customer&amp;nbsp; &amp;nbsp;Num_items&lt;BR /&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;BR /&gt;E&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cost_Table&lt;BR /&gt;&lt;BR /&gt;Num_items&amp;nbsp; &amp;nbsp; &amp;nbsp;Cost&lt;BR /&gt;1&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; $5&lt;/P&gt;
&lt;P&gt;2&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; $9&lt;/P&gt;
&lt;P&gt;3&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; $13&lt;/P&gt;
&lt;P&gt;4&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; $16&lt;BR /&gt;9&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; $37&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;SAS CODE:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Data New_Table;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; merge Customer_Table Cost_Table;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;by Num_items;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The problem here, or course, is that I'd have to have a cost for every possible value for num_items.&lt;BR /&gt;&lt;BR /&gt;&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 23:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618425#M181422</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2020-01-19T23:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618426#M181423</link>
      <description>&lt;P&gt;Hmmm, this may be the way to do it.&amp;nbsp; I don't understand all of your code, but I'm guessing there's something in there that pulls elements out of the price table and treats them like variables?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 23:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618426#M181423</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2020-01-19T23:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618428#M181425</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84517"&gt;@BarryP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hmmm, this may be the way to do it.&amp;nbsp; I don't understand all of your code, but I'm guessing there's something in there that pulls elements out of the price table and treats them like variables?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Given that you're using SAS since two years it's likely worth that you skill-up with the SAS hash and hash iterator object.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 23:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618428#M181425</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-01-19T23:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618429#M181426</link>
      <description>&lt;P&gt;So data set Customer is as you show it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     array cost cost1-cost4 (5 9 13 16);
     set customer;
     if mod(num_items, dim(cost)) = 0 then total_cost = 
        floor(num_items/dim(cost)) * cost(dim(cost));
    else total_cost = floor(num_items/dim(cost)) * cost(dim(cost)) + 
        cost(mod(num_items, dim(cost)));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 19 Jan 2020 23:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618429#M181426</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-19T23:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618430#M181427</link>
      <description>&lt;P&gt;Looking it up now.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 00:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618430#M181427</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2020-01-20T00:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618432#M181429</link>
      <description>&lt;P&gt;To be honest, I don't see this&amp;nbsp;single-product problem as a very good example of the benefits of hash, especially because the priced quantities are integers from 1 to 4.&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s code appears to be very compact for this problem, using an array indexed by the integers 1:4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If what your are really looking for is having the prices in a separated data set, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s code still works.&amp;nbsp; It just has to be preceded by a proc transpose:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prices;
  input cost;
datalines;
5
6
13
16
run;
proc transpose data=prices out=costs (drop=_name_) prefix=cost;
run;

data orders;
  input qty_ordered;
datalines;
5
25
19
run;

data want;
  set orders;
  if _n_=1 then set costs;
  array _prcs {*} cost:  ;
  total_cost=floor(qty_ordered/dim(_prcs))*_prcs{dim(_prcs)};
  if mod(qty_ordered,dim(_prcs))^=0 then total_cost=total_cost + _prcs{mod(qty_ordered,dim(_prcs))};
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I think using hash&amp;nbsp;would be very educational&amp;nbsp;if&amp;nbsp;you had prices for multiple products ("A","B", etc.) up in the prices dataset.&amp;nbsp; Then&amp;nbsp;I could see enhancing&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s code with a hash, keyed on the product ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code above changed per &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s observation.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 04:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618432#M181429</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-20T04:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618433#M181430</link>
      <description>&lt;P&gt;I agree with your comments about hash being unnecessary for the problem as stated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code needs to be adjusted for the case where this quantity is equal to zero. &lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;mod&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;qty_ordered&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;dim&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;_prcs&lt;SPAN class="token punctuation"&gt;))&amp;nbsp;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 20 Jan 2020 00:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618433#M181430</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-20T00:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618444#M181435</link>
      <description>&lt;P&gt;I used the price and quantity to simplify the problem.&amp;nbsp; The real problem is a little more complicated.&amp;nbsp; We are replacing combinations of lab instruments with different combinations of new lab instruments.&amp;nbsp; So its more like:&lt;BR /&gt;&lt;BR /&gt;1 Inst_A &amp;amp; 1 Inst_B = 2 inst_X &amp;amp; 1 inst_Y&lt;BR /&gt;2 inst_A &amp;amp; 1 Inst_B = 1 inst_Z&lt;BR /&gt;2 inst_A &amp;amp; 2 Inst_B = 3 inst_X &amp;amp; 1 inst_Y&lt;BR /&gt;1 inst_A &amp;amp; 1 inst_C = 1 inst_X &amp;amp; 2 inst_Z&lt;BR /&gt;&lt;BR /&gt;etc.&lt;BR /&gt;&lt;BR /&gt;I have a list of ~100 different combinations of 6 instruments and what they translate to (different combinations of 5 instruments).&amp;nbsp; The lookup table accounts for about 80% of our customer base.&amp;nbsp; Its the remaining 20% that I'm trying to write algorithms for.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For example, I have a lookup of 6 Inst_B &amp;amp; 1 Inst_C but I have a customer with 13 Inst_B and 4_Inst_C.&amp;nbsp; My current algorithm translates 6 Inst_B &amp;amp; 1 Inst_C, then 6 Inst_B &amp;amp; 1 Inst_C again, then 1 Inst_B &amp;amp; 1_Inst_C, and then finally 1 Inst_C.&lt;BR /&gt;&lt;BR /&gt;Those translate to (respectively):&lt;BR /&gt;&lt;BR /&gt;1 Inst_W, 3 Inst_Y, 1 Inst_Z&lt;BR /&gt;1 Inst_W, 3 Inst_Y, 1 Inst_Z&lt;BR /&gt;1 Inst_V, 1 Inst_Z&lt;BR /&gt;0 instruments&lt;BR /&gt;&lt;BR /&gt;I add them together to = 1 Inst_B, 2 Inst_W, 6 Inst_Y, 3 Inst_Z.&lt;BR /&gt;&lt;BR /&gt;When using the lookup table its pretty easy.&amp;nbsp; I have a code that says, for example, 6B1C and the table has columns for V, W, X, Y, Z and just pulls them in with the merge.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I haven't had the chance to look at the two methods proposed yet, so I don't know if it makes a difference when pulling in 5 different columns from combinations of 6 different columns.&lt;BR /&gt;&lt;BR /&gt;FWIW, here's a snippet of the code I'm currently using.&amp;nbsp; It works just fine, but I'm trying to learn more efficient methods.&amp;nbsp; Keep in mind that I omitted a bunch of code that makes this work.&amp;nbsp; The gist is that in the I run through the loop, adding the new instruments and subtracting the old ones until Loop_Control = 0.&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Do Until (Loop_Control = 0);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;If Inst_B = 1 and Inst_C = 0 and Profile = 'A&amp;amp;B Only' then do;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_V = Inst_V + 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_W = Inst_W + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_X = Inst_X + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_Y = Inst_Y + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_Z = Inst_Z + 1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_B = Inst_B - 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_C = Inst_C - 0;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;If Inst_B = 1 and Inst_C = 1 and Profile = 'A&amp;amp;B Only' then do;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_V = Inst_V + 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_W = Inst_W + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_X = Inst_X + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_Y = Inst_Y + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_Z = Inst_Z + 1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_B = Inst_B - 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_C = Inst_C - 1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;If Inst_B gt 1 and Inst_C = 1 and Profile = 'A&amp;amp;B Only' then do;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; subprofile = 'out of scope';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_V = Inst_V + 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_W = Inst_W + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_X = Inst_X + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_Y = Inst_Y + 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_Z = Inst_Z + 1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_B = Inst_B - 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inst_C = Inst_C - 1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;If Profile = 'A&amp;amp;B Only' then Loop_Control = Inst_A;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else Loop_Control = 0;&lt;BR /&gt;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 02:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618444#M181435</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2020-01-20T02:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618445#M181436</link>
      <description>&lt;P&gt;Take a look at this and let me know if this is aligned with what you're wanting:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	do num_items=1 to 50;
		output;
	end;
run;

data prices;
	input bulk bulk_price;
	datalines;
1 5
2 9
3 13
4 16
;
run;

proc sql noprint;
	select bulk_price, max(bulk) into 
		:price_list separated by ",", :num_prices from prices;
quit;

data want;
	set have;
	remainder=num_items;

	if num_items le &amp;amp;num_prices then
		price=1*scan("&amp;amp;price_list", num_items, ",");
	else
		do;
			array arr[&amp;amp;num_prices];
			do i=dim(arr) to 1 by -1;
				arr[i]=int(remainder/i);

				if remainder &amp;gt;=i*arr[i] and arr[i] &amp;gt; 0 then
					do;
						remainder=sum(remainder, -i*arr[i]);
						price=sum(price, arr[i]*scan("&amp;amp;price_list", i, ","));
					end;
			end;
		end;
	drop i arr: remainder;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 02:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618445#M181436</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-20T02:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618455#M181442</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84517"&gt;@BarryP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;For example, I have a lookup of 6 Inst_B &amp;amp; 1 Inst_C but I have a customer with 13 Inst_B and 4_Inst_C.&amp;nbsp; My current algorithm translates 6 Inst_B &amp;amp; 1 Inst_C, then 6 Inst_B &amp;amp; 1 Inst_C again, then 1 Inst_B &amp;amp; 1_Inst_C, and then finally 1 Inst_C.&lt;BR /&gt;&lt;BR /&gt;Those translate to (respectively):&lt;BR /&gt;&lt;BR /&gt;1 Inst_W, 3 Inst_Y, 1 Inst_Z&lt;BR /&gt;1 Inst_W, 3 Inst_Y, 1 Inst_Z&lt;BR /&gt;1 Inst_V, 1 Inst_Z&lt;BR /&gt;0 instruments&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in this example are you&amp;nbsp;saying that you have the following specific instrument translations available?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;- written here as (A,B,C,D,E,F)&amp;nbsp; (V,W,X,Y,Z):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(0,6,1,0,0,0)&amp;nbsp;&amp;nbsp; (0,1,0,3,1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; From 0A, 6B, 1C, 0D, 0E, 0F&amp;nbsp;&amp;nbsp; to&amp;nbsp;&amp;nbsp; 0V, 1W, 0X, 3Y, 1Z&amp;nbsp;&amp;nbsp; (Used twice)&lt;/P&gt;
&lt;P&gt;(0,1,1,0,0,0)&amp;nbsp;&amp;nbsp; (1,0,0,0,1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; From 1B and 1C to 1V, 1Z&amp;nbsp; (Used once)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the translation for the single remaining 1C?&amp;nbsp;&amp;nbsp; Is that the "0 instruments" line?&amp;nbsp;&amp;nbsp; I don't understand quite understand that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it mean&amp;nbsp;that for some customers, having a single "leftover" instrument of a particular type gets no translation (or officially translates to zero)?&amp;nbsp; I would ordinarily assume that, in addition to some standard list of lookup combinations, there would always&amp;nbsp;be a translation for each of the single original instruments&amp;nbsp;&amp;nbsp; Then you could account for leftovers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a way, this is a mathematical programming problem, where there may be more than one collection of translations that satisfy the customer order, but one would presumably choose the combination that minimizes the customer's cost - or optimizing some other criterion subject to the selected translations exactly satisfying the initial set of instruments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 05:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618455#M181442</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-20T05:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618488#M181459</link>
      <description>&lt;P&gt;I assume you are looking for a general solution to this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is one of the cases where I think it may be advantageous to have a "broad" lookup table, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prices;
  input ItemCode n1-n5 price1-price5;
cards;
1 4 3 2 1 . 16 13 9 5 .
2 10 5 3 2 1 45.50 25 18 14 8
;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put in an extra item with 5 prices, just for example. The ItemCode variable denotes the type of Item. Note that the numbers (n1-n5) and prices are arranged with the highest quantity first, and that the whole table is sorted by ItemCode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming your data is like this (again sorted by ItemCode, the InvoiceNo is just a hypothetical number identifying the invoice):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sales;
input InvoiceNo ItemCode n;
cards;
13121 1 9
2133 1 14
13121 2 11
123123 2 25
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can calculate the "fair" price like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TotalCost;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;merge&amp;nbsp;sales(in=sale)&amp;nbsp;prices;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;by&amp;nbsp;ItemCode;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;if&amp;nbsp;sale;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;array&amp;nbsp;numbers&amp;nbsp;n1-n5;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;array&amp;nbsp;prices&amp;nbsp;price1-price5;&lt;BR /&gt;  TotalCost=0;&lt;BR /&gt;  remain=n;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;do&amp;nbsp;_N_=1&amp;nbsp;to&amp;nbsp;dim(numbers)&amp;nbsp;while(remain&amp;gt;0);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TotalCost=TotalCost+int(remain/numbers(_N_))*prices(_N_);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;remain=remain-int(remain/numbers(_N_))*numbers(_N_);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end;&lt;BR /&gt;  keep InvoiceNo ItemCode n TotalCost;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your quantities are whole numbers, and the last valid number in the numbers array is always 1, this should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution assumes that you cannot get a better price by splitting e.g. 5 items into 3+2 instead of 4+1.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 09:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618488#M181459</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-01-20T09:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618496#M181464</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84517"&gt;@BarryP&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way using array to hold the prices for 0, 1, 2, 3 and 4 items. There are several answers and I have not examined all of them. Hope I am not repeating earlier answers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   array k[0:4] _temporary_ (0 5 9 13 16);
   do items = 1 to 100;
      mul4 = int(items/4);
      price = mul4 * k[4] + k[mod(items,4)];
      output;
   end;
drop mul4;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Jan 2020 10:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618496#M181464</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2020-01-20T10:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618502#M181466</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I used the price and quantity to simplify the problem. The real problem is a little more complicated. We are replacing combinations of lab instruments with different combinations of new lab instruments. So its more like:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same math works product by product that I provided above. Essentially, you do the same programming for each instrument, and then add things up. Perhaps there are smarter or faster ways to do this, but I still don't see a need for any looping or iterations within a product. You could write a loop that goes over all products.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 11:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618502#M181466</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-20T11:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618514#M181475</link>
      <description>&lt;P&gt;Yes, you understand it correctly.&lt;BR /&gt;&lt;BR /&gt;I find the 0 translation weird, too, but I don't work in sales.&amp;nbsp; I just have to use the numbers that they give me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 13:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618514#M181475</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2020-01-20T13:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618573#M181486</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;So as I'm working through this it seems like the key is that in order to treat the elements of a lookup table like variables, I need to put them into an array.&amp;nbsp; Is that correct?&lt;BR /&gt;&lt;BR /&gt;So, for example if I have a sale, 1 item for $4, or 4 items for $12, if I buy 5 items then I would need to take the price for 4 items, subtract the 4 items from the total, and then add the price for the 1 item, subtract that 1 item from the total, and now that I'm at zero items, I leave the loop.&lt;BR /&gt;&lt;BR /&gt;Sorry, I've never worked with arrays in SAS before.&amp;nbsp; So I'm assuming that to use an array like a lookup, its always going to look for the i'th element.&amp;nbsp; So instead of thinking "lookup the element that corresponds with sale_scenario_4," I have to think, "lookup the 4th element in the array and make sure that you have the value for sale-scenario_4 there."&lt;BR /&gt;&lt;BR /&gt;Is that right?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 15:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618573#M181486</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2020-01-20T15:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618586#M181495</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see two&amp;nbsp; ambiguous issues in the task you describe:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Single instrument&amp;nbsp; issue:&amp;nbsp; Your example shows pricing levels for every quantity from 1 to 4&amp;nbsp; (or more generally from 1 to Np&amp;nbsp; - the maximum quantity discounted for product p).&amp;nbsp;&amp;nbsp; Because it covers every quantity in the&amp;nbsp; 1:Np interval, it's a perfect fit for the array approach, and your description "lookup the 4th element in the array and make sure that you have the value for sale-scenario_4 there" is spot on.&lt;BR /&gt;&lt;BR /&gt;But it may be that you have&amp;nbsp; discount breaks not from 1 to 4,&amp;nbsp; but&amp;nbsp; at 1, 2, 5, and 10.&amp;nbsp;&amp;nbsp; Then the 4th element is not for quantity 4 but for quantity 10. &amp;nbsp; One can work around this while still using the array approach.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Mixed-instrument translations.&amp;nbsp; As I understand it, you have a lookup table in which various (non-exhaustive) mixes of instruments A,B,C,D will be replaced with some mix of new instruments W,X,Y,Z.&amp;nbsp; This can be more of a problem, because if your customer doesn't have any of the exact translations you have in the lookup, you might not arrive at unique mix of new instruments.&lt;BR /&gt;&lt;BR /&gt;For instance, what if your initial lookup table of {A,B} =&amp;gt; {W,X} available translations are (admittedly contrived)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {6,2}&amp;nbsp; =&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {2,1}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {2,6}&amp;nbsp; =&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {1,2}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {0,2}&amp;nbsp; =&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {0,1}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {2,0}&amp;nbsp; =&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {1,0}&lt;BR /&gt;&lt;BR /&gt;If the customer starts out&amp;nbsp; with {A,B}={6,6},&amp;nbsp; then you could end up with either&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {W,X} = {2,1} + {0,1} + {0,1}&amp;nbsp; == {2,3}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {W,X} = {1,2} + {1,0} + {1,0}&amp;nbsp; == {3,2}&lt;BR /&gt;&lt;BR /&gt;You would need a way to decide between these two alternatives.&lt;/LI&gt;
&lt;LI&gt;Also in your mixed-instrument lookup table, do those mixes of new instruments also have quantity discounts that do not match what you would produce by applying the instrument-by-instrument discounts in the new mix?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 20 Jan 2020 16:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618586#M181495</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-20T16:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a lookup table using iterations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618640#M181513</link>
      <description>&lt;P&gt;I think you are understanding me correctly.&lt;BR /&gt;&lt;BR /&gt;In a nutshell I have ~100 unique old instrument combinations that will translate to new instrument combinations.&amp;nbsp; If that was all I had, it would be an easy merge.&amp;nbsp; I need to account for, however, combinations outside of that list (the list is a table that was provided to me from marketing).&lt;BR /&gt;&lt;BR /&gt;So for example, I'll lay out the first 8 elements and codes that correspond to the instrument combinations:&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Code&amp;nbsp; Inst_A Inst_B&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1-A1B1 &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A2&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A2B1&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A3&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A4&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A5&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A6&amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;The translations are the following:&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Code&amp;nbsp; InstW InstX InstY InstZ&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1-A1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1-A1B1&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A2&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A2B1&amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A3&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A4&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A5&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1-A6&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if I have, for example, 7 Inst_A, the translation would be 1-A6 + 1-A1 which =&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Code&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; InstW InstX InstY InstZ&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1-A6 + 1-A1&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So I think I've resigned myself to the fact that the algorithms that tell you what InstA/InstB combinations are going to have to be hard coded, particularly when dealing with what order to do the calculations in, but I believe that simple 1 dimensional arrays can be used here.&amp;nbsp; (???)&amp;nbsp; Perhaps just calculate W, X, Y, &amp;amp; Z separately.&amp;nbsp; The key here is that I've either done these as table merges or hard coding if/then statements with the math written into the code.&lt;BR /&gt;&lt;BR /&gt;I want to be able to utilize an imported excel table as much as possible.&amp;nbsp; If needed, I can even add a column that just defines the i'th element in the lookup table.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 18:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-lookup-table-using-iterations/m-p/618640#M181513</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2020-01-20T18:12:52Z</dc:date>
    </item>
  </channel>
</rss>

