<?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 finding overlapping patients in 2 datasets in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734796#M28636</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get a count of the distinct patients existing in two datasets. If I use proc sql and the patient numbers are the same in both datasets, they overwrite each other. Is there a proc sql query that scans 2 datasets and produces a number (in this case 3)?&amp;nbsp; Below are sample data including an example of output I'm looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current data 1&lt;/P&gt;&lt;P&gt;MRN&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current data 2&lt;/P&gt;&lt;P&gt;MRN&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MRN_both&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;</description>
    <pubDate>Fri, 16 Apr 2021 20:07:11 GMT</pubDate>
    <dc:creator>lmyers2</dc:creator>
    <dc:date>2021-04-16T20:07:11Z</dc:date>
    <item>
      <title>finding overlapping patients in 2 datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734796#M28636</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get a count of the distinct patients existing in two datasets. If I use proc sql and the patient numbers are the same in both datasets, they overwrite each other. Is there a proc sql query that scans 2 datasets and produces a number (in this case 3)?&amp;nbsp; Below are sample data including an example of output I'm looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current data 1&lt;/P&gt;&lt;P&gt;MRN&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current data 2&lt;/P&gt;&lt;P&gt;MRN&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MRN_both&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 20:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734796#M28636</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2021-04-16T20:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: finding overlapping patients in 2 datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734797#M28637</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165633"&gt;@lmyers2&lt;/a&gt;&amp;nbsp;wrote:(&lt;EM&gt;&lt;STRONG&gt;emphasis mine&lt;/STRONG&gt;&lt;/EM&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to get a count of the distinct patients existing in two datasets. If I use proc sql and the patient numbers are the same in both datasets,&lt;EM&gt;&lt;STRONG&gt; they overwrite each other&lt;/STRONG&gt;&lt;/EM&gt;. Is there a proc sql query that scans 2 datasets and produces a number (in this case 3)?&amp;nbsp; Below are sample data including an example of output I'm looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current data 1&lt;/P&gt;
&lt;P&gt;MRN&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current data 2&lt;/P&gt;
&lt;P&gt;MRN&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MRN_both&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;Laura&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;HR /&gt;
&lt;P&gt;Why is the fact that they "overwrite each other" a problem.&amp;nbsp; This means that you will get 1 observation per common MRN, which in turns means you will have only 3 observations - the number you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  create table _null_ as  select a.mrn from 
    data1 as a 
    join 
    data2 as b 
    on a.mrn=b.mrn;
quit;
%put &amp;amp;=sqlobs;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This creates table _NULL_ which is not an actual physical data set, but it does cause SQL to behave as if it were.&amp;nbsp; So there will be a count of qualifying matches in macrovar SQLOBS.&amp;nbsp; If you can an actual table, change _NULL_ to a dataset or table name.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 20:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734797#M28637</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-16T20:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: finding overlapping patients in 2 datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734816#M28638</link>
      <description>You could look at PROC COMPARE but it's a bit of an overkill.&lt;BR /&gt;&lt;BR /&gt;You could also do a SQL query. &lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want_sql as&lt;BR /&gt;select distinct t2.ID from current_data1 as t1 where t1.id in (select distinct t2.ID from current_data2 t2);&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;You could also do a data step merge.&lt;BR /&gt;&lt;BR /&gt;data want_data;&lt;BR /&gt;merge current_data1 (in=t1) and current_data2 (in=t2);&lt;BR /&gt;by ID;&lt;BR /&gt;if t1 and t2;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;The Data step approach will not work if you have duplicate IDs in either tables but the SQL one will. You could de-dup either solution after though.</description>
      <pubDate>Fri, 16 Apr 2021 21:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734816#M28638</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-16T21:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: finding overlapping patients in 2 datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734868#M28640</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
input MRN;
cards;
1
2
3
10
;
 

data data2;
input MRN;
cards;
1
2
3
4
5
;

proc sql;
create table want as
select mrn from data1
intersect
select mrn from data2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Apr 2021 10:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-overlapping-patients-in-2-datasets/m-p/734868#M28640</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-17T10:46:00Z</dc:date>
    </item>
  </channel>
</rss>

