<?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 How to Compare a Merge ID Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-a-Merge-ID-Variable/m-p/972915#M377593</link>
    <description>&lt;P&gt;One of my teammates brought an issue to me that I am unable to resolve.&amp;nbsp; I hope someone here has some experience with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are trying to reconcile a clinical database with a safety database.&amp;nbsp; We have Subject ID, AE Term, and AE Start Date in both databases.&amp;nbsp; If they match, they are considered the same record, and then we can compare that other information matches (like relationship, actions taken, seriousness, etc.).&amp;nbsp; The problem is that they also want to reconcile the start date.&amp;nbsp; I don't know how we can have the start date be a key ID variable and a comparison check at the same time.&amp;nbsp; Has anyone come across this situation before?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example.&amp;nbsp; We have a subject that has the same AE on two separate occasions.&amp;nbsp; If I merge by subject, AE, and start date, they line up just fine, and there is no discrepancy detected:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table CLIN_AE (SUBJID char(11), AEDECOD char(100), AESTDAT num format=date9.);
		insert into clin_ae (subjid, aedecod, aestdat)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','19JUN2025'd);
	create table SAFE_AE (USUBJID char(11), DECOD char(100), STDTC num format=date9.);
		insert into safe_ae (usubjid, decod, stdtc)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','19JUN2025'd);

	create table compare as
		select a.*, b.*
		from clin_ae as a full join safe_ae as b
		on a.subjid=b.usubjid &amp;amp; a.aedecod=b.decod &amp;amp; a.aestdat=b.stdtc;
quit;

data compare;
	set compare;
	if aestdat^=stdtc then DISCREP='Start Dates not Matching';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, suppose that one of the dates was off by a day.&amp;nbsp; They are technically the same event, but a merge will not consider it as such.&amp;nbsp; It will still properly flag the discrepancy, but it duplicates it, and there is no way to know that they are the same event with a date discrepancy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table CLIN_AE (SUBJID char(11), AEDECOD char(100), AESTDAT num format=date9.);
		insert into clin_ae (subjid, aedecod, aestdat)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','18JUN2025'd);
	create table SAFE_AE (USUBJID char(11), DECOD char(100), STDTC num format=date9.);
		insert into safe_ae (usubjid, decod, stdtc)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','19JUN2025'd);

	create table compare as
		select a.*, b.*
		from clin_ae as a full join safe_ae as b
		on a.subjid=b.usubjid &amp;amp; a.aedecod=b.decod &amp;amp; a.aestdat=b.stdtc;
quit;

data compare;
	set compare;
	if aestdat^=stdtc then DISCREP='Start Dates not Matching';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any way to accommodate this?&amp;nbsp; I know this can't be a new problem.&amp;nbsp; I just can't imagine how to use a key ID variable as a comparison variable at the same time.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Aug 2025 20:59:33 GMT</pubDate>
    <dc:creator>djbateman</dc:creator>
    <dc:date>2025-08-19T20:59:33Z</dc:date>
    <item>
      <title>How to Compare a Merge ID Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-a-Merge-ID-Variable/m-p/972915#M377593</link>
      <description>&lt;P&gt;One of my teammates brought an issue to me that I am unable to resolve.&amp;nbsp; I hope someone here has some experience with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are trying to reconcile a clinical database with a safety database.&amp;nbsp; We have Subject ID, AE Term, and AE Start Date in both databases.&amp;nbsp; If they match, they are considered the same record, and then we can compare that other information matches (like relationship, actions taken, seriousness, etc.).&amp;nbsp; The problem is that they also want to reconcile the start date.&amp;nbsp; I don't know how we can have the start date be a key ID variable and a comparison check at the same time.&amp;nbsp; Has anyone come across this situation before?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example.&amp;nbsp; We have a subject that has the same AE on two separate occasions.&amp;nbsp; If I merge by subject, AE, and start date, they line up just fine, and there is no discrepancy detected:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table CLIN_AE (SUBJID char(11), AEDECOD char(100), AESTDAT num format=date9.);
		insert into clin_ae (subjid, aedecod, aestdat)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','19JUN2025'd);
	create table SAFE_AE (USUBJID char(11), DECOD char(100), STDTC num format=date9.);
		insert into safe_ae (usubjid, decod, stdtc)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','19JUN2025'd);

	create table compare as
		select a.*, b.*
		from clin_ae as a full join safe_ae as b
		on a.subjid=b.usubjid &amp;amp; a.aedecod=b.decod &amp;amp; a.aestdat=b.stdtc;
