<?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: Help needed to find alternatives for joins in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-needed-to-find-alternatives-for-joins/m-p/886834#M350411</link>
    <description>&lt;P&gt;If you mean computing performance, something you might consider is that proc sql allows for multi-threaded processing.&amp;nbsp; SAS defaults to 4 processors, but if your computer/system has more processors, you can increase that number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* evaluate CPU usage default for new session / since last CPU setting during session */ 
proc options option=cpucount;
run; /* default CPU count = 4 */ 

/* count and use all CPUs available for multi-threaded procs */ 
options threads cpucount=actual;
proc options option=cpucount;
run; /* count and use max CPU count available; my comp = 20 */ 

/* set CPUs count to use manually for multi-threaded procs */ 
options threads cpucount=19;
proc options option=cpucount;
run; /* max CPU count (20) - 1 = 19 (as not to overload other programs/processing) */ &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2023 16:22:57 GMT</pubDate>
    <dc:creator>awesome_opossum</dc:creator>
    <dc:date>2023-07-28T16:22:57Z</dc:date>
    <item>
      <title>Help needed to find alternatives for joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-needed-to-find-alternatives-for-joins/m-p/886817#M350407</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need you help to understand will too many left joins will impact performance. I am currently testing in sample data and my code is working fine, But I am getting this feeling that for larger volume the joins will take more time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;snippet of my code where I am using 7 joins&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;proc sql noprint;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; create table work.mandate_unapproved_res_tmp1 as&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;t1.order_id as plan_id,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t1.sales_units_qty,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t1.revenue_amt,&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; t1.revenue_no_vat_amt,&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; t1.margin_amt,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t1.promotion_spend_amt,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t1.cost_amt, &amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t2.plan_nm as plan_nm,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t2.plan_desc as plan_desc,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t2.start_dt as start_dt,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t2.end_dt as end_dt,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t2.plan_status_no as plan_status_no,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t2.plan_approval_flg as plan_approval_status_no,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t3.price_type_no as price_type_no,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t3.price_value_no as price_value_no,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t3.price_value_rec_flg as price_value_rec_flg,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t3.code as vehicle_cd,&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t4.num_prod_no as num_prod_no,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t5.num_geo_no as num_geo_no,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t6.num_prod_geo_no as num_prod_geo_no,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t7.rule_val as obj_func&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from work.mandate_unapproved_res_t1 t1&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left&amp;nbsp; join &amp;amp;gv_pricing_libname..main_plan t2&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on upcase(t1.order_id)=upcase(t2.order_id)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left&amp;nbsp; join work.pp_vehicle t3&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on upcase(t1.order_id)=upcase(t3.order_id)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left&amp;nbsp; join work.unapproved_prod_sku t4&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on upcase(t1.order_id)=upcase(t4.order_id)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left&amp;nbsp; join work.unapproved_geo_sku t5&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on upcase(t1.order_id)=upcase(t5.order_id)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left&amp;nbsp; join work.temp_prd_geo_cnt t6&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on upcase(t1.order_id)=upcase(t6.order_id)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; left join work.mandate_plan_rule t7&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on upcase(t1.order_id)=upcase(t7.order_id);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Any suggestion or help will be much appreciated.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Thanks!&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 14:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-needed-to-find-alternatives-for-joins/m-p/886817#M350407</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2023-07-28T14:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed to find alternatives for joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-needed-to-find-alternatives-for-joins/m-p/886834#M350411</link>
      <description>&lt;P&gt;If you mean computing performance, something you might consider is that proc sql allows for multi-threaded processing.&amp;nbsp; SAS defaults to 4 processors, but if your computer/system has more processors, you can increase that number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* evaluate CPU usage default for new session / since last CPU setting during session */ 
proc options option=cpucount;
run; /* default CPU count = 4 */ 

/* count and use all CPUs available for multi-threaded procs */ 
options threads cpucount=actual;
proc options option=cpucount;
run; /* count and use max CPU count available; my comp = 20 */ 

/* set CPUs count to use manually for multi-threaded procs */ 
options threads cpucount=19;
proc options option=cpucount;
run; /* max CPU count (20) - 1 = 19 (as not to overload other programs/processing) */ &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 16:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-needed-to-find-alternatives-for-joins/m-p/886834#M350411</guid>
      <dc:creator>awesome_opossum</dc:creator>
      <dc:date>2023-07-28T16:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed to find alternatives for joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-needed-to-find-alternatives-for-joins/m-p/886927#M350452</link>
      <description>&lt;P&gt;The SAS SQL optimizer got its limits and joins with a lot of tables can result in a sub-optimal execution path. SQL options &lt;STRONG&gt;_&lt;/STRONG&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p12ohgh32ffm6un13s7l2d5p9c8y.htm#n0hes4i1w3krg1n1omqulq16e764" target="_self"&gt;method&lt;/A&gt; and &lt;STRONG&gt;_&lt;/STRONG&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p12ohgh32ffm6un13s7l2d5p9c8y.htm#n0hes4i1w3krg1n1omqulq16e764" target="_self"&gt;tree&lt;/A&gt; write to the SAS log how SAS executes the joins.&lt;/P&gt;
&lt;P&gt;Proc SQL needs to implicitly sort the tables along the join key. In your case you join all tables with the same column so a single sort per table will suffice. I would expect this join to work as efficiently as possible.&lt;/P&gt;
&lt;P&gt;Multithreading only happens for the implicit sort operations and the installation defaults are normally appropriate. You should only have to change this in rare occasions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your base table is the big table and the lookup tables for left joins are the "small" ones then another approach is using SAS datastep hash tables. That normally beats any other approach in regards of performance because it avoids the need for any sorting.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jul 2023 00:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-needed-to-find-alternatives-for-joins/m-p/886927#M350452</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-07-29T00:34:52Z</dc:date>
    </item>
  </channel>
</rss>

