<?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 Optimize proc sql joins in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Optimize-proc-sql-joins/m-p/376503#M90382</link>
    <description>&lt;P&gt;I have a left join, is there a way to optimize it, i have used keyword magic=102, but did not see any improvement.&lt;/P&gt;
&lt;P&gt;Can Proc ds2 help is this case&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql magic=102;
create table old_tran_prod_sync_master1 as 
select 
a.*,
b.Gluten_free,
b.Non_GMO,
b.Organic,
b.Organic_Validated,
b.Whole_Trade_Guarantee
from old_tran_prod_sync_master a 
left join product_master_file b on a.UPC = b.NAT_UPC;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;::::::::::::::::::::::::LOG:::::::::::::::::::::::;;&lt;/P&gt;
&lt;P&gt;NOTE: PROC SQL planner chooses merge join.&lt;BR /&gt;NOTE: Table WORK.OLD_TRAN_PROD_SYNC_MASTER1 created, with 181692824 rows and 22 columns.&lt;/P&gt;
&lt;P&gt;842 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt; real time 15:31.88&lt;BR /&gt; user cpu time 5:40.43&lt;BR /&gt; system cpu time 5:08.82&lt;BR /&gt; memory 1059492.75k&lt;BR /&gt; OS Memory 1077260.00k&lt;BR /&gt; Timestamp 07/15/2017 08:59:10 AM&lt;BR /&gt; Step Count 78 Switch Count 231&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jul 2017 11:51:25 GMT</pubDate>
    <dc:creator>upadhi</dc:creator>
    <dc:date>2017-07-17T11:51:25Z</dc:date>
    <item>
      <title>Optimize proc sql joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-proc-sql-joins/m-p/376503#M90382</link>
      <description>&lt;P&gt;I have a left join, is there a way to optimize it, i have used keyword magic=102, but did not see any improvement.&lt;/P&gt;
&lt;P&gt;Can Proc ds2 help is this case&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql magic=102;
create table old_tran_prod_sync_master1 as 
select 
a.*,
b.Gluten_free,
b.Non_GMO,
b.Organic,
b.Organic_Validated,
b.Whole_Trade_Guarantee
from old_tran_prod_sync_master a 
left join product_master_file b on a.UPC = b.NAT_UPC;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;::::::::::::::::::::::::LOG:::::::::::::::::::::::;;&lt;/P&gt;
&lt;P&gt;NOTE: PROC SQL planner chooses merge join.&lt;BR /&gt;NOTE: Table WORK.OLD_TRAN_PROD_SYNC_MASTER1 created, with 181692824 rows and 22 columns.&lt;/P&gt;
&lt;P&gt;842 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt; real time 15:31.88&lt;BR /&gt; user cpu time 5:40.43&lt;BR /&gt; system cpu time 5:08.82&lt;BR /&gt; memory 1059492.75k&lt;BR /&gt; OS Memory 1077260.00k&lt;BR /&gt; Timestamp 07/15/2017 08:59:10 AM&lt;BR /&gt; Step Count 78 Switch Count 231&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 11:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-proc-sql-joins/m-p/376503#M90382</guid>
      <dc:creator>upadhi</dc:creator>
      <dc:date>2017-07-17T11:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize proc sql joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-proc-sql-joins/m-p/376512#M90383</link>
      <description>&lt;P&gt;As already stated in your other thread (&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/SAS-Code-Optimization/m-p/376456" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/SAS-Code-Optimization/m-p/376456&lt;/A&gt;), 15 minutes for ~200 million observations isn't that bad.&lt;/P&gt;
&lt;P&gt;Since you seem to have a one-to-many relationship, try this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=old_tran_prod_sync_master;
by UPC;
run;

proc sort data=product_master_file;
by UPC;
run;

data old_tran_prod_sync_master1;
merge
  old_tran_prod_sync_master (in=a)
  product_master_file (
    in=b
    keep=UPC Gluten_free Non_GMO Organic Organic_Validated Whole_Trade_Guarantee
  )
;
by UPC;
if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The sorts will only be necessary if the datasets are not already sorted by UPC.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 12:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-proc-sql-joins/m-p/376512#M90383</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-17T12:25:40Z</dc:date>
    </item>
  </channel>
</rss>

