<?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: Two queries different answers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302215#M64079</link>
    <description>&lt;P&gt;&lt;SPAN&gt;You're dealing with SAS files - right?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;400 million rows and 60+ variables: That's for table &lt;EM&gt;ods_bi_recon_selected&lt;/EM&gt;?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What's the size of&amp;nbsp;&lt;EM&gt;ods_iv_recon_selected?&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what you need are all distinct rows in &lt;EM&gt;ods_bi_recon_selected&lt;/EM&gt;&amp;nbsp;with no match over&amp;nbsp;the key column to&amp;nbsp;&lt;EM&gt;ods_iv_recon_selected? Right?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And: Do you have an idea how many distinct values for imb_code you're having in &lt;EM&gt;ods_iv_recon_selected?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;....and last but not least: How many rows do you expect to get in result table QueryData?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm thinking about using a hash approach but it will depend on volumes if that's possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Oct 2016 02:13:27 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2016-10-04T02:13:27Z</dc:date>
    <item>
      <title>Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302184#M64070</link>
      <description>&lt;P&gt;Hi. &amp;nbsp;Any ideas why these two queries return a different number of rows?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*	 RULE: PIECES MISSING IN IV QUERY */
	%PUT CHECK: RULE: PIECES MISSING IN IV QUERY 999.1;
	proc sql;
		create table QueryData as
		select DISTINCT subpad('PIECES MISSING IN IV',1,58) as RULE_NM, 
		       	actual_dlvry_date, 
				subpad(imb_code,1,31) as IMB_CODE length=31, 
				999.1 as Rule_Order,
				imb_dlvry_zip_5
		from ods_bi_recon_selected_mp
        EXCEPT
		select DISTINCT subpad('PIECES MISSING IN IV',1,58) as RULE_NM, 
		       	actual_dlvry_date, 
				subpad(imb_code,1,31) as IMB_CODE length=31, 
				999.1 as Rule_Order,
				imb_dlvry_zip_5
		from ods_iv_recon_selected_mp;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;vs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*	 RULE: PIECES MISSING IN IV QUERY */
	%PUT CHECK: RULE: PIECES MISSING IN IV QUERY 999.1;
	proc sql;
		create table QueryData as
		select DISTINCT subpad('PIECES MISSING IN IV',1,58) as RULE_NM, 
		       	actual_dlvry_date, 
				subpad(imb_code,1,31) as IMB_CODE length=31, 
				999.1 as Rule_Order,
				imb_dlvry_zip_5
		from ods_bi_recon_selected_mp
	    where imb_code not in(select imb_code 
		                        from ods_iv_recon_selected_mp);
	quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Oct 2016 22:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302184#M64070</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-03T22:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302203#M64074</link>
      <description>&lt;P&gt;The first query using EXCEPT only excludes rows where ALL columns are identical.&lt;/P&gt;
