<?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: Hash table: same key value to subset and output multiple data tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602315#M174363</link>
    <description>&lt;P&gt;You are absolutely right. Thank you.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Nov 2019 04:47:08 GMT</pubDate>
    <dc:creator>windlove</dc:creator>
    <dc:date>2019-11-07T04:47:08Z</dc:date>
    <item>
      <title>Hash table: same key value to subset and output multiple data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602307#M174358</link>
      <description>&lt;P&gt;I have a lookup table to be used for multiple datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I use hash table method to perform subset and output for each of them in the same step?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have experimented the following, but clearly it is not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data outA outB;
	
    if 0 then set lookup(keep=ppn);
    if _n_ = 1 then do;
        declare hash hash(dataset: 'lookup(keep=ppn)');&lt;BR /&gt;                hash.defineKey('ppn');
                hash.defineDone();
    end;

    do until(last);
        set tableA end = last;
        if ~hash.find() then output outA;
    end;

    do until(last);
	set tableB end = last;
	if ~hash.find() then output outB;
    end;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 03:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602307#M174358</guid>
      <dc:creator>windlove</dc:creator>
      <dc:date>2019-11-07T03:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Hash table: same key value to subset and output multiple data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602312#M174360</link>
      <description>&lt;P&gt;The main thing is to reset variable LAST before the 2nd do-while loop.&lt;/P&gt;
&lt;P&gt;I would use the check() method because you don't need to read the value from the hash table into the PDV. You just want to check for existence.&lt;/P&gt;
&lt;P&gt;I've never seen the ~ used in front of the hash reference. It appears to work but can you explain to me what's that for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here your code amended - inclusive a few cosmetic changes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tableA tableB lookup;
  set sashelp.class;
  ppn=name;
  output tableA;
  output tableB;

  if _n_&amp;lt;4 then
    output lookup;
run;

data outA outB;
  if 0 then set lookup(keep=ppn);

  declare hash h1(dataset: 'lookup(keep=ppn)');
  h1.defineKey('ppn');
  h1.defineDone();

  do until(last);
    set tableA end = last;
    if h1.check()=0 then output outA;
  end;

  last=0;
  do until(last);
    set tableB end = last;
    if h1.check()=0 then output outB;
  end;

  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Nov 2019 04:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602312#M174360</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-07T04:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Hash table: same key value to subset and output multiple data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602313#M174361</link>
      <description>&lt;P&gt;Thanks Patrick.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"~hash.check" is the same as "hash.check = 0".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I learnt when someone taught me hash table method for the first time. Then got used to it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your solution partially worked. But both data were merged.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway I can prevent them from merging?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 04:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602313#M174361</guid>
      <dc:creator>windlove</dc:creator>
      <dc:date>2019-11-07T04:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Hash table: same key value to subset and output multiple data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602314#M174362</link>
      <description>&lt;P&gt;What do you mean by merging?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's certainly not merging rows but it will add all the variables from the source tables to the PDV and though to the target tables. You can use a data set KEEP option to prevent this from happening.&lt;/P&gt;
&lt;PRE&gt;data outA(keep=&amp;lt;variable list&amp;gt;) outB(keep=&amp;lt;variable list&amp;gt;);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 04:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602314#M174362</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-07T04:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Hash table: same key value to subset and output multiple data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602315#M174363</link>
      <description>&lt;P&gt;You are absolutely right. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 04:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602315#M174363</guid>
      <dc:creator>windlove</dc:creator>
      <dc:date>2019-11-07T04:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Hash table: same key value to subset and output multiple data tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602354#M174388</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I've never seen the ~ used in front of the hash reference. It appears to work but can you explain to me what's that for?&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's just one of the (operating system dependent) symbols for the &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p00iah2thp63bmn1lt20esag14lh.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n19ojrq5dkxpd6n14egp2a3oz0up" target="_blank" rel="noopener"&gt;logical operator&lt;/A&gt; NOT, by no means specific to hash object syntax. (Strangely enough, the linked documentation seems to contain a typo: ° instead of ^ as it's correctly listed in &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=n1bhfu7h99wzgwn1md27dqxx4b5y.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n04dt1vkbery59n1bu28kzvp5z5a" target="_blank" rel="noopener"&gt;WHERE syntax&lt;/A&gt;.)&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 10:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-table-same-key-value-to-subset-and-output-multiple-data/m-p/602354#M174388</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-07T10:22:31Z</dc:date>
    </item>
  </channel>
</rss>

