<?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: many-to-many left outer join with hash table question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356288#M83531</link>
    <description>&lt;P&gt;I reckon I can add an array for all the variables from lkup and then call missing using the array.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;array lkup {*} var1 -- var3;
...
call missing (of lkup {*});
...
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;However, this is not ideal as I still have to define the first and last variables manually.&amp;nbsp; Better solutions are welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2017 09:55:21 GMT</pubDate>
    <dc:creator>J_CKY</dc:creator>
    <dc:date>2017-05-05T09:55:21Z</dc:date>
    <item>
      <title>many-to-many left outer join with hash table question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356285#M83530</link>
      <description>&lt;P&gt;I was trying to do a many-to-many hash join.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;use sashelp.class as base table, I added extra row to get a data set with duplicated Name:&lt;/P&gt;
&lt;PRE&gt;data work.class;
set sashelp.class end=eof;
if eof then do;
  Name = 'Alice'  ;
  Sex='F'  ;
  age=20  ;
  height=60  ;
  weight=159 ;
end;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, I created a lookup table:&lt;/P&gt;
&lt;PRE&gt;data work.lkup;
input name $ Var1 Var2;
datalines;
Alice  12  54
Jack   13  56
James  4   6
Alice  37  25
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I managed to created a left join by using the following code:&lt;/P&gt;
&lt;PRE&gt;data work.test;
set work.class;

if _N_ =1 then do;
  if 0 then set lkup;
  declare hash h(dataset: 'lkup', hashExp:16 , multidata: 'y');
  h.defineKey('name');;
  h.defineData(all:'y');
  h.defineDone();
end;

if h.find() then do;
  &lt;STRONG&gt;call missing (of _all_);&lt;/STRONG&gt;
output;
end;
if not h.find();output;
if not h.find_next();output;

run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but the bolded call missing statement clear out all of the variable, both data from class and lkup.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So instead of manually using the following code to clear out non-matched results&lt;/P&gt;
&lt;PRE&gt;call missing (var1 var2);&lt;/PRE&gt;
&lt;P&gt;is there any other way I can call missing var1 and var2 easily? (I am trying to apply the logic by using a lookup table with lots of variables.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 09:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356285#M83530</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-05-05T09:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many left outer join with hash table question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356288#M83531</link>
      <description>&lt;P&gt;I reckon I can add an array for all the variables from lkup and then call missing using the array.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;array lkup {*} var1 -- var3;
...
call missing (of lkup {*});
...
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;However, this is not ideal as I still have to define the first and last variables manually.&amp;nbsp; Better solutions are welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 09:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356288#M83531</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-05-05T09:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many left outer join with hash table question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356291#M83533</link>
      <description>I also noticed that the &lt;BR /&gt;&lt;BR /&gt;if not h.find_next(); output; &lt;BR /&gt;&lt;BR /&gt;only return the 2nd result (if any) then, the 3rd result will be missed (if any);&lt;BR /&gt;&lt;BR /&gt;what's the solution to this?</description>
      <pubDate>Fri, 05 May 2017 10:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356291#M83533</guid>
      <dc:creator>J_CKY</dc:creator>
      <dc:date>2017-05-05T10:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many left outer join with hash table question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356314#M83550</link>
      <description>&lt;P&gt;This should meet your req:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; work.test;&lt;/P&gt;&lt;P&gt;set work.class;&lt;/P&gt;&lt;P&gt;if _N_ =&lt;STRONG&gt;1&lt;/STRONG&gt; then do;&lt;/P&gt;&lt;P&gt;if &lt;STRONG&gt;0&lt;/STRONG&gt; then&amp;nbsp; set lkup;&lt;/P&gt;&lt;P&gt;declare hash h(dataset: 'lkup', hashExp:&lt;STRONG&gt;16&lt;/STRONG&gt; , multidata: 'y');&lt;/P&gt;&lt;P&gt;h.defineKey('name');;&lt;/P&gt;&lt;P&gt;h.defineData(all:'y');&lt;/P&gt;&lt;P&gt;h.defineDone();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;rc = h.find();&lt;/P&gt;&lt;P&gt;if rc ne &lt;STRONG&gt;0&lt;/STRONG&gt; then output;&lt;/P&gt;&lt;P&gt;if (rc = &lt;STRONG&gt;0&lt;/STRONG&gt;) then do;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;rc = h.find_next();&lt;/P&gt;&lt;P&gt;do while(rc = &lt;STRONG&gt;0&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;rc = h.find_next();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;call missing(of v: );&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop rc;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 11:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356314#M83550</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-05-05T11:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many left outer join with hash table question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356357#M83563</link>
      <description>&lt;P&gt;Technically, this will not work anyway since you can't mix numeric and character variables in the same array. &amp;nbsp;However, you can define two arrays, as long as you do it in the proper spot within the program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array nums {*} _numeric_;&lt;/P&gt;
&lt;P&gt;array chars {*} _character_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The array statements must be placed early in the program. &amp;nbsp;Just before the initial SET statement, you can insert:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if 5=4 then do;. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set lkup;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;** both array statements;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way, their definition will be limited to the variables in the lookup data set. &amp;nbsp;You will need two call missings later (one for nums{*} and one for chars{*}), and your program may still fail for a data set that contains only one type of variable.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356357#M83563</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-05T13:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many left outer join with hash table question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356482#M83592</link>
      <description>&lt;P&gt;The technique is to take advantage of how SAS builds the program data vector.&amp;nbsp; In the program below, the &lt;EM&gt;&lt;STRONG&gt;italic-bold&lt;/STRONG&gt;&lt;/EM&gt; syntax assures that variables from LKUP are between variables _pre and _post.&amp;nbsp; Then the modified call missing works as you apparently intend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: any var that is on BOTH class and LKUP will not be set to missing, since its position in the PDV will be to the left of _pre.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data work.test &lt;EM&gt;&lt;STRONG&gt;(drop=_pre _post)&lt;/STRONG&gt;&lt;/EM&gt;;&lt;BR /&gt;set work.class;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;retain _pre .;&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;if _N_ =1 then do;&lt;BR /&gt;&amp;nbsp; if 0 then set lkup;&lt;BR /&gt;&amp;nbsp; declare hash h(dataset: 'lkup', hashExp:16 , multidata: 'y');&lt;BR /&gt;&amp;nbsp; h.defineKey('name');;&lt;BR /&gt;&amp;nbsp; h.defineData(all:'y');&lt;BR /&gt;&amp;nbsp; h.defineDone();&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;retain _post .;&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;if h.find() then do;&lt;BR /&gt;&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;call missing (of _pre -- _post);&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;if not h.find();output;&lt;BR /&gt;if not h.find_next();output;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 17:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356482#M83592</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-05T17:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many left outer join with hash table question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356525#M83601</link>
      <description>&lt;P&gt;In addition to my suggestion of building the program data vector to make &lt;EM&gt;&lt;STRONG&gt;call missing(of _pre -- _post)&lt;/STRONG&gt;&lt;/EM&gt; work as intended, I suggest you modify the code below,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if h.find() then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;call missing (of _pre--_post_);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not h.find();output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not h.find_next();output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;call missing (of _pre--_post_);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=h.find();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;do rc=h.find_next() by 0 while (rc=0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rc=h.find_next();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; It reduces the number of explicit output statments, and it accomodates cases in which a key value occurs more than twice.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 19:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-left-outer-join-with-hash-table-question/m-p/356525#M83601</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-05T19:39:29Z</dc:date>
    </item>
  </channel>
</rss>

