<?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: Divide 2 datasets values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607413#M176583</link>
    <description>&lt;P&gt;Merge the data sets first so that the values are in the same line and then do the division. &lt;BR /&gt;&lt;BR /&gt;Merges in SAS &lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/match-merging-data-files-in-sas/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/match-merging-data-files-in-sas/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Creating new variables:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/creating-and-recoding-variables-in-sas/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/creating-and-recoding-variables-in-sas/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213838"&gt;@new_sas_user_4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi folks,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 datasets.&lt;/P&gt;
&lt;P&gt;I would like to divide the rows from the first dataset /second based on the matching item/region:&lt;/P&gt;
&lt;P&gt;eg Divide&amp;nbsp;&lt;STRONG&gt;OUT audi AB&lt;/STRONG&gt;&amp;nbsp;by&amp;nbsp;&lt;STRONG&gt;IN audi AB&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;so : 10/1 and 20/2&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data Base1;&lt;BR /&gt;length metric $3 item $4 region $2;&lt;BR /&gt;input metric $ item $ region $ PY1 PY2 ;&lt;BR /&gt;datalines;&lt;BR /&gt;OUT audi AB 10 20&lt;BR /&gt;OUT audi ON 30 20&lt;BR /&gt;OUT BMW AB 50 20&lt;BR /&gt;OUT BMW ON 70 80&lt;BR /&gt;OUT BMW BC 90 100&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;data Base2;&lt;BR /&gt;length metric $3 item $4 region $2;&lt;BR /&gt;input metric $ item $ region $ PY1 PY2 ;&lt;BR /&gt;datalines;&lt;BR /&gt;IN audi AB 1 2&lt;BR /&gt;IN audi ON 3 2&lt;BR /&gt;IN BMW AB 5 2&lt;BR /&gt;IN BMW ON 7 8&lt;BR /&gt;IN BMW BC 9 10&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected Output :&lt;/P&gt;
&lt;P&gt;Div Audi AB 10 10&lt;/P&gt;
&lt;P&gt;Div Audi ON 10 10&lt;/P&gt;
&lt;P&gt;Div BMW AB 10 10&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IN BMW ON 10 10&lt;/P&gt;
&lt;P&gt;IN BMW BC 10 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas on how to achieve this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;</description>
    <pubDate>Tue, 26 Nov 2019 16:23:45 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-11-26T16:23:45Z</dc:date>
    <item>
      <title>Divide 2 datasets values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607409#M176580</link>
      <description>&lt;P&gt;Hi folks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 datasets.&lt;/P&gt;&lt;P&gt;I would like to divide the rows from the first dataset /second based on the matching item/region:&lt;/P&gt;&lt;P&gt;eg Divide&amp;nbsp;&lt;STRONG&gt;OUT audi AB&lt;/STRONG&gt;&amp;nbsp;by&amp;nbsp;&lt;STRONG&gt;IN audi AB&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;so : 10/1 and 20/2&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data Base1;&lt;BR /&gt;length metric $3 item $4 region $2;&lt;BR /&gt;input metric $ item $ region $ PY1 PY2 ;&lt;BR /&gt;datalines;&lt;BR /&gt;OUT audi AB 10 20&lt;BR /&gt;OUT audi ON 30 20&lt;BR /&gt;OUT BMW AB 50 20&lt;BR /&gt;OUT BMW ON 70 80&lt;BR /&gt;OUT BMW BC 90 100&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data Base2;&lt;BR /&gt;length metric $3 item $4 region $2;&lt;BR /&gt;input metric $ item $ region $ PY1 PY2 ;&lt;BR /&gt;datalines;&lt;BR /&gt;IN audi AB 1 2&lt;BR /&gt;IN audi ON 3 2&lt;BR /&gt;IN BMW AB 5 2&lt;BR /&gt;IN BMW ON 7 8&lt;BR /&gt;IN BMW BC 9 10&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected Output :&lt;/P&gt;&lt;P&gt;Div Audi AB 10 10&lt;/P&gt;&lt;P&gt;Div Audi ON 10 10&lt;/P&gt;&lt;P&gt;Div BMW AB 10 10&amp;nbsp;&lt;/P&gt;&lt;P&gt;IN BMW ON 10 10&lt;/P&gt;&lt;P&gt;IN BMW BC 10 10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas on how to achieve this?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607409#M176580</guid>
      <dc:creator>new_sas_user_4</dc:creator>
      <dc:date>2019-11-26T16:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Divide 2 datasets values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607413#M176583</link>
      <description>&lt;P&gt;Merge the data sets first so that the values are in the same line and then do the division. &lt;BR /&gt;&lt;BR /&gt;Merges in SAS &lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/match-merging-data-files-in-sas/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/match-merging-data-files-in-sas/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Creating new variables:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/creating-and-recoding-variables-in-sas/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/creating-and-recoding-variables-in-sas/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213838"&gt;@new_sas_user_4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi folks,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 datasets.&lt;/P&gt;
