<?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: Merge data sets using Hash method- error due to rename problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893247#M352861</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Great great,&lt;/P&gt;
&lt;P&gt;So SAS knows to connect&amp;nbsp;Branch_Cust_Nbr with lak_id and&amp;nbsp;Branch_Nbr&amp;nbsp; with snif?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1694119522374.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87705iA97A0488EC4B633F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Ronein_0-1694119522374.png" alt="Ronein_0-1694119522374.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I also want to ask please- Is Hash method Sort the data (in the background)?&lt;/P&gt;
&lt;P&gt;What is the advantage if using this method for merging data sets?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It does not so much sort the data has put into bins to make it easier to find.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the datasets are already sorted (and why aren't they) then the fastest method is a normal data step MERGE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If one of the datasets is small enough to fit into memory than loading it into a HASH object means you do not have to sort the other (larger) dataset.&amp;nbsp; That can be doubly important if you need that dataset sorted in some other way for you later operations.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Sep 2023 04:32:00 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-09-08T04:32:00Z</dc:date>
    <item>
      <title>Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893124#M352816</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am using Hash method to merge data sets.&lt;/P&gt;
&lt;P&gt;The by variables to merge have different names.&lt;/P&gt;
&lt;P&gt;Here is the code I run that produce error.&lt;/P&gt;
&lt;P&gt;In real life data sets are very big so I don't want to rename variables of data set&amp;nbsp;&lt;CODE class=" language-sas"&gt;VBM374_USED_BRANCH_CUSTOMER.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;It&amp;nbsp;means&amp;nbsp;that&amp;nbsp;the&amp;nbsp;rename&amp;nbsp;should&amp;nbsp;be&amp;nbsp;done&amp;nbsp;during&amp;nbsp;Hash&amp;nbsp;process&amp;nbsp;and&amp;nbsp;not&amp;nbsp;before.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ABT_ALL;
input lak_id snif X y Z;
cards;
111111 987 10 20 30
222222 921 15 30 45
333333 940 20 40 60
;
Run;


Data VBM374_USED_BRANCH_CUSTOMER;
input Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP;
cards;
222222 921 123 
333333 940 456
;
run;


data ABT_ALL_b;
set ABT_ALL;
if _n_ = 1
then do;
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER");
h.definekey("Branch_Cust_Nbr","Branch_Nbr"); 
h.definedata("Numerator_DWH");
h.definedone();
if 0 then set VBM374_USED_BRANCH_CUSTOMER (keep=Branch_Cust_Nbr  Branch_Nbr first_Branch_Cust_IP rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif first_Branch_Cust_IP=Numerator_DWH));
call missing(Numerator_DWH);
end;
rc = h.find();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The error&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1                                                          The SAS System                          07:19 Thursday, September 7, 2023

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program (6)';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HTMLBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HTMLBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&amp;amp;sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         data ABT_ALL_b;
27         set ABT_ALL;
28         if _n_ = 1
29         then do;
30         declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER");
31         h.definekey("Branch_Cust_Nbr","Branch_Nbr");
32         h.definedata("Numerator_DWH");
33         h.definedone();
34         if 0 then set VBM374_USED_BRANCH_CUSTOMER (keep=Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP
34       ! rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif first_Branch_Cust_IP=Numerator_DWH));
35         call missing(Numerator_DWH);
36         end;
37         rc = h.find();
38         drop rc;
39         run;

ERROR: Undeclared key symbol Branch_Cust_Nbr for hash object at line 33 column 1.
ERROR: DATA STEP Component Object failure.  Aborted during the EXECUTION phase.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set WORK.ABT_ALL.
WARNING: The data set WORK.ABT_ALL_B may be incomplete.  When this step was stopped there were 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      user cpu time       0.01 seconds
      system cpu time     0.01 seconds
      memory              810.68k
      OS Memory           26024.00k
      Timestamp           09/07/2023 01:18:27 PM
      Step Count                        168  Switch Count  2
      Page Faults                       0
      Page Reclaims                     172
      Page Swaps                        0
2                                                          The SAS System                          07:19 Thursday, September 7, 2023

      Voluntary Context Switches        44
      Involuntary Context Switches      1
      Block Input Operations            0
      Block Output Operations           0
      

40         
41         GOPTIONS NOACCESSIBLE;
42         %LET _CLIENTTASKLABEL=;
43         %LET _CLIENTPROCESSFLOWNAME=;
44         %LET _CLIENTPROJECTPATH=;
45         %LET _CLIENTPROJECTPATHHOST=;
46         %LET _CLIENTPROJECTNAME=;
47         %LET _SASPROGRAMFILE=;
48         %LET _SASPROGRAMFILEHOST=;
49         
50         ;*';*";*/;quit;run;
51         ODS _ALL_ CLOSE;
52         
53         
54         QUIT; RUN;
55         
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 10:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893124#M352816</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-07T10:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893125#M352817</link>
      <description>&lt;P&gt;Move if 0 then set .... before declaring the hash.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 10:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893125#M352817</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-09-07T10:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893135#M352823</link>
      <description>&lt;P&gt;No work,still error&lt;/P&gt;
