<?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 compare two datasets unique values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520529#M141153</link>
    <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; my1:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; my2:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clm drg tin;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;aa bb 1 2 3&lt;/P&gt;
&lt;P&gt;bb cc 2 3 4&lt;/P&gt;
&lt;P&gt;dd ee 3 4 5&lt;/P&gt;
&lt;P&gt;ff gg 4 5 6&lt;/P&gt;
&lt;P&gt;hh ii 6 7 8&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; b;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; cust1:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; cust2:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clm drg tin;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;aa bb 1 2 3&lt;/P&gt;
&lt;P&gt;bb cc 2 3 4&lt;/P&gt;
&lt;P&gt;zz xx 3 4 5&lt;/P&gt;
&lt;P&gt;yy ww 4 5 6&lt;/P&gt;
&lt;P&gt;hh ii 2 7 8&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="Courier New" size="3"&gt;I&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; am attempting to create a dataset where the contents of both tables DO NOT EQUAL&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in this case I want the first two rows in both are the same so i want to eliminate them.&amp;nbsp; I then want to create a dataset of the unique values&lt;/P&gt;
&lt;P&gt;Can this be done in a proc sql or datastep&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Dec 2018 20:31:45 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2018-12-11T20:31:45Z</dc:date>
    <item>
      <title>compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520529#M141153</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; my1:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; my2:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clm drg tin;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;aa bb 1 2 3&lt;/P&gt;
&lt;P&gt;bb cc 2 3 4&lt;/P&gt;
&lt;P&gt;dd ee 3 4 5&lt;/P&gt;
&lt;P&gt;ff gg 4 5 6&lt;/P&gt;
&lt;P&gt;hh ii 6 7 8&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; b;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; cust1:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; cust2:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; clm drg tin;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;aa bb 1 2 3&lt;/P&gt;
&lt;P&gt;bb cc 2 3 4&lt;/P&gt;
&lt;P&gt;zz xx 3 4 5&lt;/P&gt;
&lt;P&gt;yy ww 4 5 6&lt;/P&gt;
&lt;P&gt;hh ii 2 7 8&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="Courier New" size="3"&gt;I&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; am attempting to create a dataset where the contents of both tables DO NOT EQUAL&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in this case I want the first two rows in both are the same so i want to eliminate them.&amp;nbsp; I then want to create a dataset of the unique values&lt;/P&gt;
&lt;P&gt;Can this be done in a proc sql or datastep&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 20:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520529#M141153</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2018-12-11T20:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520534#M141156</link>
      <description>Can you please show what you'd like as an output? Is it ok to rename the first data set. Is this a one time thing, or something that needs to scale to other data sets? Or will be run multiple times?</description>
      <pubDate>Tue, 11 Dec 2018 20:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520534#M141156</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-11T20:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520538#M141157</link>
      <description>&lt;P&gt;It's not clear why the variables have different names in the two data sets, but let's take that as a given.&amp;nbsp; Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by my1 my2 clm drg tin;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by cust1 cust2 clm drg tin;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data unique;&lt;/P&gt;
&lt;P&gt;set a (in=ina rename=(my1=cust1 my2=cust2))&lt;/P&gt;
&lt;P&gt;b;&lt;/P&gt;
&lt;P&gt;by cust1 cust2 clm drg tin;&lt;/P&gt;
&lt;P&gt;if first.tin and last.tin;&lt;/P&gt;
&lt;P&gt;if in1 then source='Dataset A';&lt;/P&gt;
&lt;P&gt;else source3='Dataset B';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 20:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520538#M141157</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-11T20:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520544#M141160</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from 
(select * from a
	except 
 select * from b)
union 
select * from 
(select * from b
	except 
 select * from a)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 241px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25571iD120F1C7CFCFB10F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also,try PROC COMPARE which gives more information that might help you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare data=a compare=b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Dec 2018 20:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520544#M141160</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-12-11T20:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520546#M141162</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data a;

input my1:$2. my2:$2. clm drg tin;

datalines;
aa bb 1 2 3
bb cc 2 3 4
dd ee 3 4 5
ff gg 4 5 6
hh ii 6 7 8
;

run;

data b;

input cust1:$2. cust2:$2. clm drg tin;

datalines;
aa bb 1 2 3
bb cc 2 3 4
zz xx 3 4 5
yy ww 4 5 6
hh ii 2 7 8
;

