<?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: How to compare dates from two datasets having same ID but multiple observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490114#M128134</link>
    <description>&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if _n_=1 then do;
if 0 then set have2;
  declare hash H (dataset:'have2(rename=(date=date1))',multidata:'y') ;
   h.definekey  ("id") ;
   h.definedata ("date1") ;
   h.definedone () ;
   call missing(date1);
   declare hash H2 (dataset:'have2(drop=no rename=(date=date2))',multidata:'y') ;
   h2.definekey  ("id",'date2') ;
   h2.defineData(all: 'y');
   h2.definedone () ;
   call missing(date2);
end;
do until(last.id);
set have1;
by id;
call missing(date2,acc);
do rc=h.find() by 0 while(rc=0);
if date&amp;gt;=date1 then date2=max(date1,date2);
rc=h.find_next();
end;
rc=h2.find(key:id,key:date2);
valid=ifc(date2=.,'N','Y');
output;
end;
format date: date9.;
drop date1 rc;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes, you have sufficient memory to have two hash tables&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Aug 2018 15:16:12 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-08-27T15:16:12Z</dc:date>
    <item>
      <title>How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489913#M128035</link>
      <description>&lt;P&gt;Dear SAS Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need your help in figuring out how to compare dates in 2 datasets having same ID for multiple observations and selecting the latest as I am bit new to SAS and still learning&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1 has 3 columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp; Date&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 4-Apr-18&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;19-May-18&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 20-Jul-18&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01-Aug-18&lt;/P&gt;&lt;P&gt;'&lt;/P&gt;&lt;P&gt;Table 2 has 3 columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp; Date&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2-May-18&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;10-Jun-18&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 15-Jul-18&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For every record in table1 with&amp;nbsp;the same ID , i need to compare the date with table2&amp;nbsp; having same ID and ensure t1.date &amp;gt;=t2.date.&lt;/P&gt;&lt;P&gt;If there multiple records satisfying the condition from table 2 then take the latest and create a column valid with values Y or N, if condition not satisfied&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g. for record 3 in table1 for ID=1 all the records from table2 satisfy the&amp;nbsp;&lt;SPAN&gt;t1.date &amp;gt;=t2.date. in this case i have to pick the 15-jul-18 against that record. and put valid flag as Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for all the help in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 15:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489913#M128035</guid>
      <dc:creator>smiles</dc:creator>
      <dc:date>2018-08-26T15:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489915#M128036</link>
      <description>&lt;P&gt;Can you post a sample of your requird output for your input sample to avoid assumptions plz&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 16:13:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489915#M128036</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-26T16:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489917#M128037</link>
      <description>&lt;P&gt;The desired output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1 with additional columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp; Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t2.date&amp;nbsp; &amp;nbsp; &amp;nbsp; valid&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 4-Apr-18&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;19-May-18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2-May&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 20-Jul-18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15-Jul&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 01-Aug-18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15-Jul&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 16:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489917#M128037</guid>
      <dc:creator>smiles</dc:creator>
      <dc:date>2018-08-26T16:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489920#M128039</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

 data have1;
 input ID   No    Date :date9.;
 format date date9.;
cards;
1     1      4-Apr-18
1     2     19-May-18
1     3      20-Jul-18
1     4       01-Aug-18
;

data have2;
input ID   No    Date :date9.;
 format date date9.;
 cards;
1     1      2-May-18
1     2     10-Jun-18
1     3      15-Jul-18
;

proc sql;
create table want as
select distinct a.id, a.date as date1,ifn(a.date &amp;gt;=b.date,b.date,.) as date2	format =date9.,
case when calculated date2=. then 'N' else 'Y' end as valid
from have1 a, have2 b
where a.id=b.id
group by a.id,a.date 
having date2=max(date2);

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Aug 2018 17:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489920#M128039</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-26T17:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489940#M128051</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data have1;
 input ID   No    Date :date9.;
 format date date9.;
cards;
1     1      4-Apr-18
1     2     19-May-18
1     3      20-Jul-18
1     4       01-Aug-18
;

data have2;
input ID   No    Date :date9.;
 format date date9.;
 cards;
1     1      2-May-18
1     2     10-Jun-18
1     3      15-Jul-18
;
data want;
if _n_=1 then do;
if 0 then set have2;
  declare hash H (dataset:'have2(rename=(date=date1))',multidata:'y') ;
   h.definekey  ("id") ;
   h.definedata ("date1") ;
   h.definedone () ;
   call missing(date1);
