<?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 Not Exists Operator in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316864#M69301</link>
    <description>&lt;P&gt;For some reason I just ran it and it worked now. Thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2016 22:16:26 GMT</pubDate>
    <dc:creator>kisumsam</dc:creator>
    <dc:date>2016-12-05T22:16:26Z</dc:date>
    <item>
      <title>Proc Sql Not Exists Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316824#M69289</link>
      <description>&lt;P&gt;Hello, got a question about proc sql. I have the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;** List of full employee list **;
data emplist;
do empid = 1 to 1000;
first = "XXX";
last = "YYY";
address = "ZZZ";
output;
end;
run;

** List of terminated employee **;
data empterm;
do empid = 1 to 1000;
if ranuni(0)&amp;lt;0.05 then output;
end;
run;

** List of current employee **;
proc sql;
select empid, first, last, address
from emplist
where not exists 
	(select *
		from empterm
		where emplist.empid=empterm.empid);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The first data step creates a full list of employee. The second data step creates a list of terminated employee.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use the NOT EXISTS operator to create a data set of current employees (full list - terminated). I created the code based on a sample code that I read from&amp;nbsp;the advanced exam study guide but it doesn't seem to be working. It creates the full list of employees including the terminated ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you anyone&amp;nbsp;show me the problem(s) I have with my code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 19:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316824#M69289</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2016-12-05T19:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Not Exists Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316830#M69292</link>
      <description>&lt;P&gt;I think you mean:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; empid&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; last&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; address
&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; emplist
&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;STRONG&gt;&lt;SPAN class="token operator"&gt;empid not in&lt;/SPAN&gt;
&lt;SPAN class="token punctuation"&gt;     (&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;empid &lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; empterm);&lt;/STRONG&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 20:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316830#M69292</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-05T20:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Not Exists Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316834#M69293</link>
      <description>&lt;P&gt;Thanks Shmuel. I think your code works but the exact code I got from the prep guide is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select lastname, firstname
from sasuser.flightattendants
where not exists
(select *
from sasuser.flightschedule
where flightattendants.empid=
flightschedule.empid);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code above is supposed to do a, in data step term, "if a and not b merge".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified it to test the sample data sets that I created but it didn't work. Do you know why?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 20:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316834#M69293</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2016-12-05T20:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Not Exists Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316836#M69294</link>
      <description>&lt;P&gt;I have the feeling that "where not exist" needs a following condition to check,&lt;/P&gt;
&lt;P&gt;some expression that is either TRUE or FALSE.&lt;/P&gt;
&lt;P&gt;Maybe there is a typo in the guide code. I can't guess.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 20:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316836#M69294</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-05T20:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Not Exists Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316863#M69300</link>
      <description>&lt;P&gt;It does work for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;98   ** List of full employee list **;
99   data emplist;
100  do empid = 1 to 1000;
101  first = "XXX";
102  last = "YYY";
103  address = "ZZZ";
104  output;
105  end;
106  run;

NOTE: The data set WORK.EMPLIST has 1000 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.03 seconds


107
108  ** List of terminated employee **;
109  data empterm;
110  do empid = 1 to 1000;
111  if ranuni(0)&amp;lt;0.05 then output;
112  end;
113  run;

NOTE: The data set WORK.EMPTERM has 46 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


114
115  ** List of current employee **;
116  proc sql;
117  create table current as
118  select empid, first, last, address
119  from emplist
120  where not exists
121      (select *
122          from empterm
123          where emplist.empid=empterm.empid);
NOTE: Table WORK.CURRENT created, with 954 rows and 4 columns.

124  quit;
&lt;/PRE&gt;
&lt;P&gt;Note the number of rows in table CURRENT.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 22:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316863#M69300</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-12-05T22:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Not Exists Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316864#M69301</link>
      <description>&lt;P&gt;For some reason I just ran it and it worked now. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 22:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Not-Exists-Operator/m-p/316864#M69301</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2016-12-05T22:16:26Z</dc:date>
    </item>
  </channel>
</rss>

