<?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: Compare two datasets using Hash and update values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478855#M71414</link>
    <description>&lt;P&gt;Just for fun, swapping hash obj&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if _n_=1 then do;
if 0 then set a;
 dcl hash H (dataset:'b',ordered: "A") ;
   h.definekey  ("id","name") ;
   h.definedata ("id","name") ;
   h.definedone () ;
   dcl hiter i('h');
 end;
 set a end=last;
 if h.find()=0 then do; call missing(ind);h.remove();end;
 output;
 if last then do;
 rc = i.first();
 do while (rc = 0);
  ind=today();
  output;
  rc = i.next();
 end;
 end;
 drop rc;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 17 Jul 2018 22:12:29 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-07-17T22:12:29Z</dc:date>
    <item>
      <title>Compare two datasets using Hash and update values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478848#M71411</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 datasets which I need to compare multiple ways and update values in one column. I have datasets&amp;nbsp;A &amp;amp; B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question 1&lt;/P&gt;&lt;P&gt;I need to compare set B with A using Hash and if there are i&lt;U&gt;dentical values&lt;/U&gt; then for those rows I need to delete the Ind. value in 3rd column. I only need to delete the date filed in 3rd column but still keep the row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question&amp;nbsp;2&lt;/P&gt;&lt;P&gt;I need to compare set B with A using Hash and if there are&amp;nbsp;&lt;U&gt;NEW values&lt;/U&gt; in Set B then I need to add them to Set A and add todays date to 3rd column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Work.A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Name&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Ind.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Lin&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;6/15/2018&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Fin&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;7/15/2018&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Min&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;7/15/2018&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;4&l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>
      <pubDate>Tue, 17 Jul 2018 21:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478848#M71411</guid>
      <dc:creator>jpm2478</dc:creator>
      <dc:date>2018-07-17T21:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two datasets using Hash and update values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478852#M71412</link>
      <description>&lt;P&gt;See if this matches your expected output, or let me know&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input Id	Name $	Ind mmddyy10.;
format ind mmddyy10.;
cards; 
1	Lin	6/15/2018
2	Fin	7/15/2018
3	Min	7/15/2018
4	Tin	6/15/2018
;
 
data b;
input	Id	Name $	;
cards; 
1	Lin
8	Fin
5	Min
4	Tin
10	Quin
;

data _null_;
if _n_=1 then do;
if 0 then set a;
 dcl hash H (dataset:'a',ordered: "A") ;
   h.definekey  ("id","name") ;
   h.definedata ("id","name","Ind") ;
   h.definedone () ;
 end;
 set b end=last;
 if h.find()=0 then do; call missing(ind);h.replace();end;
 else do;ind=today();h.replace();end;
 if last then h.output(dataset:'want');
 run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2018 21:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478852#M71412</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-17T21:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two datasets using Hash and update values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478855#M71414</link>
      <description>&lt;P&gt;Just for fun, swapping hash obj&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if _n_=1 then do;
if 0 then set a;
 dcl hash H (dataset:'b',ordered: "A") ;
   h.definekey  ("id","name") ;
   h.definedata ("id","name") ;
   h.definedone () ;
   dcl hiter i('h');
 end;
 set a end=last;
 if h.find()=0 then do; call missing(ind);h.remove();end;
 output;
 if last then do;
 rc = i.first();
 do while (rc = 0);
  ind=today();
  output;
  rc = i.next();
 end;
 end;
 drop rc;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2018 22:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478855#M71414</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-17T22:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two datasets using Hash and update values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478856#M71415</link>
      <description>Can you please explain these two lines....&lt;BR /&gt;if h.find()=0 then do; call missing(ind);h.replace();end;&lt;BR /&gt;else do;ind=today();h.replace();end;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jul 2018 22:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478856#M71415</guid>
      <dc:creator>jpm2478</dc:creator>
      <dc:date>2018-07-17T22:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two datasets using Hash and update values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478858#M71416</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if h.find()=0 then do; call missing(ind);h.replace();end;&lt;EM&gt; /*This does your 1st requirement ---if there are i&lt;U&gt;dentical values&lt;/U&gt;&amp;nbsp;then for those rows I need to delete the Ind. value in 3rd column,find the matches, call missing assigns nulls to the date value and loads back in the hash using replace*/&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;else do;ind=today();h.replace();end;&lt;EM&gt;/* this one does your 2nd req--if there are&amp;nbsp;&lt;U&gt;NEW values&lt;/U&gt;&amp;nbsp;in Set B then I need to add them to Set A and add todays date to 3rd column and loads back using replace*/&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 22:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478858#M71416</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-17T22:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two datasets using Hash and update values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478862#M71417</link>
      <description>&lt;P&gt;And a non-hash solution that I think works since no example output was provided...&lt;/P&gt;
&lt;PRE&gt;data a;
input Id	Name $	Ind :mmddyy10.;
format ind mmddyy10.;
cards; 
1	Lin	6/15/2018
2	Fin	7/15/2018
3	Min	7/15/2018
4	Tin	6/15/2018
;
run; 
data b;
input	Id	Name $	;
ind=.;
cards; 
1	Lin
8	Fin
5	Min
4	Tin
10	Quin
;
run;
proc sort data=a;
  by id Name;
run;
proc sort data=b;
   by id Name;
run;

data a;
  update a (in=ina) b (in=inb) updatemode=nomissingcheck;
  by id Name;
  if inb and not ina then ind=today();

run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2018 22:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/478862#M71417</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-17T22:50:05Z</dc:date>
    </item>
  </channel>
</rss>

