<?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: matching variable from another file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264974#M52036</link>
    <description>&lt;P&gt;Yes. This indeed is much simpler and better. I like it. Thank you.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Apr 2016 01:28:04 GMT</pubDate>
    <dc:creator>fengyuwuzu</dc:creator>
    <dc:date>2016-04-20T01:28:04Z</dc:date>
    <item>
      <title>matching variable from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264935#M52028</link>
      <description>&lt;P&gt;I have two data sets, setA and setB. Both have ID column. I want to add one more column in setA, called "In_setB", that when the ID is found in set B, In_setB = "Yes"; when there is no such a match, In_setB = "No".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only way I can do it, is using merge and IN options, like codes below. It works, but I wonder if others have simpler solutions. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data setA;
input ID $ amount;
datalines;
001 150
002 200
003 100
004 160
005 180
006 220
;
run;

data setB;
input ID $ amount;
datalines;
002 230
004 180
005 200
007 190
009 210
;
run;

/* I want to have want like this:
ID Amount In_setB
001 150 No
002 200	Yes
003 100	No	
004 160 Yes
005 180 Yes
006 220 No
*/

data want;
merge setA(IN=A) setB(IN=B);
by ID;
If A and B then In_setB = "Yes"; 
if A and not B then In_setB = "No"; 
If not A and B then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 22:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264935#M52028</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-04-19T22:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: matching variable from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264942#M52030</link>
      <description>&lt;P&gt;If this were my data I would do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge setA(IN=A) setB(IN=B);
by ID;
If A ;
In_SetB = B;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have a custom format that will display 1 as Yes and 0 as No when needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I prefer the numeric coding for Yes/No because I can dump the variable into procedures like Tabulate, Report or Means. The N= number of records, mean = percent yes, sum=number yes.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 22:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264942#M52030</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-19T22:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: matching variable from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264972#M52035</link>
      <description>&lt;P&gt;If you want to avoid sorting the tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
set setA;
if _N_=1 then do;
  dcl hash B (dataset:'setB');
  B.definekey('ID');
  B.definedone();
end;
In_setB =^B.check();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Apr 2016 01:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264972#M52035</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-04-20T01:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: matching variable from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264974#M52036</link>
      <description>&lt;P&gt;Yes. This indeed is much simpler and better. I like it. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2016 01:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264974#M52036</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-04-20T01:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: matching variable from another file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264975#M52037</link>
      <description>Thank you, Chris! I am not familiar with definekey, but I will take a look and learn about it. Thanks!</description>
      <pubDate>Wed, 20 Apr 2016 01:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-variable-from-another-file/m-p/264975#M52037</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-04-20T01:30:19Z</dc:date>
    </item>
  </channel>
</rss>

