<?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: Code to compare how many account_id in one dataset are in another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591530#M169467</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data account_1;
input account_id $;
datalines;
1
2
3
4
5
6
7
8
;

data account_2;
input account_id $;
datalines;
14
5
1
2
99
98
93
;

proc sort data=account_1;
by account_id;
run;

proc sort data=account_2;
by account_id;
run;

data account_match account_no_match;
merge account_1 (in=a)
	  account_2 (in=b);
by account_id;
if a and b then output account_match;
else if a and not b then output account_no_match;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Not sure if this is what you're trying to get at.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Sep 2019 13:56:34 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2019-09-25T13:56:34Z</dc:date>
    <item>
      <title>Code to compare how many account_id in one dataset are in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591442#M169415</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one dataset (dataset 1) with 10,000 observations and another dataset (dataset 2) with 150,000 observations. What code could be used so that &lt;U&gt;&lt;STRONG&gt;two output datasets&lt;/STRONG&gt;&lt;/U&gt; are created when comparing account_id between two datasets?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. In one output dataset (&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;account_match&lt;/STRONG&gt;&lt;/FONT&gt;) to be created, there is a &lt;STRONG&gt;list of all of the account_id&lt;/STRONG&gt; (and &lt;STRONG&gt;also select all of the corresponding variables associated with that account_id in the output dataset&lt;/STRONG&gt;) from dataset 1 that are &lt;STRONG&gt;also in&lt;/STRONG&gt; dataset 2 (i.e. where there the &lt;STRONG&gt;account_id in dataset 1&lt;/STRONG&gt;&amp;nbsp;is &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;U&gt;also in &lt;/U&gt;&lt;/FONT&gt;dataset 2&lt;/STRONG&gt;)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. The second output dataset to be created, &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;account_no_match&lt;/STRONG&gt;&lt;/FONT&gt;, would output &lt;STRONG&gt;all of the account_id in dataset 1&lt;/STRONG&gt; that are &lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt; &lt;/U&gt;&lt;/FONT&gt;seen in dataset 2 (and &lt;STRONG&gt;also select all of the corresponding variables associated with that account_id in the output dataset&lt;/STRONG&gt;) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a result, number of accounts in &lt;STRONG&gt;account_match&lt;/STRONG&gt; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;+&lt;/STRONG&gt; &lt;/FONT&gt;number of accounts in &lt;STRONG&gt;account_no_match&lt;/STRONG&gt; = &lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;10,000 observations&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt; (i.e. dataset 1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Code:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;data account_match account_no_match;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;[insert code here]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 13:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591442#M169415</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-09-25T13:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Code to compare how many account_id in one dataset are in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591530#M169467</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data account_1;
input account_id $;
datalines;
1
2
3
4
5
6
7
8
;

data account_2;
input account_id $;
datalines;
14
5
1
2
99
98
93
;

proc sort data=account_1;
by account_id;
run;

proc sort data=account_2;
by account_id;
run;

data account_match account_no_match;
merge account_1 (in=a)
	  account_2 (in=b);
by account_id;
if a and b then output account_match;
else if a and not b then output account_no_match;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Not sure if this is what you're trying to get at.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 13:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591530#M169467</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2019-09-25T13:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Code to compare how many account_id in one dataset are in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591535#M169469</link>
      <description>Thanks a lot!</description>
      <pubDate>Wed, 25 Sep 2019 14:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591535#M169469</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-09-25T14:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Code to compare how many account_id in one dataset are in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591543#M169473</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266226"&gt;@jeremy4&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here two other options how to do this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data account_1;
  input account_id $;
  some_other_var=_n_;
  datalines;
1
2
3
4
5
6
7
8
;

data account_2;
  input account_id $;
  datalines;
14
5
1
2
99
98
93
;

/* options 1 */
data match no_match;
  if _n_=1 then 
    do;
      dcl hash h1(dataset:'account_2(keep=account_id)');
      h1.defineKey('account_id');
      h1.defineDone();
    end;
  set account_1;
  if h1.check()=0 then output match;
  else output no_match;
run;

/* option 2 */
proc sql;
  create table match_noMatch as
    select 
      t1.*,
      case when missing(t2.account_id) then '0' else '1' end as match_flg
    from 
      account_1 as t1
      left join
      (select distinct account_id from account_2) as t2
      on t1.account_id=t2.account_id
    ;
quit;

      &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Sep 2019 14:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591543#M169473</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-25T14:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Code to compare how many account_id in one dataset are in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591571#M169483</link>
      <description>&lt;P&gt;If I &lt;STRONG&gt;only wanted variables&lt;/STRONG&gt; from dataset "&lt;STRONG&gt;account_1&lt;/STRONG&gt;" to be included in &lt;STRONG&gt;&lt;U&gt;both&lt;/U&gt; output datasets&lt;/STRONG&gt; (account_match and account_no_match), how could I change your code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; account_match account_no_match&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;merge&lt;/SPAN&gt; account_1 &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
	  account_2 &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; account_id&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; a and b &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; output account_match&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; a and &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; b &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; output account_no_match&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 15:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591571#M169483</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-09-25T15:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Code to compare how many account_id in one dataset are in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591577#M169488</link>
      <description>&lt;P&gt;You want the same results for both data sets? That's how I'm reading your question. If so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data account_match account_no_match;
merge account_1 (in=a)
	  account_2 (in=b);
by account_id;
if a and b then output account_match account_no_match;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I don't think this is what you're trying to convey though. You should post a snapshot of your data.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 15:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591577#M169488</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2019-09-25T15:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Code to compare how many account_id in one dataset are in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591698#M169554</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266226"&gt;@jeremy4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If I &lt;STRONG&gt;only wanted variables&lt;/STRONG&gt; from dataset "&lt;STRONG&gt;account_1&lt;/STRONG&gt;" to be included in &lt;STRONG&gt;&lt;U&gt;both&lt;/U&gt; output datasets&lt;/STRONG&gt; (account_match and account_no_match), how could I change your code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; account_match account_no_match&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;merge&lt;/SPAN&gt; account_1 &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
	  account_2 &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; account_id&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; a and b &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; output account_match&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; a and &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; b &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; output account_no_match&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only read account_id from table account_2.&lt;/P&gt;
&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;....&lt;BR /&gt;account_2 &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b keep=account_id&lt;SPAN class="token punctuation"&gt;);&lt;/SPAN&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 20:41:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Code-to-compare-how-many-account-id-in-one-dataset-are-in/m-p/591698#M169554</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-25T20:41:16Z</dc:date>
    </item>
  </channel>
</rss>