&lt;P&gt;The second query excludes all rows where there is a matching&amp;nbsp;IMB_CODE (but other columns can still have&amp;nbsp;different values).&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 00:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302203#M64074</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-04T00:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302205#M64075</link>
      <description>Wow, great insight. Thanks so much.&lt;BR /&gt;&lt;BR /&gt;I always thought Nested Selects were inefficient, which is the reason I was trying the Except concept.&lt;BR /&gt;&lt;BR /&gt;Is there a more efficient way to restructure the nested select version of the query and get the same results where ? Or is the Nested Select a good option?</description>
      <pubDate>Tue, 04 Oct 2016 01:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302205#M64075</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-04T01:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302208#M64077</link>
      <description>&lt;P&gt;If using EXCEPT you want also to pay attention to the effect of keyword ALL&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/69049/HTML/default/viewer.htm#n0vo2lglyrnexwn14emi8m0jqvrj.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/sqlproc/69049/HTML/default/viewer.htm#n0vo2lglyrnexwn14emi8m0jqvrj.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which syntax to use really depends on what result you need&amp;nbsp;and if it's about performance then also what data volumes you're dealing with (eg.&amp;nbsp;the number of rows of the table used within the IN operator).&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 01:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302208#M64077</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-04T01:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302211#M64078</link>
      <description>Thanks for this info! Yah, it's 400 million rows and 60+ variables. Huge to me, but what are ur thoughts on that size of a ds using the Nested Select?</description>
      <pubDate>Tue, 04 Oct 2016 01:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302211#M64078</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-04T01:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302215#M64079</link>
      <description>&lt;P&gt;&lt;SPAN&gt;You're dealing with SAS files - right?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;400 million rows and 60+ variables: That's for table &lt;EM&gt;ods_bi_recon_selected&lt;/EM&gt;?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What's the size of&amp;nbsp;&lt;EM&gt;ods_iv_recon_selected?&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what you need are all distinct rows in &lt;EM&gt;ods_bi_recon_selected&lt;/EM&gt;&amp;nbsp;with no match over&amp;nbsp;the key column to&amp;nbsp;&lt;EM&gt;ods_iv_recon_selected? Right?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And: Do you have an idea how many distinct values for imb_code you're having in &lt;EM&gt;ods_iv_recon_selected?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;....and last but not least: How many rows do you expect to get in result table QueryData?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm thinking about using a hash approach but it will depend on volumes if that's possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 02:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302215#M64079</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-04T02:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302220#M64082</link>
      <description>Sorry, 400 million for the BI and 400 million for the IV dataset each. Yes, both are already SAS datasets.&lt;BR /&gt;&lt;BR /&gt;Yes, distinct only, BUT approx. 98% of records are already DISTINCT.&lt;BR /&gt;&lt;BR /&gt;I expect anywhere from 0 to 400 million records in QueryData depending on the day the code is run.&lt;BR /&gt;&lt;BR /&gt;Thanks for your input.</description>
      <pubDate>Tue, 04 Oct 2016 02:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302220#M64082</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-04T02:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302224#M64083</link>
      <description>&lt;P&gt;&lt;SPAN&gt;If the volumes in both tables are that huge and there is nothing you can do to reduce them AND your key column has potentially also more&amp;nbsp;distinct values than we could fit into memory, then I guess your 2nd query is more or less what you can do.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does your result set really need to be "distinct"? That's very costly.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The following paper provides a lot of insight of how the SQL optimizer works which is all you need to decide in concrete cases how you could eventually tweak code:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/101-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/101-30.pdf&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 02:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302224#M64083</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-04T02:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302304#M64122</link>
      <description>&lt;P&gt;If imp_code is 8 bytes, the table will 3GB, which probably can fit into memory (?), thus&amp;nbsp;making a hash table lookup feasible.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 10:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302304#M64122</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-04T10:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries different answers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302331#M64132</link>
      <description>&lt;P&gt;I'm using DISTINCT because about 2% of IMB_CODEs are duplicates and the duplicates break my program. &amp;nbsp;So for now I'm choosing to lose 2% of my data just to make head way...not good I know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The official requirement is that IMB_CODEs are only unique for 30 days after their ACTUAL_DLVRY_DATE variable value. &amp;nbsp;Is there anyway I can remove the UNIQUE option and still handle a requirement like this? &amp;nbsp;If there is I'd appreciate the help for sure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*	 RULE: PIECES MISSING IN IV QUERY */
%PUT CHECK: RULE: PIECES MISSING IN IV QUERY 999.1;
proc sql;
	create table QueryData as
	SELECT &lt;STRONG&gt;&lt;STRIKE&gt;DISTINCT&lt;/STRIKE&gt;&lt;/STRONG&gt; subpad('PIECES MISSING IN IV',1,58) as RULE_NM, 
	       	actual_dlvry_date, 
		subpad(imb_code,1,31) as IMB_CODE length=31, 
		999.1 as Rule_Order,
		imb_dlvry_zip_5
	FROM ods_bi_recon_selected_mp
        WHERE imb_code not in(select imb_code from ods_iv_recon_selected_mp)&lt;BR /&gt;          &lt;STRONG&gt;AND (requirement = IMB_CODEs are only unique for 30 days after their ACTUAL_DLVRY_DATE variable value?)&lt;/STRONG&gt;&lt;BR /&gt;        ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 13:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-different-answers/m-p/302331#M64132</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-10-04T13:19:49Z</dc:date>
    </item>
  </channel>
</rss>

