<?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 to get result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312842#M67886</link>
    <description>&lt;P&gt;What's the Error? Please post the relevant section of the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In below code shouldn't this be&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;STRONG&gt;b.buyerid=&lt;FONT color="#FF0000"&gt;o.&lt;/FONT&gt;buyerid&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc sql ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select b.buyers,b.f_name,b.l_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from sasdata.buyers b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;left join sasdata.orderIf you want all rows in table buyers&amp;nbsp;with no match to table Orderno then use an EXIST clause.s o on &lt;FONT color="#000000"&gt;&lt;STRONG&gt;b.buyerid=&lt;FONT color="#FF0000"&gt;b.&lt;/FONT&gt;buyerid&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;where o.orderno is missing;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You write "&lt;EM&gt;Second SQL statement will be then used an outer join..&lt;/EM&gt;" but in the code you've posted you're using a LEFT join.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I also can't see how this would achieve your goal as you then only keep variables from table Buyers. What will happen is that you end up with duplicate rows if there is a 1:M join.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;From what you describe I believe you're after code logic as below (not tested)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table accessories2016 as
    select distinct buyerid 
    from sasdata.accessories
    WHERE dateord between '01jan2016 00:00:00'dt and '31dec2016 23:59:59'dt
  ;
quit;


proc sql;
  select b.buyers,b.f_name,b.l_name
    from sasdata.buyers b
    where b.buyerid not in (select buyerid from accessories2016)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 20 Nov 2016 00:42:40 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2016-11-20T00:42:40Z</dc:date>
    <item>
      <title>Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312837#M67881</link>
      <description>&lt;P&gt;I am getting errors in log which I cannot clear. Hope somebody can help me to check my below SQL code can be changed to make my code work.I want to create through 2 SQL queries which should display the buyer id and the f_name and l_names of all the buyers who made no accessories&amp;nbsp;orders in the year 2016.&amp;nbsp;&lt;SPAN&gt;First&amp;nbsp;SQL statement &amp;nbsp;to create&lt;/SPAN&gt;&amp;nbsp;a dataset called accessories2016 which has all the columns in sasdata.accessories and the rows for which the year sold is 2016.&amp;nbsp;Second SQL statement will be then used an outer join to complete my requirements.My code looks like this: I have two tables buyers and orders&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table accessories2016 AS
select * from
sasdata.accessories
WHERE Year(datepart(dateord))=2016;
quit;

proc sql ;
select b.buyers,b.f_name,b.l_name
from sasdata.buyers b
left join sasdata.orders o on b.buyerid=b.buyerid
where o.orderno is missing;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 05:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312837#M67881</guid>
      <dc:creator>afs</dc:creator>
      <dc:date>2016-11-20T05:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312840#M67884</link>
      <description>&lt;P&gt;This is not an answer to your question, but I'd suggest you consider the inefficiency of a where clause like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; WHERE Year(datepart(dateord))=2016;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;which will perform two functions on variable DATEORD for every observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since dateord is apparently a datetime value, consider using datetime literals as upper and lower bounds on dateord, i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; where dateord between '01jan2016 00:00:00'dt and '31dec2016 23:59:59'dt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The benefit is that you are comparing dateord to two fixed values - avoiding&amp;nbsp;unnecessary computation.&amp;nbsp; Possibly beneficial for large datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 00:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312840#M67884</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-20T00:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312841#M67885</link>
      <description>And oh yes, I forgot.  What errors are you seeing in your log?</description>
      <pubDate>Sun, 20 Nov 2016 00:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312841#M67885</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-20T00:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312842#M67886</link>
      <description>&lt;P&gt;What's the Error? Please post the relevant section of the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In below code shouldn't this be&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;STRONG&gt;b.buyerid=&lt;FONT color="#FF0000"&gt;o.&lt;/FONT&gt;buyerid&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc sql ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select b.buyers,b.f_name,b.l_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from sasdata.buyers b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;left join sasdata.orderIf you want all rows in table buyers&amp;nbsp;with no match to table Orderno then use an EXIST clause.s o on &lt;FONT color="#000000"&gt;&lt;STRONG&gt;b.buyerid=&lt;FONT color="#FF0000"&gt;b.&lt;/FONT&gt;buyerid&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;where o.orderno is missing;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You write "&lt;EM&gt;Second SQL statement will be then used an outer join..&lt;/EM&gt;" but in the code you've posted you're using a LEFT join.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I also can't see how this would achieve your goal as you then only keep variables from table Buyers. What will happen is that you end up with duplicate rows if there is a 1:M join.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;From what you describe I believe you're after code logic as below (not tested)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table accessories2016 as
    select distinct buyerid 
    from sasdata.accessories
    WHERE dateord between '01jan2016 00:00:00'dt and '31dec2016 23:59:59'dt
  ;
quit;


proc sql;
  select b.buyers,b.f_name,b.l_name
    from sasdata.buyers b
    where b.buyerid not in (select buyerid from accessories2016)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Nov 2016 00:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312842#M67886</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-20T00:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312861#M67890</link>
      <description>Dear Patric ,&lt;BR /&gt;b.buyerid=b.buyerid was a typo error .&lt;BR /&gt;For the second statement i wanted an outer join to complete my statement.As i was trying rather sub query to use outer join . If you can help</description>
      <pubDate>Sun, 20 Nov 2016 03:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312861#M67890</guid>
      <dc:creator>afs</dc:creator>
      <dc:date>2016-11-20T03:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312929#M67925</link>
      <description>&lt;P&gt;You could use a set operation to get the list of desired buyerId's and a join to get other fields from the sasdata.buyers table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table nonBuyersId2016 as
select buyerId from sasdata.buyers
except
select buyerId from sasdata.accessories
	where dateord between '01jan2016:00:00'dt and '31dec2016:23:59:59'dt;
	
create table nonBuyers2016 as
select a.buyerId, a.f_name, a.l_name
from sasdata.buyers as a natural join nonBuyersId2016;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Nov 2016 21:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312929#M67925</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-20T21:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312933#M67927</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/113625"&gt;@afs﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;If you're asking for actual and tested code then you need to post sample data (a SAS data step creating such data), explain what you want to do and post/describe the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2016 22:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/312933#M67927</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-20T22:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/314156#M68380</link>
      <description>I used the following and i got the table for 2012&lt;BR /&gt;WHERE Year(accessories.dateord)=2012;&lt;BR /&gt;and then i used the orderno is missing and got the&lt;BR /&gt;select a.buyerId, a.f_name, a.l_name to get the result.&lt;BR /&gt;Wanted your input</description>
      <pubDate>Thu, 24 Nov 2016 22:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/314156#M68380</guid>
      <dc:creator>afs</dc:creator>
      <dc:date>2016-11-24T22:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries to get result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/314157#M68381</link>
      <description>&lt;P&gt;Great! Post the queries and we might be able to suggest optimisations.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 22:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries-to-get-result/m-p/314157#M68381</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-24T22:30:15Z</dc:date>
    </item>
  </channel>
</rss>

