<?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 merge in data step mis-behaviour in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348033#M80546</link>
    <description>&lt;P&gt;Does in_set contain key1 and key2?&lt;/P&gt;
&lt;P&gt;How many observations does in_set contain, and how many are output to out_set?&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2017 09:19:46 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-04-07T09:19:46Z</dc:date>
    <item>
      <title>Hash merge in data step mis-behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348014#M80534</link>
      <description>&lt;P&gt;I have written the following code to perform a hash merge within a data-step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but the steps after the join is not porforming correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data out_set;
set in_set;

length var1 var2 8;
if _n_ =1 then do;
	declare hash h1(dataset: 'lkup_1',multidata:'y');
	rc= h1.defineKey('key1');
	rc= h1.defineData('var1');
	rc= h1.defineDone();

	declare hash h2(dataset: 'lkup_2' , multidata:'y');
	rc= h2.defineKey('key2');
	rc= h2.defineData('var2');
	rc= h2.defineDone();
end;
	rc= h1.find();
	rc= h2.find();
	output;

	do while (rc=0);
	   rc= h1.find_next();
	   rc= h2.find_next();
	   if rc = 0 then output;
	end;

	miss_flag = missing(var1);
	run;&lt;/PRE&gt;
&lt;P&gt;All of the MISS_FLAG are returning null even for obs where var1 is not missing.&amp;nbsp; Ideally, I would like to perform the follows and replace the MISS_FLAG:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;VAR = ifn(missing(VAR1), VAR2, VAR1);
drop VAR1 VAR2 rc;
&lt;/PRE&gt;
&lt;P&gt;Somehow the drop statement was working, but the step above was not. So i tried to investigate with the miss_flag variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone could point me to the right direction would be great.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 08:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348014#M80534</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-04-07T08:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Hash merge in data step mis-behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348033#M80546</link>
      <description>&lt;P&gt;Does in_set contain key1 and key2?&lt;/P&gt;
&lt;P&gt;How many observations does in_set contain, and how many are output to out_set?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 09:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348033#M80546</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-07T09:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Hash merge in data step mis-behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348034#M80547</link>
      <description>&lt;P&gt;PS It's always good to post the whole log of the step for reference (use the {i} button to open a window that allows posting with a fixed font and no HTML formatting)&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 09:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348034#M80547</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-07T09:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Hash merge in data step mis-behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348046#M80550</link>
      <description>&lt;P&gt;Regarding ".. returning null even for obs where var1 is not missing."&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Yes, probably because&lt;/P&gt;
&lt;P&gt;rc= h1.find_next();&lt;BR /&gt;rc= h2.find_next();&lt;/P&gt;
&lt;P&gt;causes the rc of h1 to be overwritten by h2. What exactly is going on, is hard to tell without data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 11:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348046#M80550</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2017-04-07T11:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Hash merge in data step mis-behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348062#M80553</link>
      <description>&lt;PRE&gt;
You have two hash table, so you need two RC.


data out_set;
set in_set;

length var1 var2 8;
if _n_ =1 then do;
	declare hash h1(dataset: 'lkup_1',multidata:'y');
	 h1.defineKey('key1');
	 h1.defineData('var1');
	 h1.defineDone();

	declare hash h2(dataset: 'lkup_2' , multidata:'y');
	 h2.defineKey('key2');
	 h2.defineData('var2');
	 h2.defineDone();
end;
call missing(var1,var2);
	rc1= h1.find();
	rc2= h2.find();
	

	do while (rc1=0 and rc2=0);
           output;
	   rc1= h1.find_next();
	   rc2= h2.find_next();
	end;

	miss_flag = missing(var1);
	run;


&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Apr 2017 12:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-merge-in-data-step-mis-behaviour/m-p/348062#M80553</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-07T12:52:33Z</dc:date>
    </item>
  </channel>
</rss>