proc sql;
create table want as
(select * from a
except all
select * from b)
union all
(select * from b
except all
select * from a);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Dec 2018 20:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520546#M141162</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-11T20:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520548#M141164</link>
      <description>&lt;P&gt;Oh well&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;I failed to notice the similar approach by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;&amp;nbsp;that was posted earlier. Ignore mine! Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 20:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520548#M141164</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-11T20:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520570#M141179</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;

input my1:$2. my2:$2. clm drg tin;

datalines;
aa bb 1 2 3
bb cc 2 3 4
dd ee 3 4 5
ff gg 4 5 6
hh ii 6 7 8
;

run;

data b;

input cust1:$2. cust2:$2. clm drg tin;

datalines;
aa bb 1 2 3
bb cc 2 3 4
zz xx 3 4 5
yy ww 4 5 6
hh ii 2 7 8
;

data _null_;
if _n_=1 then do;
if 0 then set a;
   dcl hash H (dataset:'a',multidata:'y',ordered:'y') ;
   h.definekey  ('my1','my2','clm','drg','tin') ;
   h.definedone () ;
end;
set b end=l;
rc= h.check(key:cust1,key:cust2,key:clm,key:drg,key:tin) ;
if rc=0 then rc1=h.remove(key:cust1,key:cust2,key:clm,key:drg,key:tin);
else h.add(key:cust1,key:cust2,key:clm,key:drg,key:tin,data:cust1,data:cust2,data:clm,data:drg,data:tin);
if l then h.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Dec 2018 21:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520570#M141179</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-11T21:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520575#M141183</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;Although it's almost similar you have covered one extra point by mentioning&amp;nbsp;&lt;STRONG&gt;ALL&lt;/STRONG&gt;, which will also include duplicate records if their are any.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 21:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520575#M141183</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-12-11T21:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520578#M141184</link>
      <description>&lt;P&gt;Here's a&amp;nbsp; single data step solution that doesn't require sorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input my1:$2. my2:$2. clm drg tin;
datalines;
aa bb 1 2 3
bb cc 2 3 4
dd ee 3 4 5
ff gg 4 5 6
hh ii 6 7 8
run;

data b;
  input cust1:$2. cust2:$2. clm drg tin;
datalines;
aa bb 1 2 3
bb cc 2 3 4
zz xx 3 4 5
yy ww 4 5 6
hh ii 2 7 8
run;

data want1 want2;
  set a b;
  if _n_=1 then do;
    declare hash h (dataset:'a (obs=0))';
      h.definekey(all:'Y');
      h.definedata(all:'Y');
      h.definedone();
  end;
  if h.check^=0 then do;
    output want1;
    h.add();
  end;
  else output want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The&amp;nbsp; strategy here is&lt;/P&gt;
&lt;P&gt;&amp;nbsp; read a record&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if this is first time for these values (i.e. not in the hash object) then output want1 and put it in the hash object for later checking&lt;/P&gt;
&lt;P&gt;&amp;nbsp; but if it's already in the hash then output want2.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 21:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520578#M141184</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-11T21:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520580#M141185</link>
      <description>&lt;P&gt;Yes thank you, but you did post it and I missed to see it which I generally don't. Anyways,&amp;nbsp; indeed probably the best approach by any means right from convenience of coding, to maintenance and change requests by anybody regardless of skills level in my opinion. Well done! &amp;amp; cheers!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 21:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520580#M141185</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-11T21:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets unique values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520598#M141195</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input my1:$2. my2:$2. clm drg tin;
datalines;
aa bb 1 2 3
bb cc 2 3 4
dd ee 3 4 5
ff gg 4 5 6
hh ii 6 7 8
;

run;

data b;
input cust1:$2. cust2:$2. clm drg tin;
datalines;
aa bb 1 2 3
bb cc 2 3 4
zz xx 3 4 5
yy ww 4 5 6
hh ii 2 7 8
;

proc sql;
create table want(drop=t) as
select *
from (select *, 1 as t from a
union all
select *, 2 as t from b)
group by my1,my2,clm,drg,tin
having count(distinct t)=1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Dec 2018 22:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets-unique-values/m-p/520598#M141195</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-11T22:09:36Z</dc:date>
    </item>
  </channel>
</rss>

