<?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: Proc sql query optimization - Running long hours in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761805#M241117</link>
    <description>&lt;P&gt;Thanks a lot for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here Impressions contains 60781 records and clicks contain 2058. and leads contain around 10. Its taking very long time that i force stop every time, commenting some codes , i think the issue started to come for certain products where impressions came very high this month causing this slowness. Do you require sample data here.&lt;/P&gt;&lt;P&gt;also i think joining with leads causes more slowness as join with impressions and clicks was giving results within 30 mins..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Aug 2021 13:58:50 GMT</pubDate>
    <dc:creator>SASUserRocks</dc:creator>
    <dc:date>2021-08-16T13:58:50Z</dc:date>
    <item>
      <title>Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761800#M241114</link>
      <description>&lt;P&gt;Hello friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am facing issue with optimizing this long running proc sql query. I compute daily impressions and clicks and aggregate records along with leads information. This query takes very long time. Please suggest some way forward. Impressions and clicks table also contain only 1 day data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table libshare.Total_Click_Impressions_Lead as&lt;BR /&gt;select distinct A.date,A.Product, count( A.ImpressionId) as Impressions,&lt;BR /&gt;count( B.clickid) as Clicks ,&lt;BR /&gt;count( distinct row_id||x_adcb_prod_group||x_adcb_prod_code||utm_medium) as Leads ,&lt;BR /&gt;startdate as start_date ,enddate as end_date&amp;nbsp;&lt;BR /&gt;from impressions A&lt;BR /&gt;left join clicks B on A.date = B.date and A.Product = B.ProductLabel&lt;BR /&gt;left join (select * from libshare.leads where x_adcb_last_lead_action_date='09Aug2021'd) C&lt;BR /&gt;on intnx('day',A.date,0,'B') = intnx('day',C.x_adcb_last_lead_action_date,0,'B')&lt;BR /&gt;and A.Product = C.adcb_utm_camp&lt;BR /&gt;&amp;nbsp;left join(select min(date) format date11. as startdate , max(date) format date11. as enddate ,&lt;BR /&gt;product from libshare.Total_Click_Impressions_Lead group by product) D on A.Product = D.Product&lt;BR /&gt;group by A.date,A.Product ;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 13:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761800#M241114</guid>
      <dc:creator>SASUserRocks</dc:creator>
      <dc:date>2021-08-16T13:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761801#M241115</link>
      <description>&lt;P&gt;slight change in query. :-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table libshare.Total_Click_Impressions_Lead1 as&lt;BR /&gt;select distinct A.date,A.Product, count( distinct A.ImpressionId) as Impressions,&lt;BR /&gt;count( distinct B.clickid) as Clicks ,&lt;BR /&gt;count( distinct row_id||x_adcb_prod_group||x_adcb_prod_code||utm_medium) as Leads&amp;nbsp; ,&lt;BR /&gt;startdate as start_date ,enddate as end_date&amp;nbsp;&lt;BR /&gt;from impressions A&lt;BR /&gt;left join clicks B on A.date = B.date and A.Product = B.ProductLabel&lt;BR /&gt;left join (select * from libshare.leads where x_adcb_last_lead_action_date='09Aug2021'd) C&lt;BR /&gt;on intnx('day',A.date,0,'B') = intnx('day',C.x_adcb_last_lead_action_date,0,'B')&lt;BR /&gt;and A.Product = C.adcb_utm_camp&lt;BR /&gt;&amp;nbsp;left join(select min(date) format date11. as startdate , max(date) format date11. as enddate ,&lt;BR /&gt;product from libSHARE.Total_Click_Impressions_Lead group by product) D on A.Product = D.Product&lt;BR /&gt;gr&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 13:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761801#M241115</guid>
      <dc:creator>SASUserRocks</dc:creator>
      <dc:date>2021-08-16T13:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761803#M241116</link>
      <description>&lt;P&gt;First, I highly recommend you format your code. Second, you should use the `Insert SAS Code` in the body header of the post to paste your code. I went ahead and formatted your code (your first post, not your second) in my own way which may not be preferable to you, but it makes it more readable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table 	libshare.Total_Click_Impressions_Lead as
		select 		
					distinct A.date,
					A.Product,
					count( A.ImpressionId) as Impressions,
					count( B.clickid) as Clicks,
					count(distinct row_id||x_adcb_prod_group||x_adcb_prod_code||utm_medium) as Leads,
					startdate as start_date ,enddate as end_date 
		from 
					impressions A
						left join 
					clicks B 
							on 	A.date = B.date and 
								A.Product = B.ProductLabel
						left join 	(
										select 
													* 
										from 
													libshare.leads
										where 
													x_adcb_last_lead_action_date = '09Aug2021'd
									) C
							on 	intnx('day',A.date,0,'B') = intnx('day',C.x_adcb_last_lead_action_date,0,'B') and
								A.Product = C.adcb_utm_camp
 						left join	(
 										select 
 													min(date) format date11. as startdate,
 													max(date) format date11. as enddate,
													product
										from 
													libshare.Total_Click_Impressions_Lead
										group by
													product
									) D 
							on A.Product = D.Product
		group by 	A.date, A.Product;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Most importantly, &lt;STRONG&gt;I would request that we see your log and any warnings/messages that you're receiving. &lt;/STRONG&gt;Since we don't have any data to reproduce your example, it makes it a bit more difficult.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would presume that all the joins that you have in here are slowing the program down, particularly the 'SELECT *" that you have. But again, I don't have your data, so I can only run off assumptions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might help to break the query down into smaller parts to see where your issues are occurring.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 13:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761803#M241116</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-08-16T13:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761805#M241117</link>
      <description>&lt;P&gt;Thanks a lot for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here Impressions contains 60781 records and clicks contain 2058. and leads contain around 10. Its taking very long time that i force stop every time, commenting some codes , i think the issue started to come for certain products where impressions came very high this month causing this slowness. Do you require sample data here.&lt;/P&gt;&lt;P&gt;also i think joining with leads causes more slowness as join with impressions and clicks was giving results within 30 mins..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 13:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761805#M241117</guid>
      <dc:creator>SASUserRocks</dc:creator>
      <dc:date>2021-08-16T13:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761809#M241119</link>
      <description>&lt;P&gt;changed leads block to below and evaluating the execution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;left join (&lt;BR /&gt;select&lt;BR /&gt;row_id,prod_group,x_adcb_prod_code,utm_medium&lt;BR /&gt;from&lt;BR /&gt;libshare.leads&lt;BR /&gt;where&lt;BR /&gt;lead_action_date = '09Aug2021'd&lt;BR /&gt;) C&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 14:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761809#M241119</guid>
      <dc:creator>SASUserRocks</dc:creator>
      <dc:date>2021-08-16T14:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761826#M241124</link>
      <description>&lt;P&gt;One thing you have that is wasting clock cycles:&lt;/P&gt;
