<?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 lookup values from another table for calculation? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510051#M1879</link>
    <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;"...what specifically is the problem you are trying to eliminate or reduce?"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Nothing in particular.&amp;nbsp; As I'm learning to code I'm trying to eliminate as many workarounds and be as efficient as possible while avoiding bad habits.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for the feedback, it was very helpful!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Nov 2018 20:13:05 GMT</pubDate>
    <dc:creator>BarryP</dc:creator>
    <dc:date>2018-11-02T20:13:05Z</dc:date>
    <item>
      <title>How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510009#M1869</link>
      <description>&lt;P&gt;Hi, I'm looking for a more efficient way to do this than what I've come up with.&amp;nbsp; I need to multiply QUANTITY by COST, but I want COST to exist in a separate table so that that calculations will carry through when they are updated.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Table_1:&lt;BR /&gt;&lt;BR /&gt;ACCOUNT&amp;nbsp; &amp;nbsp; &amp;nbsp;QUANTITY&lt;BR /&gt;Bob&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;BR /&gt;Louis&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;BR /&gt;Sarah&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&lt;BR /&gt;&lt;BR /&gt;Table_2:&lt;BR /&gt;&lt;BR /&gt;COST&lt;BR /&gt;5,200&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Table_I_Want:&lt;BR /&gt;&lt;BR /&gt;ACCOUNT&amp;nbsp; &amp;nbsp; &amp;nbsp;QUANTITY&amp;nbsp; &amp;nbsp; &amp;nbsp; COST&amp;nbsp; &amp;nbsp; &amp;nbsp;TOTAL&lt;BR /&gt;Bob&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&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5,200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;26,000&lt;BR /&gt;Louis&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5,200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;52,000&lt;/P&gt;&lt;P&gt;Sarah&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5,200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;62,400&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Right now I'm creating a lookup field for each table and then merging the tables together, but I'm assuming there is a more efficient way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 18:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510009#M1869</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2018-11-02T18:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510011#M1870</link>
      <description>&lt;P&gt;Well, if you want to keep the quantity in a separate table from the cost, then you will have to merge the two tables together somehow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, is there a more efficient way? I don't think so, unless you are doing extremely inefficient merging now. Can you show us how you are doing this today?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 18:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510011#M1870</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T18:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510015#M1871</link>
      <description>&lt;P&gt;You present the problem as one in which the cost "table" has a single value.&amp;nbsp; After all you are using it as a constant for all three records in the quantity table.&amp;nbsp; Is that true, or can you have differing table_2 costs for differing accounts in table_1?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 18:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510015#M1871</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-11-02T18:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510031#M1873</link>
      <description>&lt;P&gt;&lt;SPAN&gt;This is what I am currently doing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Table_1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ACCOUNT&amp;nbsp; &amp;nbsp; &amp;nbsp;QUANTITY&amp;nbsp; LookUpKey&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Bob&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&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Service_Key&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Louis&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Service_Key&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sarah&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Service_Key&lt;BR /&gt;&lt;BR /&gt;Table_2:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;COST&amp;nbsp; &amp;nbsp; &amp;nbsp;LookUpKey&lt;BR /&gt;5,200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Service_Key&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;SAS Code:&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Data Table_I_Generate;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;merge Table_1 Table_2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;by LookUpKey;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Table_I_Generate:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ACCOUNT&amp;nbsp; &amp;nbsp; &amp;nbsp;QUANTITY&amp;nbsp; LookUpKey&amp;nbsp; &amp;nbsp; &amp;nbsp; COST&amp;nbsp;&lt;BR /&gt;Bob&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&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Service_Key&amp;nbsp; &amp;nbsp; &amp;nbsp;5,200&lt;BR /&gt;Louis&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Service_Key&amp;nbsp; &amp;nbsp; &amp;nbsp;5,200&lt;BR /&gt;Sarah&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Service_Key&amp;nbsp; &amp;nbsp; &amp;nbsp;5,200&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Code:&lt;BR /&gt;&lt;BR /&gt;data Table_With_Total&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set Table_I_Generate(drop=LookUpKey);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Total = Quantity * Cost;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Drop&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510031#M1873</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2018-11-02T19:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510034#M1874</link>
      <description>&lt;P&gt;Yes, it would be a constant value for every record.&amp;nbsp; It would not change from one record to the next.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;When I do this in Excel, I just reference the cell where it exists in the calculation.&amp;nbsp; For example, if it is in cell A1 I would multiply each row by $A$1.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've got about 13 years experience doing pretty involved calculations in Excel but have only been programming in SAS for ~6 months, so I'm still getting used to manipulating databases.&amp;nbsp; It looks like there's some subtle but important differences.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510034#M1874</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2018-11-02T19:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510036#M1875</link>
      <description>&lt;P&gt;That's what is required. I doubt it could be made simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if you have a much larger data sets, it probably will take more time to do the merge ... what specifically is the problem you are trying to eliminate or reduce?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510036#M1875</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T19:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510050#M1878</link>
      <description>&lt;P&gt;If it's a constant pull that into a macro variable and use it in your calculations. You can also keep it in a view so it is up to date every time you 'look' at the table. If you're not familiar with views, it may be beneficial in this case.&amp;nbsp;&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;*create macro variable with cost;

proc sql noprint;
select cost into :cost_value from table_2;
quit;

data want / view=want;
set have;

Total = &amp;amp;cost_value * Quantity;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&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;Yes, it would be a constant value for every record.&amp;nbsp; It would not change from one record to the next.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;When I do this in Excel, I just reference the cell where it exists in the calculation.&amp;nbsp; For example, if it is in cell A1 I would multiply each row by $A$1.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've got about 13 years experience doing pretty involved calculations in Excel but have only been programming in SAS for ~6 months, so I'm still getting used to manipulating databases.&amp;nbsp; It looks like there's some subtle but important differences.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 20:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510050#M1878</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-02T20:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510051#M1879</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;"...what specifically is the problem you are trying to eliminate or reduce?"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Nothing in particular.&amp;nbsp; As I'm learning to code I'm trying to eliminate as many workarounds and be as efficient as possible while avoiding bad habits.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for the feedback, it was very helpful!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 20:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510051#M1879</guid>
      <dc:creator>BarryP</dc:creator>
      <dc:date>2018-11-02T20:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510054#M1880</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;Yes, it would be a constant value for every record.&amp;nbsp; It would not change from one record to the next.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;When I do this in Excel, I just reference the cell where it exists in the calculation.&amp;nbsp; For example, if it is in cell A1 I would multiply each row by $A$1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS can't do things the way Excel does things. You'll just have to learn to think differently.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 20:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510054#M1880</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T20:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to lookup values from another table for calculation?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510057#M1881</link>
      <description>In general, when you start out its common to relate it to what you know. For SAS, the key idea to remember at all times, it's really only seeing one line at a time and then goes through each line in order. If that value isn't available in that row, then you need to get it there somewhere. Trying to do things as in Excel means your programs will be inefficient in SAS because there's usually a different way that can be handled a bit easier. Common tasks (transpose) have PROCS that would be otherwise almost impossible in Excel, to streamline at least. &lt;BR /&gt;</description>
      <pubDate>Fri, 02 Nov 2018 20:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-lookup-values-from-another-table-for-calculation/m-p/510057#M1881</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-02T20:27:37Z</dc:date>
    </item>
  </channel>
</rss>