quit;

data compare;
	set compare;
	if aestdat^=stdtc then DISCREP='Start Dates not Matching';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, suppose that one of the dates was off by a day.&amp;nbsp; They are technically the same event, but a merge will not consider it as such.&amp;nbsp; It will still properly flag the discrepancy, but it duplicates it, and there is no way to know that they are the same event with a date discrepancy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table CLIN_AE (SUBJID char(11), AEDECOD char(100), AESTDAT num format=date9.);
		insert into clin_ae (subjid, aedecod, aestdat)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','18JUN2025'd);
	create table SAFE_AE (USUBJID char(11), DECOD char(100), STDTC num format=date9.);
		insert into safe_ae (usubjid, decod, stdtc)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','19JUN2025'd);

	create table compare as
		select a.*, b.*
		from clin_ae as a full join safe_ae as b
		on a.subjid=b.usubjid &amp;amp; a.aedecod=b.decod &amp;amp; a.aestdat=b.stdtc;
quit;

data compare;
	set compare;
	if aestdat^=stdtc then DISCREP='Start Dates not Matching';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any way to accommodate this?&amp;nbsp; I know this can't be a new problem.&amp;nbsp; I just can't imagine how to use a key ID variable as a comparison variable at the same time.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 20:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-a-Merge-ID-Variable/m-p/972915#M377593</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2025-08-19T20:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to Compare a Merge ID Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-a-Merge-ID-Variable/m-p/972927#M377595</link>
      <description>&lt;P&gt;I think you may be entering the world of fuzzy matching / fuzzy merging.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if you want to join any records&amp;nbsp; where the dates are within one day of each other, you could replace :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;on a.subjid=b.usubjid &amp;amp; a.aedecod=b.decod &amp;amp; a.aestdat=b.stdtc;&lt;/PRE&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;PRE&gt;on a.subjid=b.usubjid &amp;amp; a.aedecod=b.decod &amp;amp; abs(a.aestdat-b.stdtc)&amp;lt;=1;&lt;/PRE&gt;
&lt;P&gt;But then you might have to deal with one-to-many matches, or even many-to-many.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to think of this as a data cleaning step, where first you find all the exact matches, then look for any "off-by-one" errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you search lexjansen.com for "fuzzy match" and "fuzzy merge" you'll likely find some helpful papers.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 21:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-a-Merge-ID-Variable/m-p/972927#M377595</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-08-19T21:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to Compare a Merge ID Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-a-Merge-ID-Variable/m-p/972931#M377599</link>
      <description>&lt;P&gt;For this scenario , you could match this condition by operator BETWEEN AND.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
	create table CLIN_AE (SUBJID char(11), AEDECOD char(100), AESTDAT num format=date9.);
		insert into clin_ae (subjid, aedecod, aestdat)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','18JUN2025'd);
	create table SAFE_AE (USUBJID char(11), DECOD char(100), STDTC num format=date9.);
		insert into safe_ae (usubjid, decod, stdtc)
			values ('101-001-001','Rash','30MAY2025'd)
			values ('101-001-001','Rash','19JUN2025'd);

	create table compare as
		select a.*, b.*
		from clin_ae as a full join safe_ae as b
		on a.subjid=b.usubjid &amp;amp; a.aedecod=b.decod &amp;amp; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;b.stdtc between a.aestdat and a.aestdat+1;&lt;/STRONG&gt;&lt;/FONT&gt;
quit;

data compare;
	set compare;
	if aestdat^=stdtc then DISCREP='Start Dates not Matching';
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Aug 2025 01:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-a-Merge-ID-Variable/m-p/972931#M377599</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-08-20T01:10:28Z</dc:date>
    </item>
  </channel>
</rss>