&lt;PRE&gt;on intnx('day',A.date,0,'B') = intnx('day',C.x_adcb_last_lead_action_date,0,'B')&lt;/PRE&gt;
&lt;P&gt;INTNX 0 for 'day' if the value is a date does nothing, and the "B" is also practically useless. There is no "beginning" for a DAY value. If you have a DATETIME and are using DTDAY as the interval then you get the time portion to reflect the beginning of the datetime for that date part. With date and 0 though just wasting time calling the function as the result is the same.&lt;/P&gt;
&lt;P&gt;In the example below note that &lt;STRONG&gt;all&lt;/STRONG&gt; the Y variables have the same value as X.&lt;/P&gt;
&lt;PRE&gt;data example;
   x='01JUL2021'd;
   y1=intnx('day',x,0);
   y2=intnx('day',x,0,'B');
   y3=intnx('day',x,0,'E');
   y4=intnx('day',x,0,'S');
   format x y: date9.;
   put _all_;
run;&lt;/PRE&gt;
&lt;P&gt;You code may run a little bit faster using&lt;/P&gt;
&lt;PRE&gt;on A.date = C.x_adcb_last_lead_action_date&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Aug 2021 14:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761826#M241124</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-16T14:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761831#M241127</link>
      <description>A.date and C.lead action date are in different formats, is this okay to equating like this.</description>
      <pubDate>Mon, 16 Aug 2021 15:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761831#M241127</guid>
      <dc:creator>SASUserRocks</dc:creator>
      <dc:date>2021-08-16T15:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761834#M241129</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286518"&gt;@SASUserRocks&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;A.date and C.lead action date are in different formats, is this okay to equating like this.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;FORMAT has absolutely &lt;STRONG&gt;no&lt;/STRONG&gt; impact on comparing values.&lt;/P&gt;