&lt;P&gt;ERROR: Undeclared key symbol Branch_Cust_Nbr for hash object at line 33 column 1.&lt;BR /&gt;ERROR: DATA STEP Component Object failure. Aborted during the EXECUTION phase.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ABT_ALL_b;
set ABT_ALL;
if _n_ = 1 then do;
if 0 then set VBM374_USED_BRANCH_CUSTOMER (keep=Branch_Cust_Nbr  Branch_Nbr first_Branch_Cust_IP rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif first_Branch_Cust_IP=Numerator_DWH));
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER");
h.definekey("Branch_Cust_Nbr","Branch_Nbr"); 
h.definedata("Numerator_DWH");
h.definedone();
call missing(Numerator_DWH);
end;
rc = h.find();
drop rc;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2023 11:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893135#M352823</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-07T11:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893144#M352827</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you are renaming&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;Branch_Cust_Nbr&amp;nbsp;&lt;/FONT&gt;to &lt;FONT face="courier new,courier"&gt;lak_id&lt;/FONT&gt;, but later you refer back to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Branch_Cust_Nbr&lt;/FONT&gt;. Try instead to refer to &lt;FONT face="courier new,courier"&gt;lak_id&lt;/FONT&gt;, and the same goes for any other variables you have renamed and then are referring to later.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also need to have a rename of the same variables when declaring the hash, if possible, otherwise maybe remove the rename.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Typo.&lt;/P&gt;
&lt;P&gt;Edit2: Added second suggestion.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 12:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893144#M352827</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2023-09-07T12:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893155#M352831</link>
      <description>May you please show code Amir?</description>
      <pubDate>Thu, 07 Sep 2023 12:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893155#M352831</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-07T12:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893163#M352833</link>
      <description>&lt;P&gt;You are renaming Branch_Cust_Nbr to lak_id, so you can't use Branch_Cust_Nbr as key in the hash object&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;set ... rename=(Branch_Cust_Nbr=lak_id ...&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 13:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893163#M352833</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-09-07T13:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893171#M352835</link>
      <description>&lt;P&gt;Your IF 0 THEN SET has a RENAME= dataset option, which means the variables are defined into the PDV with other names than those you use in the DEFINE methods.&lt;/P&gt;
&lt;P&gt;Use the same options in the DECLARE statement, and use the RENAMEd names in the DEFINEs.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 15:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893171#M352835</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-07T15:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893179#M352838</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope it is clear what is required now, based on the follow up from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When renaming variables for an incoming data set, e.g., &lt;FONT face="courier new,courier"&gt;old_name = new_name&lt;/FONT&gt;, you should refer to &lt;FONT face="courier new,courier"&gt;new_name&lt;/FONT&gt; in the rest of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If after making changes&amp;nbsp;&lt;SPAN&gt;you're still getting issues then please post the log showing the data step that you've tried to fix and any notes, warnings or error messages, using the Insert Code icon "&amp;lt;/&amp;gt;".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 15:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893179#M352838</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2023-09-07T15:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893184#M352839</link>
      <description>&lt;P&gt;Why all of the renames?&amp;nbsp; Just use the KEY: option on the FIND() command to tell the hash object which variables have the key.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ABT_ALL;
  input lak_id snif X y Z;
cards;
111111 987 10 20 30
222222 921 15 30 45
333333 940 20 40 60
;

data VBM374_USED_BRANCH_CUSTOMER;
  input Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP;
cards;
222222 921 123 
333333 940 456
;

data ABT_ALL_b;
  set ABT_ALL;
  if 0 then set VBM374_USED_BRANCH_CUSTOMER(keep=Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP);
  if _n_ = 1 then do;
    declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER");
    h.definekey("Branch_Cust_Nbr","Branch_Nbr"); 
    h.definedata("first_Branch_Cust_IP");
    h.definedone();
  end;
  if not h.find(key:lak_id,key:snif) then Numerator_DWH=first_Branch_Cust_IP;
  drop Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP ;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    lak_id    snif     X     y     Z    Numerator_DWH

 1     111111     987    10    20    30         .
 2     222222     921    15    30    45       123
 3     333333     940    20    40    60       456

