<?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: Output both records that meet and don't meet the selection criteria SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212698#M267496</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming that we're dealing with SAS tables here using a hash lookup could be quite efficient. See code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname import (work);&lt;/P&gt;&lt;P&gt;libname extract (work);&lt;/P&gt;&lt;P&gt;data IMPORT.BAC21 IMPORT.MMF20;&lt;/P&gt;&lt;P&gt;&amp;nbsp; T_M_STYLE='abc';&lt;/P&gt;&lt;P&gt;&amp;nbsp; do T_M_N=1 to 10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output IMPORT.BAC21;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mod(t_m_n,2)=0 then output IMPORT.MMF20;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data EXTRACT.ACCOUNTS_FOR_M rest;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 0 then set IMPORT.MMF20(keep=T_M_N);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dcl hash h(dataset:'IMPORT.MMF20(keep=T_M_N)');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rc=h.defineKey('T_M_N');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rc=h.defineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop _rc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set IMPORT.BAC21(WHERE=(T_M_STYLE &amp;lt;&amp;gt; "ZZZ"));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if h.check()=0 then output EXTRACT.ACCOUNTS_FOR_M;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else output rest;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 31 Mar 2015 10:05:45 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2015-03-31T10:05:45Z</dc:date>
    <item>
      <title>Output both records that meet and don't meet the selection criteria SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212693#M267491</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if there is a way to output records that do not meet a selection criteria into a different dataset using SQL. How do I achieve the below without rewriting the opposite of the below query&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT;&lt;/P&gt;&lt;P&gt; CREATE TABLE EXTRACT.ACCOUNTS_FOR_M AS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT A.*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IMPORT.BAC21(WHERE=(A.T_M_STYLE &amp;lt;&amp;gt; "ZZZ")) AS A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; WHERE A.T_M_N IN (SELECT B.T_M_N FROM IMPORT.MMF20 AS B)&lt;/P&gt;&lt;P&gt; ;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Mar 2015 14:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212693#M267491</guid>
      <dc:creator>Avenue</dc:creator>
      <dc:date>2015-03-30T14:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Output both records that meet and don't meet the selection criteria SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212694#M267492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this is best done with a data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data&lt;/P&gt;&lt;P&gt;&amp;nbsp; output_with&lt;/P&gt;&lt;P&gt;&amp;nbsp; output_without&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if condition&lt;/P&gt;&lt;P&gt;then output output_with;&lt;/P&gt;&lt;P&gt;else output output_without;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Depending on your condition (how many items does SELECT B.T_M_N FROM IMPORT.MMF20 AS B render?), you may have to prepare your datasets for a merge first or use other tools like a format that gives you the condition, or a hash object.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Mar 2015 14:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212694#M267492</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-03-30T14:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Output both records that meet and don't meet the selection criteria SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212695#M267493</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The select returns about 4 million records. I am interested in finding records that exist in both datasets without dropping them with no visibility.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea how will the merge function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Mar 2015 07:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212695#M267493</guid>
      <dc:creator>Avenue</dc:creator>
      <dc:date>2015-03-31T07:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Output both records that meet and don't meet the selection criteria SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212696#M267494</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort&lt;/P&gt;&lt;P&gt;&amp;nbsp; data=import.bac21 (where=(T_M_STYLE &amp;lt;&amp;gt; "ZZZ"))&lt;/P&gt;&lt;P&gt;&amp;nbsp; out=int_a&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;by T_M_N;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort&lt;/P&gt;&lt;P&gt;&amp;nbsp; data=import.mmf20 (keep=T_M_N)&lt;/P&gt;&lt;P&gt;&amp;nbsp; out=int_b&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;by T_M_N;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data&lt;/P&gt;&lt;P&gt;&amp;nbsp; EXTRACT.ACCOUNTS_FOR_M&lt;/P&gt;&lt;P&gt;&amp;nbsp; missing_records&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;merge&lt;/P&gt;&lt;P&gt;&amp;nbsp; int_a (in=a)&lt;/P&gt;&lt;P&gt;&amp;nbsp; int_b (in=b)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;by T_M_N;&lt;/P&gt;&lt;P&gt;if a;&lt;/P&gt;&lt;P&gt;if b then output EXTRACT.ACCOUNTS_FOR_M;&lt;/P&gt;&lt;P&gt;else output missing_records;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Mar 2015 07:16:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212696#M267494</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-03-31T07:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Output both records that meet and don't meet the selection criteria SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212697#M267495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you mean by "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;without rewriting the opposite of the below query". Why not?. What is your actual requirement?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;Is this a one time shot or something that will be executed regularly? &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW having the where as a DS-option ads no value in this case. Moving the criteria to the WHERE clau&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;se will make the code more readable and clean.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Mar 2015 07:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212697#M267495</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-03-31T07:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Output both records that meet and don't meet the selection criteria SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212698#M267496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming that we're dealing with SAS tables here using a hash lookup could be quite efficient. See code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname import (work);&lt;/P&gt;&lt;P&gt;libname extract (work);&lt;/P&gt;&lt;P&gt;data IMPORT.BAC21 IMPORT.MMF20;&lt;/P&gt;&lt;P&gt;&amp;nbsp; T_M_STYLE='abc';&lt;/P&gt;&lt;P&gt;&amp;nbsp; do T_M_N=1 to 10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output IMPORT.BAC21;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mod(t_m_n,2)=0 then output IMPORT.MMF20;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data EXTRACT.ACCOUNTS_FOR_M rest;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 0 then set IMPORT.MMF20(keep=T_M_N);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dcl hash h(dataset:'IMPORT.MMF20(keep=T_M_N)');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rc=h.defineKey('T_M_N');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rc=h.defineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop _rc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set IMPORT.BAC21(WHERE=(T_M_STYLE &amp;lt;&amp;gt; "ZZZ"));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if h.check()=0 then output EXTRACT.ACCOUNTS_FOR_M;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else output rest;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Mar 2015 10:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-both-records-that-meet-and-don-t-meet-the-selection/m-p/212698#M267496</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-03-31T10:05:45Z</dc:date>
    </item>
  </channel>
</rss>