&lt;P&gt;You are just wasting clock cycles.&lt;/P&gt;
&lt;P&gt;You asked about optimization and "running long hours". Small thing things like these unneeded function calls add to longer running times.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 15:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761834#M241129</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-16T15:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761835#M241130</link>
      <description>&lt;P&gt;Fine, I just took care of this and added extra filter for D block, query still running...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table libshare.Total_Click_Impressions_Lead3 as&lt;BR /&gt;select&lt;BR /&gt;distinct A.date,&lt;BR /&gt;A.Product,&lt;BR /&gt;count( A.ImpressionId) as Impressions,&lt;BR /&gt;count( B.clickid) as Clicks,&lt;BR /&gt;count(distinct row_id||x_adcb_prod_group||adcb_utm_camp||utm_medium) as Leads,&lt;BR /&gt;startdate as start_date ,enddate as end_date&lt;BR /&gt;from&lt;BR /&gt;impressions A&lt;BR /&gt;left join&lt;BR /&gt;clicks B&lt;BR /&gt;on A.date = B.date and&lt;BR /&gt;A.Product = B.ProductLabel&lt;BR /&gt;left join (&lt;BR /&gt;select&lt;BR /&gt;row_id,x_adcb_prod_group,adcb_utm_camp,utm_medium,x_adcb_last_lead_action_date&lt;BR /&gt;from&lt;BR /&gt;libshare.LEADS&lt;BR /&gt;where&lt;BR /&gt;x_adcb_last_lead_action_date = '09Aug2021'd&lt;BR /&gt;) C&lt;BR /&gt;on A.date = C.x_adcb_last_lead_action_date and&lt;BR /&gt;A.Product = C.adcb_utm_camp&lt;BR /&gt;left join (&lt;BR /&gt;select&lt;BR /&gt;min(date) format date11. as startdate,&lt;BR /&gt;max(date) format date11. as enddate,&lt;BR /&gt;product&lt;BR /&gt;from&lt;BR /&gt;libshare.Total_Click_Impressions_Lead&lt;BR /&gt;group by&lt;BR /&gt;product having max(date) &amp;gt;='09Aug2021'd&lt;BR /&gt;) D&lt;BR /&gt;on A.Product = D.Product&lt;BR /&gt;group by A.date, A.Product;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 15:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761835#M241130</guid>
      <dc:creator>SASUserRocks</dc:creator>
      <dc:date>2021-08-16T15:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql query optimization - Running long hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761837#M241132</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table 	libshare.Total_Click_Impressions_Lead3 as
		select 		
					distinct A.date,
					A.Product,
					count( A.ImpressionId) as Impressions,
					count( B.clickid) as Clicks,
					count(distinct row_id||x_adcb_prod_group||adcb_utm_camp||utm_medium) as Leads,
					startdate as start_date ,enddate as end_date 
		from 
					impressions A
						left join 
					clicks B 
							on 	A.date = B.date and 
								A.Product = B.ProductLabel
						left join 	(
										select 
												 row_id,x_adcb_prod_group,adcb_utm_camp,utm_medium,x_adcb_last_lead_action_date
										from 
													libshare.LEADS
										where 
													x_adcb_last_lead_action_date = '09Aug2021'd
									) C
							on 	A.date = C.x_adcb_last_lead_action_date and
								A.Product = C.adcb_utm_camp
 						left join	(
										select 
 													min(date) format date11. as startdate,
 													max(date) format date11. as enddate,
													product
										from 
													libshare.Total_Click_Impressions_Lead
													group by
													product having max(date) &amp;gt;='09Aug2021'd
									) D 
							on A.Product = D.Product
		group by 	A.date, A.Product;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Aug 2021 15:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-query-optimization-Running-long-hours/m-p/761837#M241132</guid>
      <dc:creator>SASUserRocks</dc:creator>
      <dc:date>2021-08-16T15:24:33Z</dc:date>
    </item>
  </channel>
</rss>

