<?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 output both matching and non-matching account_id for two datasets in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591583#M76008</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data in1 in2 matched;

merge t1(in=in_t1) t2(in=in_t2);
by account_id;&lt;BR /&gt;
if in_t1 and not in_t2 then output in1;
else if in_t2 and not in_t1 then output in2;
else output matched;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use a MERGE and IN data set option to control the output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IN1 - all records only in T1 dataset&lt;/P&gt;
&lt;P&gt;IN2 - all records only in the T2 dataset&lt;/P&gt;
&lt;P&gt;MATCHED - records in both T1 and T2 datasets&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: fixed per&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;comment&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=ledsoptsref&amp;amp;docsetTarget=n1p1o2dsuc465nn198ovwdrj9mvy.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=ledsoptsref&amp;amp;docsetTarget=n1p1o2dsuc465nn198ovwdrj9mvy.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&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;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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;U&gt;&lt;STRONG&gt;two output datasets&lt;/STRONG&gt;&lt;/U&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;list of all of the account_id&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;also in&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;dataset 2 (i.e. where there the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_id in dataset 1&lt;/STRONG&gt;&amp;nbsp;is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;U&gt;also in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;account_no_match&lt;/STRONG&gt;&lt;/FONT&gt;, would output&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;all of the account_id in dataset 1&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_match&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;+&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;number of accounts in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_no_match&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;10,000 observations&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Sep 2019 15:41:12 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-09-25T15:41:12Z</dc:date>
    <item>
      <title>Code to output both matching and non-matching account_id for two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591499#M76002</link>
      <description>&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;U&gt;&lt;STRONG&gt;two output datasets&lt;/STRONG&gt;&lt;/U&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;list of all of the account_id&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;also in&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;dataset 2 (i.e. where there the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_id in dataset 1&lt;/STRONG&gt;&amp;nbsp;is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;U&gt;also in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;account_no_match&lt;/STRONG&gt;&lt;/FONT&gt;, would output&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;all of the account_id in dataset 1&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_match&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;+&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;number of accounts in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_no_match&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;10,000 observations&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&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;</description>
      <pubDate>Wed, 25 Sep 2019 13:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591499#M76002</guid>
      <dc:creator>jeremy4</dc:creator>
      <dc:date>2019-09-25T13:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Code to output both matching and non-matching account_id for two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591583#M76008</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data in1 in2 matched;

merge t1(in=in_t1) t2(in=in_t2);
by account_id;&lt;BR /&gt;
if in_t1 and not in_t2 then output in1;
else if in_t2 and not in_t1 then output in2;
else output matched;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use a MERGE and IN data set option to control the output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IN1 - all records only in T1 dataset&lt;/P&gt;
&lt;P&gt;IN2 - all records only in the T2 dataset&lt;/P&gt;
&lt;P&gt;MATCHED - records in both T1 and T2 datasets&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: fixed per&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;comment&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=ledsoptsref&amp;amp;docsetTarget=n1p1o2dsuc465nn198ovwdrj9mvy.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=ledsoptsref&amp;amp;docsetTarget=n1p1o2dsuc465nn198ovwdrj9mvy.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&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;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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;U&gt;&lt;STRONG&gt;two output datasets&lt;/STRONG&gt;&lt;/U&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;list of all of the account_id&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;also in&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;dataset 2 (i.e. where there the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_id in dataset 1&lt;/STRONG&gt;&amp;nbsp;is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;U&gt;also in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;account_no_match&lt;/STRONG&gt;&lt;/FONT&gt;, would output&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;all of the account_id in dataset 1&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_match&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;+&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;number of accounts in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;account_no_match&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;10,000 observations&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 15:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591583#M76008</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-25T15:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Code to output both matching and non-matching account_id for two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591589#M76010</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by account_id;&amp;nbsp; ?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 15:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591589#M76010</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-09-25T15:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Code to output both matching and non-matching account_id for two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591591#M76011</link>
      <description>Thanks, fixed!</description>
      <pubDate>Wed, 25 Sep 2019 15:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591591#M76011</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-25T15:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Code to output both matching and non-matching account_id for two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591600#M76013</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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several other ways to solve your problem. It is known as "Table Lookup" problem. The simplest way for a beginner is what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;has given.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the data type of 'account_id'? Is it a Number or Character. If it is Number, use of Array might be the fastest way for your problem.&lt;/P&gt;
&lt;P&gt;Please let us know.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 15:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Code-to-output-both-matching-and-non-matching-account-id-for-two/m-p/591600#M76013</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-09-25T15:58:56Z</dc:date>
    </item>
  </channel>
</rss>

