<?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 Hash Table - Flag when ID variable in both datasets, using two columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-Table-Flag-when-ID-variable-in-both-datasets-using-two/m-p/638017#M189721</link>
    <description>&lt;P&gt;I have two datasets:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA List_ID;
     INPUT ID;
DATALINES;
1
2
3
4
;
DATA Flag_ID;
    INPUT ID1 ID2;
DATALINES;
1, 5 
2, 3
6, 4
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am trying to create a flag if the IDs in Flag_ID appear in List_ID, adding two new columns to Flag_ID (FlagID1 FLAGID2). I used hash table to do this when flagging one ID variable, with the same name:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FlagOne;
  if _N_ = 1 then do;  
    declare hash TST(dataset: "List_ID"); 
    TST.definekey("id1"); /*Pretending the ID variable is ID1 to match the other variable */
    TST.definedone();
  end; 
  set Flag_ID
  	ID1_Flag= (TST.check() = 0);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I do a similar operation using two variables and creating two new flags? My desired output is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID1 ID2 FlagID1 FlagID2&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;</description>
    <pubDate>Tue, 07 Apr 2020 11:07:53 GMT</pubDate>
    <dc:creator>MB_Analyst</dc:creator>
    <dc:date>2020-04-07T11:07:53Z</dc:date>
    <item>
      <title>Hash Table - Flag when ID variable in both datasets, using two columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Table-Flag-when-ID-variable-in-both-datasets-using-two/m-p/638017#M189721</link>
      <description>&lt;P&gt;I have two datasets:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA List_ID;
     INPUT ID;
DATALINES;
1
2
3
4
;
DATA Flag_ID;
    INPUT ID1 ID2;
DATALINES;
1, 5 
2, 3
6, 4
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am trying to create a flag if the IDs in Flag_ID appear in List_ID, adding two new columns to Flag_ID (FlagID1 FLAGID2). I used hash table to do this when flagging one ID variable, with the same name:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FlagOne;
  if _N_ = 1 then do;  
    declare hash TST(dataset: "List_ID"); 
    TST.definekey("id1"); /*Pretending the ID variable is ID1 to match the other variable */
    TST.definedone();
  end; 
  set Flag_ID
  	ID1_Flag= (TST.check() = 0);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I do a similar operation using two variables and creating two new flags? My desired output is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID1 ID2 FlagID1 FlagID2&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 11:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Table-Flag-when-ID-variable-in-both-datasets-using-two/m-p/638017#M189721</guid>
      <dc:creator>MB_Analyst</dc:creator>
      <dc:date>2020-04-07T11:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Table - Flag when ID variable in both datasets, using two columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Table-Flag-when-ID-variable-in-both-datasets-using-two/m-p/638020#M189723</link>
      <description>&lt;P&gt;You need to use the key: argument to the check method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FlagOne;
  if _N_ = 1 then do;
    declare hash TST(dataset: "List_ID");
    TST.definekey("id");
    TST.definedone();
  end;
  set Flag_ID;
  ID1_Flag = (TST.check(key:ID1) = 0);
  ID2_Flag = (TST.check(key:ID2) = 0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Apr 2020 11:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Table-Flag-when-ID-variable-in-both-datasets-using-two/m-p/638020#M189723</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-07T11:24:25Z</dc:date>
    </item>
  </channel>
</rss>

