<?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: Matching observations from one data to see if any are missing in another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343749#M78936</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13754"&gt;@AndrewHowell&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Assuming the tables are called First&amp;nbsp;&amp;amp;&amp;nbsp;Second:&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;
&amp;nbsp; /* Get IDs in First but not in Second */
&amp;nbsp; select id from First&amp;nbsp;except select id from Second;
&amp;nbsp; /* Get IDs in Second but not in First&amp;nbsp;*/
&amp;nbsp; select id from Second&amp;nbsp;except select id from First;
&amp;nbsp; /* Get IDs in both&amp;nbsp;*/
&amp;nbsp; select id from Second intersect select id from First;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this help?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;May want select distinct id if there are duplicates.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2017 15:13:48 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-03-23T15:13:48Z</dc:date>
    <item>
      <title>Matching observations from one data to see if any are missing in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343684#M78920</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets and I need to see if observations from one dataset are missing from another dataset. For example,&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;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; Name :&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;upcase4&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; id Net &lt;SPAN class="token procnames"&gt;Reg&lt;/SPAN&gt; Loss&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;   &lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;home 344 200  50    .
home 543  80   .    5
TDR  453  75   .    3
TDR  543   .   5    .&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;BR /&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN&gt; have&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN&gt; Name :&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;upcase4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN&gt; id Net &lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;Reg&lt;/SPAN&gt;&lt;SPAN&gt; Loss&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt; &lt;BR /&gt;home &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;344 200  50    .
home 543  80   .    5&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I want to see if any ids are missing in the second dataset compared with the first dataset. For example, id 453 is missing but 543 and 344 are not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Jack&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 12:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343684#M78920</guid>
      <dc:creator>jackmelbourne</dc:creator>
      <dc:date>2017-03-23T12:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Matching observations from one data to see if any are missing in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343691#M78922</link>
      <description>&lt;P&gt;Assuming the tables are called First&amp;nbsp;&amp;amp;&amp;nbsp;Second:&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;
&amp;nbsp; /* Get IDs in First but not in Second */
&amp;nbsp; select id from First&amp;nbsp;except select id from Second;
&amp;nbsp; /* Get IDs in Second but not in First&amp;nbsp;*/
&amp;nbsp; select id from Second&amp;nbsp;except select id from First;
&amp;nbsp; /* Get IDs in both&amp;nbsp;*/
&amp;nbsp; select id from Second intersect select id from First;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Does this help?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 13:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343691#M78922</guid>
      <dc:creator>AndrewHowell</dc:creator>
      <dc:date>2017-03-23T13:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Matching observations from one data to see if any are missing in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343701#M78924</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have1;
by id;
run;

proc sort data=have2;
by id;
run;

data
  miss_from_have2
  miss_from_have1
  both
;
merge
  have1 (in=a keep=id)
  have2 (in=b keep=id)
;
by id;
if a and b
then output both;
else if a
then output miss_from_have2;
else output miss_from_have1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;might perform better on large datasets.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 13:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343701#M78924</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-23T13:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Matching observations from one data to see if any are missing in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343730#M78931</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Elegant SQL intersection and exception of sets of data

Matching observations from one data to see if any are missing in another dataset

see
https://goo.gl/xCjIsU
https://communities.sas.com/t5/Base-SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343684

HAVE
=====

Up to 40 obs WORK.HAV1ST total obs=2

Obs    NAME    ID

 1     home    ___
 2     home    XXX


Up to 40 obs WORK.HAV2ND total obs=4

Obs    NAME    ID

 1     home    ___
 2     home    XXX
 3     TDR     @@@
 4     TDR     XXX

WANT
=====

   SQLOBS=0 hav1st except hav2nd

   SQLOBS=1 hav2nd except hav1st

   ID
   --------
   @@@

   SQLOBS=2 hav2nd intersect hav1st

   ID
   --------
   XXX
   ___

FULL SOLUTION
===============


%utlnopts; /* turn options off so so only the puts statements are in the log */
proc sql;

  /* ID @@@ Get IDs in hav1st but not in hav2nd */
  select id from hav1st except select id from hav2nd;
  %put &amp;amp;=sqlobs hav1st except hav2nd;

  /* Get IDs in hav2nd but not in hav1st */
  select id from hav2nd except select id from hav1st;
  %put &amp;amp;=sqlobs hav2nd except hav1st;

  /* Get IDs in both */
  select id from hav2nd intersect select id from hav1st;
  %put &amp;amp;=sqlobs hav2nd intersect hav1st;

quit;

proc sql;
  select id from hav1st where id not in (select id from hav2nd);
  %put &amp;amp;=sqlobs hav1st except hav2nd;
  select id from hav2nd where id not in (select id from hav1st);
  %put &amp;amp;=sqlobs hav2nd except hav1st;
  select id from hav1st where id in (select id from hav2nd);
  %put &amp;amp;=sqlobs hav2nd intersect hav1st;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 14:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343730#M78931</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-23T14:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Matching observations from one data to see if any are missing in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343749#M78936</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13754"&gt;@AndrewHowell&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Assuming the tables are called First&amp;nbsp;&amp;amp;&amp;nbsp;Second:&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;
&amp;nbsp; /* Get IDs in First but not in Second */
&amp;nbsp; select id from First&amp;nbsp;except select id from Second;
&amp;nbsp; /* Get IDs in Second but not in First&amp;nbsp;*/
&amp;nbsp; select id from Second&amp;nbsp;except select id from First;
&amp;nbsp; /* Get IDs in both&amp;nbsp;*/
&amp;nbsp; select id from Second intersect select id from First;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this help?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;May want select distinct id if there are duplicates.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 15:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343749#M78936</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-23T15:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Matching observations from one data to see if any are missing in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343780#M78945</link>
      <description>&lt;P&gt;This can also be a good task for beginning to use hash objects:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first_not_second;
  set first;
  if _n_=1 then do;
    declare hash second_ids (dataset:'second(keep=id)');
      second_ids.definekey(all:'Y');
      second_ids.definedone();
  end;
  if second_ids.find()^=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 17:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-observations-from-one-data-to-see-if-any-are-missing-in/m-p/343780#M78945</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-23T17:10:06Z</dc:date>
    </item>
  </channel>
</rss>