&lt;/PRE&gt;
&lt;P&gt;If you do want to rename them then do in the DATASET: option and the DEFINEKEY() and DEFINEDATA() options.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ABT_ALL_b;
  set ABT_ALL;
  if _n_ = 1 then do;
    declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER
     (rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif
             first_Branch_Cust_IP=Numerator_DWH))"
    );
    h.definekey("lak_id","snif"); 
    h.definedata("Numerator_DWH");
    h.definedone();
  end;
  if h.find() then Numerator_DWH=.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2023 16:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893184#M352839</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-07T16:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893226#M352851</link>
      <description>But the rename was done on data set "VBM374_USED_BRANCH_CUSTOMER"  and not on data set  "ABT_ALL"  . Here you wrote the rename on data set ABT_ALL</description>
      <pubDate>Thu, 07 Sep 2023 20:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893226#M352851</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-07T20:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893228#M352852</link>
      <description>&lt;P&gt;Do you mean that in&amp;nbsp; h.definekey and h.definedata I should use the renamed columns?&lt;/P&gt;
&lt;P&gt;This code still have error&lt;/P&gt;
&lt;P&gt;ERROR: Variable lak_id is not on file WORK.VBM374_USED_BRANCH_CUSTOMER.&lt;BR /&gt;ERROR: Hash data set load failed at line 33 column 1.&lt;BR /&gt;ERROR: DATA STEP Component Object failure. Aborted during the EXECUTION phase.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
set ABT_ALL;
if _n_ = 1
then do;
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER");
h.definekey("lak_id","snif"); 
h.definedata("Numerator_DWH");
h.definedone();
if 0 then set VBM374_USED_BRANCH_CUSTOMER (keep=Branch_Cust_Nbr  Branch_Nbr first_Branch_Cust_IP
                                           rename=(Branch_Cust_Nbr=lak_id   Branch_Nbr=snif   first_Branch_Cust_IP=Numerator_DWH));
call missing(Numerator_DWH);
end;
rc = h.find();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2023 20:42:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893228#M352852</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-07T20:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893230#M352853</link>
      <description>&lt;P&gt;Great great,&lt;/P&gt;
&lt;P&gt;So SAS knows to connect&amp;nbsp;Branch_Cust_Nbr with lak_id and&amp;nbsp;Branch_Nbr&amp;nbsp; with snif?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1694119522374.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87705iA97A0488EC4B633F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1694119522374.png" alt="Ronein_0-1694119522374.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I also want to ask please- Is Hash method Sort the data (in the background)?&lt;/P&gt;
&lt;P&gt;What is the advantage if using this method for merging data sets?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 20:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893230#M352853</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-07T20:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893231#M352854</link>
      <description>&lt;P&gt;You really need to&amp;nbsp;&lt;U&gt;read&lt;/U&gt; our posts. Quote from mine:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Use the same options in the DECLARE statement&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;You simply did not do that.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Details are important in computing.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 20:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893231#M352854</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-07T20:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893247#M352861</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Great great,&lt;/P&gt;
&lt;P&gt;So SAS knows to connect&amp;nbsp;Branch_Cust_Nbr with lak_id and&amp;nbsp;Branch_Nbr&amp;nbsp; with snif?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1694119522374.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87705iA97A0488EC4B633F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Ronein_0-1694119522374.png" alt="Ronein_0-1694119522374.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I also want to ask please- Is Hash method Sort the data (in the background)?&lt;/P&gt;
&lt;P&gt;What is the advantage if using this method for merging data sets?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It does not so much sort the data has put into bins to make it easier to find.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the datasets are already sorted (and why aren't they) then the fastest method is a normal data step MERGE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If one of the datasets is small enough to fit into memory than loading it into a HASH object means you do not have to sort the other (larger) dataset.&amp;nbsp; That can be doubly important if you need that dataset sorted in some other way for you later operations.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 04:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893247#M352861</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-08T04:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893248#M352862</link>
      <description>&lt;P&gt;Thanks friends,&lt;/P&gt;
&lt;P&gt;Here is the summary of the solutions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ABT_ALL;
input lak_id snif X y Z;
cards;
111111 987 10 20 30
222222 921 15 30 45
333333 940 20 40 60
;
Run;

Data VBM374_USED_BRANCH_CUSTOMER;
input Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP;
cards;
222222 921 123 
333333 940 456
;
run;

/************Left join*****************************************/
/************Left join*****************************************/
/************Left join*****************************************/
data WAY1;
set ABT_ALL;
if _n_ = 1 then do;
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER
                       (rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif
                        first_Branch_Cust_IP=Numerator_DWH))");
h.definekey("lak_id","snif"); 
h.definedata("Numerator_DWH");
h.definedone();
end;
if h.find() then Numerator_DWH=.;
run;


data WAY2;
set ABT_ALL;
if _n_ = 1
then do;
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER
                       (rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif
                        first_Branch_Cust_IP=Numerator_DWH))");