&lt;P&gt;I would like to divide the rows from the first dataset /second based on the matching item/region:&lt;/P&gt;
&lt;P&gt;eg Divide&amp;nbsp;&lt;STRONG&gt;OUT audi AB&lt;/STRONG&gt;&amp;nbsp;by&amp;nbsp;&lt;STRONG&gt;IN audi AB&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;so : 10/1 and 20/2&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data Base1;&lt;BR /&gt;length metric $3 item $4 region $2;&lt;BR /&gt;input metric $ item $ region $ PY1 PY2 ;&lt;BR /&gt;datalines;&lt;BR /&gt;OUT audi AB 10 20&lt;BR /&gt;OUT audi ON 30 20&lt;BR /&gt;OUT BMW AB 50 20&lt;BR /&gt;OUT BMW ON 70 80&lt;BR /&gt;OUT BMW BC 90 100&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;data Base2;&lt;BR /&gt;length metric $3 item $4 region $2;&lt;BR /&gt;input metric $ item $ region $ PY1 PY2 ;&lt;BR /&gt;datalines;&lt;BR /&gt;IN audi AB 1 2&lt;BR /&gt;IN audi ON 3 2&lt;BR /&gt;IN BMW AB 5 2&lt;BR /&gt;IN BMW ON 7 8&lt;BR /&gt;IN BMW BC 9 10&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected Output :&lt;/P&gt;
&lt;P&gt;Div Audi AB 10 10&lt;/P&gt;
&lt;P&gt;Div Audi ON 10 10&lt;/P&gt;
&lt;P&gt;Div BMW AB 10 10&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IN BMW ON 10 10&lt;/P&gt;
&lt;P&gt;IN BMW BC 10 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas on how to achieve this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607413#M176583</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-26T16:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Divide 2 datasets values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607414#M176584</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=rc in:);
   if _N_=1 then do;
      declare hash h(dataset:'Base2(rename=(PY1=inPY1 PY2=inPY2))');
      h.definekey('item', 'region');
      h.definedata('inPY1', 'inPY2');
      h.definedone();
   end;
   
   set Base1;
   inPY1=.; inPY2=.;

   rc=h.find();

   PY1=divide(PY1, inPY1);
   PY2=divide(PY2, inPY2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 16:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607414#M176584</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-26T16:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Divide 2 datasets values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607431#M176595</link>
      <description>&lt;P&gt;Thanks a lot for the solution!!&lt;/P&gt;&lt;P&gt;I want to understand declare hash/ definekey/definedata better ....Do you have any reference material I could read through to understand ? Highly appreciate the help!!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 17:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607431#M176595</guid>
      <dc:creator>new_sas_user_4</dc:creator>
      <dc:date>2019-11-26T17:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Divide 2 datasets values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607434#M176596</link>
      <description>&lt;P&gt;I sure do &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously, use the &lt;A href="https://documentation.sas.com/?docsetId=lecompobjref&amp;amp;docsetTarget=p00ilfw5pzcjvtn1nfya9863fozd.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;Hash Object Documentation&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want to get an understanding of the hash object, get a hold of the book&amp;nbsp;&lt;A href="https://www.sas.com/store/books/categories/examples/data-management-solutions-using-sas-hash-table-operations-a-business-intelligence-case-study/prodBK_69153_en.html" target="_self"&gt;Data Management Solutions Using SAS® Hash Table Operations: A Business Intelligence Case Study&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best of luck!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 17:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-2-datasets-values/m-p/607434#M176596</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-26T17:08:32Z</dc:date>
    </item>
  </channel>
</rss>