end;
do until(last.id);
set have1;
by id;
call missing(date2);
do rc=h.find() by 0 while(rc=0);
if date&amp;gt;=date1 then date2=max(date1,date2);
rc=h.find_next();
end;
valid=ifc(date2=.,'N','Y');
output;
end;
format date: date9.;
drop date1 rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Aug 2018 23:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489940#M128051</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-26T23:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489990#M128072</link>
      <description>&lt;P&gt;Thanks for the quick help. It works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have started&amp;nbsp;reading about the hash object to understand how it actually works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One quick question, if the table2 has additional columns and I want the same in output as well&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have2;.&amp;nbsp;&lt;BR /&gt;input ID No Acc Date :date9.;&lt;BR /&gt;format date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 123 2-May-18&lt;BR /&gt;1 2 456 10-Jun-18&lt;BR /&gt;1 3 789 15-Jul-18&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified h.definedata (all='Y') ;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting 789 as ACC for all cases. After getting date2 , I need to get the ACC associated with that date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;No&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;ACC&lt;/TD&gt;&lt;TD&gt;Date&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;date2&lt;/TD&gt;&lt;TD&gt;valid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;4-Apr-18&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;19-May-18&lt;/TD&gt;&lt;TD&gt;2-May-18&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;20-Jul-18&lt;/TD&gt;&lt;TD&gt;15-Jul-18&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;1-Aug-18&lt;/TD&gt;&lt;TD&gt;15-Jul-18&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead of&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;No&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;ACC&lt;/TD&gt;&lt;TD&gt;Date&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;date2&lt;/TD&gt;&lt;TD&gt;valid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;4-Apr-18&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;19-May-18&lt;/TD&gt;&lt;TD&gt;2-May-18&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;20-Jul-18&lt;/TD&gt;&lt;TD&gt;15-Jul-18&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;1-Aug-18&lt;/TD&gt;&lt;TD&gt;15-Jul-18&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 07:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/489990#M128072</guid>
      <dc:creator>smiles</dc:creator>
      <dc:date>2018-08-27T07:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490027#M128094</link>
      <description>&lt;P&gt;That's simple. Can you plz post your complete modified sample or that's the best representative. Just making sure coz I can modify all in one shot&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 11:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490027#M128094</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-27T11:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490030#M128095</link>
      <description>That's it. This is the case.&lt;BR /&gt;&lt;BR /&gt;Really appreciate your help. I am beginner so getting to learn . Thanks&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Aug 2018 11:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490030#M128095</guid>
      <dc:creator>smiles</dc:creator>
      <dc:date>2018-08-27T11:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490104#M128128</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/228468"&gt;@smiles&lt;/a&gt;&amp;nbsp; Good morning,Welcome to SAS forum and my apologies for the delay. Obviously, I am sure you understand the time difference impact between locations where we login from. Messaging you&amp;nbsp;@ chicago time 9:10am with train/bus delays having just made it to my lab and this is my second post for the day. Earlier, I basically acknowledged your message while waking up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here you go:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
 input ID   No    Date :date9.;
 format date date9.;
cards;
1     1      4-Apr-18
1     2     19-May-18
1     3      20-Jul-18
1     4       01-Aug-18
;


data have2;
input ID No Acc Date :date9.;
format date date9.;
cards;
1 1 123 2-May-18
1 2 456 10-Jun-18
1 3 789 15-Jul-18
;

data want;
if _n_=1 then do;
if 0 then set have2;
  declare hash H (dataset:'have2(drop=no rename=(date=date1))',multidata:'y',ordered:'y') ;
   h.definekey  ("id") ;
  h.defineData(all: 'y');;
   h.definedone () ;
   call missing(date1);
end;

do until(last.id);
set have1;
by id;
call missing(date2);
do rc=h.find() by 0 while(rc=0);
if date&amp;gt;=date1 then date2=max(date1,date2);
rc=h.find_next();
end;
if date2 eq . then call missing(acc);
else
do rc=h.find() by 0 while(rc=0);
if date2=date1 then leave;
rc=h.find_next();
end;
valid=ifc(date2=.,'N','Y');
output;
end;
format date: date9.;
drop date1 rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some NOTES:&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;if date2 eq . then call missing(acc);&amp;nbsp; This assumes you have one additional var, however if you have a very wide have2 and you wanna use all:y in definedata you may not know to group all that needs to be part of the call missing(var1,var2--varn).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Call missing(a--z) can work if you know sequence of your definedata&lt;/P&gt;
&lt;P&gt;2. No. variable overwrites have1 No. variable during the lookup, therefore I dropped that out of the hash table to maintain sequence order of have1 as is. Of course, you can reassign sequence, learning that No in have2 will overwrite, however there's no point&lt;/P&gt;
&lt;P&gt;3. The more clear and best representative your sample is, the better to think through the robust solutions&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Feel free to have any follow up questions, if you may.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 14:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490104#M128128</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-27T14:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490114#M128134</link>
      <description>&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if _n_=1 then do;
if 0 then set have2;
  declare hash H (dataset:'have2(rename=(date=date1))',multidata:'y') ;
   h.definekey  ("id") ;
   h.definedata ("date1") ;
   h.definedone () ;
   call missing(date1);
   declare hash H2 (dataset:'have2(drop=no rename=(date=date2))',multidata:'y') ;
   h2.definekey  ("id",'date2') ;
   h2.defineData(all: 'y');
   h2.definedone () ;
   call missing(date2);
end;
do until(last.id);
set have1;
by id;
call missing(date2,acc);
do rc=h.find() by 0 while(rc=0);
if date&amp;gt;=date1 then date2=max(date1,date2);
rc=h.find_next();
end;
rc=h2.find(key:id,key:date2);
valid=ifc(date2=.,'N','Y');
output;
end;
format date: date9.;
drop date1 rc;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes, you have sufficient memory to have two hash tables&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 15:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490114#M128134</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-27T15:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates from two datasets having same ID but multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490510#M128337</link>
      <description>Thanks a lot!! Your fixed the problem in such a jiffy which I have been struggling with</description>
      <pubDate>Tue, 28 Aug 2018 15:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-dates-from-two-datasets-having-same-ID-but/m-p/490510#M128337</guid>
      <dc:creator>smiles</dc:creator>
      <dc:date>2018-08-28T15:11:14Z</dc:date>
    </item>
  </channel>
</rss>

