<?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: comparing variables in two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82497#M17794</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of course, like ballardw suggested, proc compare will give you whole-9-yard comparison. But if what you want is just variable names, here is an another approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data h1;&lt;/P&gt;&lt;P&gt;set sashelp.class;&lt;/P&gt;&lt;P&gt;rename age=h1_age;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data h2;&lt;/P&gt;&lt;P&gt;set h1;&lt;/P&gt;&lt;P&gt;rename h1_age=h2_age;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data=h1 out=h1out (keep=name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc contents data=h2 out=h2out(keep=name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=h1out;&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=h2out;&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data common h1only h2only;&lt;/P&gt;&lt;P&gt;merge h1out(in=h1) h2out(in=h2);&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;if h1 and h2 then output common;&lt;/P&gt;&lt;P&gt;else if h1 and not h2 then output h1only;&lt;/P&gt;&lt;P&gt;else output h2only;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Aug 2012 17:36:54 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2012-08-02T17:36:54Z</dc:date>
    <item>
      <title>comparing variables in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82494#M17791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Scenario: I have two datasets: A and B. I would to know which variables they have in common, which variables are in A but not in B and vice versa. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question: If you know any handy SAS program to accomplish this task, please share with me.&lt;/P&gt;&lt;P&gt;&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>Thu, 02 Aug 2012 17:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82494#M17791</guid>
      <dc:creator>aha123</dc:creator>
      <dc:date>2012-08-02T17:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: comparing variables in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82495#M17792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Proc compare.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basic syntax Proc compare base=&amp;lt;datasetname&amp;gt; compare=&amp;lt;datasetname&amp;gt;; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 17:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82495#M17792</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-08-02T17:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: comparing variables in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82496#M17793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is one way, although I'm sure there are many:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*create some test data*/&lt;/P&gt;&lt;P&gt;data have1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain x y z (0,0,0);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data have2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain a b c (0,0,0);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table names1 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="WORK" and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memname="HAVE1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by name&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table names2 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="WORK" and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memname="HAVE2"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by name&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge names1 (in=in1) names2 (in=in2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by name;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if in1 and in2 then type="in both";&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if in1 then type="in 1";&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if in2 then type="in 2";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=want;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 17:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82496#M17793</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-08-02T17:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: comparing variables in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82497#M17794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of course, like ballardw suggested, proc compare will give you whole-9-yard comparison. But if what you want is just variable names, here is an another approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data h1;&lt;/P&gt;&lt;P&gt;set sashelp.class;&lt;/P&gt;&lt;P&gt;rename age=h1_age;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data h2;&lt;/P&gt;&lt;P&gt;set h1;&lt;/P&gt;&lt;P&gt;rename h1_age=h2_age;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data=h1 out=h1out (keep=name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc contents data=h2 out=h2out(keep=name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=h1out;&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=h2out;&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data common h1only h2only;&lt;/P&gt;&lt;P&gt;merge h1out(in=h1) h2out(in=h2);&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;if h1 and h2 then output common;&lt;/P&gt;&lt;P&gt;else if h1 and not h2 then output h1only;&lt;/P&gt;&lt;P&gt;else output h2only;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 17:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82497#M17794</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-08-02T17:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: comparing variables in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82498#M17795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a variation you may like.&amp;nbsp; Extending an earlier suggestion:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc compare data=data1 (obs=0) compare=data2 (obs=0);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That way, you get all the structural differences (not just variable names) but you don't get all the detail about which data values are different.&amp;nbsp; For example, if the same variable name appears in both data sets, but is defined as character in one but numeric in the other, you may want to know that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 17:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82498#M17795</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-08-02T17:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: comparing variables in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82499#M17796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have1;
&amp;nbsp; set sashelp.class;
&amp;nbsp; retain x y z (0,0,0);
run;

data have2;
&amp;nbsp; set sashelp.class;
&amp;nbsp; retain a b c (0,0,0);
run;

proc sql;
create table common_var as
 select name from dictionary.columns where libname='WORK' and memname='HAVE1'
 intersect
 select name from dictionary.columns where libname='WORK' and memname='HAVE2';

create table in_a as
 select name from dictionary.columns where libname='WORK' and memname='HAVE1'
 except
 select name from dictionary.columns where libname='WORK' and memname='HAVE2';

create table in_b as
 select name from dictionary.columns where libname='WORK' and memname='HAVE2'
 except
 select name from dictionary.columns where libname='WORK' and memname='HAVE1';

 quit;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 04:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82499#M17796</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-08-03T04:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: comparing variables in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82500#M17797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My favorite approach is also SQL/Dictionary Tables , but for the sake of variety, one could also use the approach below, again relying on Proc Contents:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc contents data=sashelp.class (keep=weight age sex) out=X (keep=name) noprint;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;proc contents data=sashelp.class (rename=(name=tag weight=mass)) out=Y (keep=name) noprint;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data XnotinY YnotinX;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _N_=1 then do;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash hx (dataset:"X");&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hx.definekey("name");&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hx.definedata("name");&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hx.definedone();&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash hy (dataset:"Y");&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hy.definekey("name");&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hy.definedata("name");&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hy.definedone();&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do until(xdone);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set X end=xdone;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if hy.check() ne 0 then output XnotinY;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(name);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do until(ydone);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set Y end=ydone;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if hx.check() ne 0 then output YnotinX;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(name);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 16:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/82500#M17797</guid>
      <dc:creator>joehinson</dc:creator>
      <dc:date>2012-08-03T16:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: comparing variables in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/854354#M337638</link>
      <description>&lt;P&gt;Great, works for me, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 15:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-variables-in-two-datasets/m-p/854354#M337638</guid>
      <dc:creator>dikang77</dc:creator>
      <dc:date>2023-01-18T15:22:45Z</dc:date>
    </item>
  </channel>
</rss>

