<?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: Soft Method to compare two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315069#M68670</link>
    <description>&lt;PRE&gt;
Check PROC COMPARE 's ID statement.


&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Nov 2016 03:18:52 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-11-29T03:18:52Z</dc:date>
    <item>
      <title>Soft Method to compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/314983#M68659</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;
&lt;P&gt;Please, I need a soft method to compare two datasets.&lt;/P&gt;
&lt;P&gt;The idea, is to loop on the lines of first table, if the line in table 1 is the same in table 2, we keep the obs number , if not 0&lt;/P&gt;
&lt;P&gt;I know that, we can use compare proc, but this, this proc will compare&amp;nbsp; the observers by order (first with first, so on ..) . But&amp;nbsp; I do not want that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc compare base=t1 comp=t2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that, we can use proc sort to sort the the tables by _all_ and then using compare , but I do not want that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=ti out ti;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by _all_;&lt;/P&gt;
&lt;P&gt;run&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;INPUT&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 300pt;" width="400" cellspacing="0" cellpadding="0" border="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 60pt;" width="80" span="5" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD style="height: 12.75pt; width: 60pt;" width="80" height="17"&gt;T1&lt;/TD&gt;
&lt;TD style="width: 60pt;" width="80"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD style="width: 60pt;" width="80"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD style="width: 60pt;" width="80"&gt;T2&lt;/TD&gt;
&lt;TD style="width: 60pt;" width="80"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt;" height="17"&gt;Id&lt;/TD&gt;
&lt;TD class="xl24" style="border-left: none;"&gt;Name&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl24"&gt;Id&lt;/TD&gt;
&lt;TD class="xl24" style="border-left: none;"&gt;Name&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; border-top: none;" height="17" align="right"&gt;1&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;Bob&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none;" align="right"&gt;4&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;bonde&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; border-top: none;" height="17" align="right"&gt;2&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;sausan&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none;" align="right"&gt;2&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;sausan&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; border-top: none;" height="17" align="right"&gt;3&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;Petter&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none;" align="right"&gt;1&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;Bob&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; border-top: none;" height="17" align="right"&gt;4&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;bonde&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 180pt;" width="240" cellspacing="0" cellpadding="0" border="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 60pt;" width="80" span="3" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; width: 60pt;" width="80" height="17"&gt;Id&lt;/TD&gt;
&lt;TD class="xl24" style="border-left: none; width: 60pt;" width="80"&gt;Name&lt;/TD&gt;
&lt;TD class="xl24" style="border-left: none; width: 60pt;" width="80"&gt;Obs_IN_T2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; border-top: none;" height="17" align="right"&gt;1&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;Bob&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;" align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; border-top: none;" height="17" align="right"&gt;2&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;sausan&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;" align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; border-top: none;" height="17" align="right"&gt;3&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;Petter&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;" align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD class="xl24" style="height: 12.75pt; border-top: none;" height="17" align="right"&gt;4&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;"&gt;bonde&lt;/TD&gt;
&lt;TD class="xl24" style="border-top: none; border-left: none;" align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 28 Nov 2016 22:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/314983#M68659</guid>
      <dc:creator>LineMoon</dc:creator>
      <dc:date>2016-11-28T22:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Soft Method to compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315003#M68663</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T1 ;
input Id 	Name $;
cards;	
1 	Bob 	
2 	sausan 	
3 	Petter 	  
4 	bonde
;

data T2;
input Id  Name $;
row=_n_;
cards;     
4   bonde      
2   sausan     
1   Bob  
;   
   
   
proc sort data =t1;
by id;
run;

proc sort data =t2;
by id;
run;

option missing=0;
data t1t2;
merge t1 t2;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Nov 2016 23:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315003#M68663</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-11-28T23:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Soft Method to compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315069#M68670</link>
      <description>&lt;PRE&gt;
Check PROC COMPARE 's ID statement.


&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2016 03:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315069#M68670</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-29T03:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Soft Method to compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315073#M68671</link>
      <description>&lt;P&gt;You can do it, but you might need a lot of code to determine when you have a match. &amp;nbsp;To illustrate, I'll use the name variable that you provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set t1;&lt;/P&gt;
&lt;P&gt;do _n_=1 to _nobs_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set t2 (rename=(name=name2)) point=_n_ nobs=_nobs_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if name=name2 then obs_in_T2=_n_;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if obs_in_T2=. then obs_in_T2=0;&lt;/P&gt;
&lt;P&gt;drop name2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is feasible with a small number of variables, but very clumsy with a lot of variables. &amp;nbsp;But it can be done.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 03:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315073#M68671</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-29T03:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Soft Method to compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315110#M68680</link>
      <description>&lt;P&gt;Thank you all for your answers &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;That's very kind from you.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;: I need this method for a lots of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 07:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315110#M68680</guid>
      <dc:creator>LineMoon</dc:creator>
      <dc:date>2016-11-29T07:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Soft Method to compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315127#M68692</link>
      <description>&lt;P&gt;How about HASH?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the key - ID or Name or both?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a solution where you can have the key in whatever way you want. You said you want to use with several variables? Do you mean the key as a combination of variables? In that case hash solution is easy. If T2 is a very large file, then you include just the varaibles of interest into the hash table using KEEP/DROP to minimize the size of the hash table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T1 ;
input id    Name $;
cards;   
1  Bob   
2  sausan   
3  Petter     
4  bonde
;
run;
data T2;
input id  Name $;
cards;     
4   bonde      
2   sausan     
1   Bob  
;   
run;

data want;
   if _n_ = 1 then do;
      if 0 then set t2;
      declare hash h();
      h.definekey('id');
      h.definedata('rowid');
      h.definedone();

      do rowid = 1 by 1 until(last);
         set t2 end = last;
         h.add();
      end;
   end;
   set t1;
   if h.find() ^= 0 then rowid = 0;
run;

proc print data = want;
run;

If the key is 'NAME', replace H.DEFINEKY('ID') by
h.definekey('Name');

If ID and NAME are the composite key then use
h.dfinekey('id','Name');

All other statements remain the same.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2016 09:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315127#M68692</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-11-29T09:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Soft Method to compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315343#M68757</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17813"&gt;@KachiM﻿&lt;/a&gt;: Thank you for your answer...good idea&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 21:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Soft-Method-to-compare-two-datasets/m-p/315343#M68757</guid>
      <dc:creator>LineMoon</dc:creator>
      <dc:date>2016-11-29T21:25:07Z</dc:date>
    </item>
  </channel>
</rss>