h.definekey("lak_id","snif"); 
h.definedata("Numerator_DWH");
h.definedone();
if 0 then set VBM374_USED_BRANCH_CUSTOMER(rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif first_Branch_Cust_IP=Numerator_DWH));
call missing(Numerator_DWH);
end;
rc = h.find();
drop rc;
run;



data WAY3;
set ABT_ALL;
if 0 then set VBM374_USED_BRANCH_CUSTOMER(keep=Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP);
if _n_ = 1 then do;
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER");
h.definekey("Branch_Cust_Nbr","Branch_Nbr"); 
h.definedata("first_Branch_Cust_IP");
h.definedone();
end;
if not h.find(key:lak_id,key:snif) then Numerator_DWH=first_Branch_Cust_IP;
drop Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Sep 2023 04:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893248#M352862</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-08T04:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893249#M352863</link>
      <description>&lt;P&gt;I would like&amp;nbsp; to ask please -&lt;/P&gt;
&lt;P&gt;In each of the 3 ways of solution via Hash method - Which code is telling SAS to perform LEFT JOIN?&lt;/P&gt;
&lt;P&gt;IF I want to perform INNER JOIN-Which code need to be modified ?&lt;/P&gt;
&lt;P&gt;IF I want to perform FULL JOIN-which code need to be modified?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ABT_ALL;
input lak_id snif X y Z;
cards;
111111 987 10 20 30
222222 921 15 30 45
333333 940 20 40 60
;
Run;

Data VBM374_USED_BRANCH_CUSTOMER;
input Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP;
cards;
222222 921 123 
333333 940 456
;
run;

/************Left join*****************************************/
/************Left join*****************************************/
/************Left join*****************************************/
data WAY1;
set ABT_ALL;
if _n_ = 1 then do;
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER
                       (rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif
                        first_Branch_Cust_IP=Numerator_DWH))");
h.definekey("lak_id","snif"); 
h.definedata("Numerator_DWH");
h.definedone();
end;
if h.find() then Numerator_DWH=.;
run;


data WAY2;
set ABT_ALL;
if _n_ = 1
then do;
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER
                       (rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif
                        first_Branch_Cust_IP=Numerator_DWH))");
h.definekey("lak_id","snif"); 
h.definedata("Numerator_DWH");
h.definedone();
if 0 then set VBM374_USED_BRANCH_CUSTOMER(rename=(Branch_Cust_Nbr=lak_id Branch_Nbr=snif first_Branch_Cust_IP=Numerator_DWH));
call missing(Numerator_DWH);
end;
rc = h.find();
drop rc;
run;



data WAY3;
set ABT_ALL;
if 0 then set VBM374_USED_BRANCH_CUSTOMER(keep=Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP);
if _n_ = 1 then do;
declare hash h (dataset:"VBM374_USED_BRANCH_CUSTOMER");
h.definekey("Branch_Cust_Nbr","Branch_Nbr"); 
h.definedata("first_Branch_Cust_IP");
h.definedone();
end;
if not h.find(key:lak_id,key:snif) then Numerator_DWH=first_Branch_Cust_IP;
drop Branch_Cust_Nbr Branch_Nbr first_Branch_Cust_IP ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Sep 2023 04:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893249#M352863</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-08T04:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893251#M352864</link>
      <description>&lt;P&gt;That middle one does not need the IF 0 THEN SET statement.&lt;/P&gt;
&lt;P&gt;You are reading in only 3 variables.&amp;nbsp; 2 of them are the KEY variables so those are already defined by the SET for the non-hashed dataset.&amp;nbsp; And the third is a numeric variable, so your&amp;nbsp; use of it in the CALL MISSING() statement will define it already.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 04:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893251#M352864</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-08T04:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merge data sets using Hash method- error due to rename problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893253#M352865</link>
      <description>&lt;P&gt;Your original problem was doing a LOOKUP.&amp;nbsp; Not really any type of "JOIN".&amp;nbsp; If it wasn't for the fact that you have two key variables instead of one then you could have done that by making a FORMAT or an INFORMAT instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;None of the data steps you posted are doing what SQL calls a JOIN.&amp;nbsp; They do not handle the situation where both datasets could have multiple observations for the same set of key values.&amp;nbsp; But as long as the small dataset (the one you put into the hash) has unique observations then it is doing LEFT (or RIGHT what is the difference really) JOIN since you keep all of the observations from the main dataset and just add on the values extracted from the dataset that is stored in the hash.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To handle multiple observations for the same key values you would have to define the hash to allow that.&amp;nbsp; And then make multple calls to the .FIND() method until you no longer retrieve another observation.&amp;nbsp; So you would need to add a loop and output statement(s).&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 04:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-data-sets-using-Hash-method-error-due-to-rename-problem/m-p/893253#M352865</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-08T04:47:45Z</dc:date>
    </item>
  </channel>
</rss>

