<?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 Currency Conversion in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Currency-Conversion/m-p/293257#M20041</link>
    <description>&lt;P&gt;Good afternoon still struggling with something I started&amp;nbsp;a while ago, so starting a new message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to join 2 tables, exchange_rates and summary, in order to convert local currencies to usd.&amp;nbsp; The tables can be joined on&lt;/P&gt;&lt;P&gt;exchange_rates.currency_id = summary.transaction_currency_id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The challenge is finding the right exchange rate based on identifying the closest exchange_rate_date to Month_End_Close_Date to find the correct&amp;nbsp;currency conversion rate to use given many to many relationships.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have come up with attatching the data sets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Temp_Conversion_Table as&amp;nbsp;&lt;BR /&gt;select a.exchange_rate_id,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.currency_id,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.month_end_close_date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.exchange_rate,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.Exchange_Rate_Date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abs(a.exchange_rate_date - b.month_end_close_date) as exchange_date_calc_value /* calculates absolute value for exchange rate date to month end close date by currency */&lt;BR /&gt;from Exchange_Rates a&lt;BR /&gt;left join SUMMARY b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.currency_id = b.transaction_currency_id&lt;BR /&gt;where b.month_end_close_date is not null&lt;BR /&gt;order by a.currency_id asc, a.Exchange_Rate_Date, b.month_end_close_date;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Month_End_Close_Conversion_Table as&lt;BR /&gt;select currency_id,&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exchange_Rate_Date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; month_end_close_date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exchange_rate,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exchange_date_calc_value&lt;BR /&gt;from Temp_Conversion_Table&lt;BR /&gt;group by currency_id,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exchange_Rate_Date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; month_end_close_date&lt;BR /&gt;having exchange_date_calc_value = min(exchange_date_calc_value);&amp;nbsp;&lt;BR /&gt;quit;&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, 22 Aug 2016 20:30:12 GMT</pubDate>
    <dc:creator>RickyS</dc:creator>
    <dc:date>2016-08-22T20:30:12Z</dc:date>
    <item>
      <title>Currency Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Currency-Conversion/m-p/293257#M20041</link>
      <description>&lt;P&gt;Good afternoon still struggling with something I started&amp;nbsp;a while ago, so starting a new message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to join 2 tables, exchange_rates and summary, in order to convert local currencies to usd.&amp;nbsp; The tables can be joined on&lt;/P&gt;&lt;P&gt;exchange_rates.currency_id = summary.transaction_currency_id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The challenge is finding the right exchange rate based on identifying the closest exchange_rate_date to Month_End_Close_Date to find the correct&amp;nbsp;currency conversion rate to use given many to many relationships.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have come up with attatching the data sets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Temp_Conversion_Table as&amp;nbsp;&lt;BR /&gt;select a.exchange_rate_id,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.currency_id,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.month_end_close_date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.exchange_rate,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.Exchange_Rate_Date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abs(a.exchange_rate_date - b.month_end_close_date) as exchange_date_calc_value /* calculates absolute value for exchange rate date to month end close date by currency */&lt;BR /&gt;from Exchange_Rates a&lt;BR /&gt;left join SUMMARY b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.currency_id = b.transaction_currency_id&lt;BR /&gt;where b.month_end_close_date is not null&lt;BR /&gt;order by a.currency_id asc, a.Exchange_Rate_Date, b.month_end_close_date;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Month_End_Close_Conversion_Table as&lt;BR /&gt;select currency_id,&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exchange_Rate_Date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; month_end_close_date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exchange_rate,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exchange_date_calc_value&lt;BR /&gt;from Temp_Conversion_Table&lt;BR /&gt;group by currency_id,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exchange_Rate_Date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; month_end_close_date&lt;BR /&gt;having exchange_date_calc_value = min(exchange_date_calc_value);&amp;nbsp;&lt;BR /&gt;quit;&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, 22 Aug 2016 20:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Currency-Conversion/m-p/293257#M20041</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2016-08-22T20:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Currency Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Currency-Conversion/m-p/293362#M20047</link>
      <description>&lt;P&gt;Please provide example data in a reasonable format. Don't expect people to open a Excel(!) file from the internet. Use a data step with cards;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My preferred method would be:&lt;/P&gt;
&lt;P&gt;- sort the summary dataset by currency&lt;/P&gt;
&lt;P&gt;- in a data step "by currency", at every first.currency create a hash object with your exchange rates from the respective currency&lt;/P&gt;
&lt;P&gt;- scan through the hash to find the closest exchange rate date; since this happens in memory, this is probably best, performancewise&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, if your month_end_close_date is unique for every month, one could first extract all currency exchange rate observations that are closest to this date for every month, and then simply join on currency and month.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2016 07:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Currency-Conversion/m-p/293362#M20047</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-23T07:04:35Z</dc:date>
    </item>
  </channel>
</rss>

