<?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: The hash left join using the  _N_=0 trick does produce unexpected results. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-hash-left-join-using-the-N-0-trick-does-produce-unexpected/m-p/462343#M117705</link>
    <description>&lt;P&gt;That's a characteristic of DATA steps in general, not of hashing in particular.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any variable that comes from a SAS data set is automatically retained.&amp;nbsp; Doesn't matter whether the SAS data set is mentioned in a SET vs. MERGE vs. UPDATE statement ... if the source is a SAS data set, the variable is retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when the SET statement appears, all variables from RightData are automatically retained.&amp;nbsp; The rest of it (when it happens, how to handle) it looks like you have figured out.&lt;/P&gt;</description>
    <pubDate>Tue, 15 May 2018 13:23:22 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-05-15T13:23:22Z</dc:date>
    <item>
      <title>The hash left join using the  _N_=0 trick does produce unexpected results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-hash-left-join-using-the-N-0-trick-does-produce-unexpected/m-p/462334#M117701</link>
      <description>&lt;P&gt;The behavior of the hash left join using the&amp;nbsp; _N_=0 trick does produce unexpected results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hleftjoin;
  IF _N_=0 THEN SET RightData;
 IF _N_=1 THEN DO;
  declare hash lookupdata;
                lookupdata = _new_ hash(dataset:"RightData", ordered:"yes");
		lookupdata.defineKey('Key1','Key2');
		lookupdata.defineData('leftCol1','leftCol2');
		lookupdata.defineDone();
END;
SET LEftData end=EOF_daily;
	rc = lookupdata.find(KEY: Key1, KEY: Key2);
	
				
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;produces for Key1 and Key2 data in LeftData with a rc value greater than 0 (ie not found in RightData) non-missing leftCol1 and LeftCol2 data. It seems to put the last leftCol1 &amp;amp;2 values in it. This can be easyly taken care of with a IF rc ne 0 THEN Call missing(LeftCol1, LeftCol2). It doesn't help to put a CALL MISSING right after the hash declaration (_N_=1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However this doesn't occur when instead of the _N_=0 trick you use the LENGTH statement (LENGHT LeftCol1 LeftCol2 &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; or FORMAT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot make sense of it and this is error is not easly found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 12:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-hash-left-join-using-the-N-0-trick-does-produce-unexpected/m-p/462334#M117701</guid>
      <dc:creator>niemannk</dc:creator>
      <dc:date>2018-05-15T12:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: The hash left join using the  _N_=0 trick does produce unexpected results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-hash-left-join-using-the-N-0-trick-does-produce-unexpected/m-p/462343#M117705</link>
      <description>&lt;P&gt;That's a characteristic of DATA steps in general, not of hashing in particular.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any variable that comes from a SAS data set is automatically retained.&amp;nbsp; Doesn't matter whether the SAS data set is mentioned in a SET vs. MERGE vs. UPDATE statement ... if the source is a SAS data set, the variable is retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when the SET statement appears, all variables from RightData are automatically retained.&amp;nbsp; The rest of it (when it happens, how to handle) it looks like you have figured out.&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 13:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-hash-left-join-using-the-N-0-trick-does-produce-unexpected/m-p/462343#M117705</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-15T13:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: The hash left join using the  _N_=0 trick does produce unexpected results.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-hash-left-join-using-the-N-0-trick-does-produce-unexpected/m-p/462352#M117708</link>
      <description>ok. eventhough there is the  never true_N_=0 if statement it still initiliazes the variables and then retains it until it gets overwritten. And this behaviour is not "activated" when using the LENGTH statement, because there is no SET.</description>
      <pubDate>Tue, 15 May 2018 13:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-hash-left-join-using-the-N-0-trick-does-produce-unexpected/m-p/462352#M117708</guid>
      <dc:creator>niemannk</dc:creator>
      <dc:date>2018-05-15T13:53:17Z</dc:date>
    </item>
  </channel>
</rss>

