<?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 Comparing tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-tables/m-p/566608#M159266</link>
    <description>&lt;P&gt;Hi SAS experts,&lt;/P&gt;&lt;P&gt;Currently, I have two datasets. dataset1 has two columns, ID and svcdate, with duplicate ID. Dataset2 has two columns, ID and admdate, with no duplicates. I want to see whether the ID in dataset2 appears in dataset1. If it does appear, I want count how many times the admdate is bigger than svcdate for those IDs. How can I achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are two sample datasets:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	input svcdate : mmddyy10. id @@;
	format svcdate mmddyy10.;
	cards;
04/11/2008 1 03/29/2008 1 07/22/2008 1
03/05/2008 2 11/15/2008 2 01/04/2008 2
01/07/2008 3 04/05/2008 3 06/06/2008 3
;
run;

data test2;
	input admdate : mmddyy10. id @@;
	format admdate mmddyy10.;
	cards;
05/01/2008 1
08/01/2008 2
07/01/2008 3
;
run;

proc sort data=test1;
	by id svcdate;
run;

proc sort data=test2;
	by id admdate;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jun 2019 15:10:42 GMT</pubDate>
    <dc:creator>Xing</dc:creator>
    <dc:date>2019-06-17T15:10:42Z</dc:date>
    <item>
      <title>Comparing tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-tables/m-p/566608#M159266</link>
      <description>&lt;P&gt;Hi SAS experts,&lt;/P&gt;&lt;P&gt;Currently, I have two datasets. dataset1 has two columns, ID and svcdate, with duplicate ID. Dataset2 has two columns, ID and admdate, with no duplicates. I want to see whether the ID in dataset2 appears in dataset1. If it does appear, I want count how many times the admdate is bigger than svcdate for those IDs. How can I achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are two sample datasets:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	input svcdate : mmddyy10. id @@;
	format svcdate mmddyy10.;
	cards;
04/11/2008 1 03/29/2008 1 07/22/2008 1
03/05/2008 2 11/15/2008 2 01/04/2008 2
01/07/2008 3 04/05/2008 3 06/06/2008 3
;
run;

data test2;
	input admdate : mmddyy10. id @@;
	format admdate mmddyy10.;
	cards;
05/01/2008 1
08/01/2008 2
07/01/2008 3
;
run;

proc sort data=test1;
	by id svcdate;
run;

proc sort data=test2;
	by id admdate;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 15:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-tables/m-p/566608#M159266</guid>
      <dc:creator>Xing</dc:creator>
      <dc:date>2019-06-17T15:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-tables/m-p/566626#M159275</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test3;
merge test1 test2(in=a);
 by id;
  if a;
 visits=admdate GT svcdate;
 if visits;
run;
proc summary nway;
class id;
 var visits;
  output out=totals (drop=_:)
  sum=;
 run;
 proc print label;
   label visits="admdate GT svcdate";
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jun 2019 15:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-tables/m-p/566626#M159275</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2019-06-17T15:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-tables/m-p/566628#M159276</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.WANT	AS
	SELECT
		  a.ID
		, COUNT(a.ID)	AS Count_ADM_GT

	FROM		WORK.Test1	AS a
	INNER JOIN	WORK.Test2	as b	ON a.ID=b.ID
	WHERE b.ADMDATE &amp;gt; a.svcdate
	GROUP BY a.ID
	ORDER BY a.ID;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results Generated:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Count_ADM_GT&lt;/STRONG&gt;&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;2&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;2&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;3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 17 Jun 2019 15:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-tables/m-p/566628#M159276</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-17T15:54:35Z</dc:date>
    </item>
  </channel>
</rss>

