<?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 with Hash Object in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888784#M351111</link>
    <description>&lt;P&gt;Here is an example :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;data class;&lt;/DIV&gt;
&lt;DIV&gt;input Name$ Sex$ Age Height Weight;&lt;/DIV&gt;
&lt;DIV&gt;infile datalines dlm=' ' dsd;&lt;/DIV&gt;
&lt;DIV&gt;datalines;&lt;/DIV&gt;
&lt;DIV&gt;Alfred M 14 69.0 112.5&lt;/DIV&gt;
&lt;DIV&gt;Alice F 13 56.5 84.0&lt;/DIV&gt;
&lt;DIV&gt;Barbara F 13 65.3 98.0&lt;/DIV&gt;
&lt;DIV&gt;Carol F 14 62.8 102.5&lt;/DIV&gt;
&lt;DIV&gt;Henry M 14 63.5 102.5&lt;/DIV&gt;
&lt;DIV&gt;;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data cities;&lt;/DIV&gt;
&lt;DIV&gt;input zipcode City :$30. Department :$30. Persona:$10.;&lt;/DIV&gt;
&lt;DIV&gt;infile datalines dlm=',' dsd;&lt;/DIV&gt;
&lt;DIV&gt;datalines;&lt;/DIV&gt;
&lt;DIV&gt;75008, Paris 8è ,Paris,Alice&lt;/DIV&gt;
&lt;DIV&gt;91940, Les Ulis, Essonne,Carol&lt;/DIV&gt;
&lt;DIV&gt;92330,Sceaux, Hauts-de-Seine,Henry&lt;/DIV&gt;
&lt;DIV&gt;93140, Bondy , Seine-Saint-Denis,Henry&lt;/DIV&gt;
&lt;DIV&gt;94150, Rungis, Val-de-Marne,Alice&lt;/DIV&gt;
&lt;DIV&gt;;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data Set1 ;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if 0 then set class cities;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;if _n_ = 1 then do;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; declare Hash Match1 (dataset:'class');&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineKey ('Name');&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineData ('Name','Sex','Age');&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineDone ();&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;end;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;set cities;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if Match1.find(key:Persona) = 0 then output;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;What I want is an output set that contains&amp;nbsp;Name Sex Age Department! I can do it with&amp;nbsp;(keep=Name Sex Age Department), but I dont want to process this variables!&lt;/DIV&gt;
&lt;DIV&gt;Thanks&lt;/DIV&gt;</description>
    <pubDate>Thu, 10 Aug 2023 12:15:22 GMT</pubDate>
    <dc:creator>ssafmed</dc:creator>
    <dc:date>2023-08-10T12:15:22Z</dc:date>
    <item>
      <title>Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888568#M351054</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to merge 2 tables&amp;nbsp; using Hash Object by keyA and keyB that have the same values(but not the same name in the tables), but in my output I want just a few values from both tables,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example&lt;/P&gt;
&lt;P&gt;table A : keyA, Cl_A_1,&amp;nbsp; Cl_A_2, Cl_A_3, Cl_A_4, CL_A5&lt;/P&gt;
&lt;P&gt;table B : keyB,&amp;nbsp;Cl_B_1,Cl_B_2,Cl_B_3,Cl_B_4,Cl_B_5,Cl_B_6&lt;/P&gt;
&lt;P&gt;------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;Output : KeyA, keyB,&amp;nbsp;Cl_A_1,&amp;nbsp; Cl_A_2,&amp;nbsp;Cl_B_1,Cl_B_2,Cl_B_3&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 13:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888568#M351054</guid>
      <dc:creator>ssafmed</dc:creator>
      <dc:date>2023-08-09T13:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888685#M351094</link>
      <description>&lt;P&gt;Plesse provide sample data in the form of a working DATA step, and a working DATA step with the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With that clarification, we'll be able to determine a way to get from sample input to desired output, with tested code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Help us help you.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 22:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888685#M351094</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-09T22:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888698#M351097</link>
      <description>&lt;P&gt;Easiest is to just rename the key variable to what's in your base table when loading into the hash table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dcl hash h1 (dataset:'your_table(rename=(keyB=KeyA))');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;but in my output I want just a few values from both tables&lt;/EM&gt;"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to further specify what this is about AND you need to provide sample data and desired result. Please provide the sample data via a working SAS datastep that creates such data.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 23:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888698#M351097</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-09T23:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888784#M351111</link>
      <description>&lt;P&gt;Here is an example :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;data class;&lt;/DIV&gt;
&lt;DIV&gt;input Name$ Sex$ Age Height Weight;&lt;/DIV&gt;
&lt;DIV&gt;infile datalines dlm=' ' dsd;&lt;/DIV&gt;
&lt;DIV&gt;datalines;&lt;/DIV&gt;
&lt;DIV&gt;Alfred M 14 69.0 112.5&lt;/DIV&gt;
&lt;DIV&gt;Alice F 13 56.5 84.0&lt;/DIV&gt;
&lt;DIV&gt;Barbara F 13 65.3 98.0&lt;/DIV&gt;
&lt;DIV&gt;Carol F 14 62.8 102.5&lt;/DIV&gt;
&lt;DIV&gt;Henry M 14 63.5 102.5&lt;/DIV&gt;
&lt;DIV&gt;;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data cities;&lt;/DIV&gt;
&lt;DIV&gt;input zipcode City :$30. Department :$30. Persona:$10.;&lt;/DIV&gt;
&lt;DIV&gt;infile datalines dlm=',' dsd;&lt;/DIV&gt;
&lt;DIV&gt;datalines;&lt;/DIV&gt;
&lt;DIV&gt;75008, Paris 8è ,Paris,Alice&lt;/DIV&gt;
&lt;DIV&gt;91940, Les Ulis, Essonne,Carol&lt;/DIV&gt;
&lt;DIV&gt;92330,Sceaux, Hauts-de-Seine,Henry&lt;/DIV&gt;
&lt;DIV&gt;93140, Bondy , Seine-Saint-Denis,Henry&lt;/DIV&gt;
&lt;DIV&gt;94150, Rungis, Val-de-Marne,Alice&lt;/DIV&gt;
&lt;DIV&gt;;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data Set1 ;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if 0 then set class cities;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;if _n_ = 1 then do;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; declare Hash Match1 (dataset:'class');&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineKey ('Name');&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineData ('Name','Sex','Age');&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineDone ();&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;end;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;set cities;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if Match1.find(key:Persona) = 0 then output;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;What I want is an output set that contains&amp;nbsp;Name Sex Age Department! I can do it with&amp;nbsp;(keep=Name Sex Age Department), but I dont want to process this variables!&lt;/DIV&gt;
&lt;DIV&gt;Thanks&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Aug 2023 12:15:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888784#M351111</guid>
      <dc:creator>ssafmed</dc:creator>
      <dc:date>2023-08-10T12:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888815#M351128</link>
      <description>&lt;P&gt;Add these two statements to your IF N_ = 1 block:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length name $8 sex $8 age 8;
call missing(name,sex,age);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You have to tell the data step compiler about the new variables, so it can compile them into the PDV. The second statement is just there to avoid the "uninitialized" NOTE.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 16:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888815#M351128</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-10T16:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888820#M351129</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, in my output I just want de keep&amp;nbsp;Name Sex Age and department and not (zipcode, City, Persona)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I dont even want that the variables&amp;nbsp;(zipcode, City, Persona)&amp;nbsp; went to PVD&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 17:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888820#M351129</guid>
      <dc:creator>ssafmed</dc:creator>
      <dc:date>2023-08-10T17:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888826#M351132</link>
      <description>&lt;P&gt;Use either the DROP= or KEEP= dataset option in your SET statement.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 17:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888826#M351132</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-10T17:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888828#M351133</link>
      <description>&lt;P&gt;In this case it will be process in PDV, but I want to avoid that for efficiency because my data are very big!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 18:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888828#M351133</guid>
      <dc:creator>ssafmed</dc:creator>
      <dc:date>2023-08-10T18:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888838#M351141</link>
      <description>&lt;P&gt;When you exclude variables in the SET statement, which controls the&amp;nbsp;&lt;U&gt;reading&lt;/U&gt; of a dataset, those variables will&amp;nbsp;&lt;U&gt;not&lt;/U&gt; be part of the PDV. You can verify this with a PUT _ALL_; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW since the whole dataset file will be p?hysically read anyway, the number of variables in the PDV won't have an influence on processing time, only on memory used, and with so few as you describe, the effect of dropping them will be nil.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 18:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888838#M351141</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-10T18:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888844#M351147</link>
      <description>&lt;P&gt;I put a keep just after If 0 (I dont know if it is that you mean by Set reading statment)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but still processing all the variables in PVD (please see log below)&lt;/P&gt;
&lt;P&gt;Code :&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN&gt;if 0 then set class cities;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;keep Name Sex Age Persona Department;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;if _n_ = 1 then do;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; declare Hash Match1 (dataset:'class');&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineKey ('Name');&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineData ('Name','Sex','Age');&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;Match1.DefineDone ();&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;end;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;set cities ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if Match1.find(key:Persona) = 0 then output;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;PUT _ALL_;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;log :&lt;/P&gt;
&lt;DIV id="sasLogNote1_1691693778497" class="sasNote"&gt;NOTE: There were 5 observations read from the data set WORK.CLASS.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Name=Alice Sex=F Age=13 Height=. Weight=. zipcode=75008 City=Paris 8è Department=Paris Persona=Alice _ERROR_=0 _N_=1&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Name=Carol Sex=F Age=14 Height=. Weight=. zipcode=91940 City=Les Ulis Department=Essonne Persona=Carol _ERROR_=0 _N_=2&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Name=Henry Sex=M Age=14 Height=. Weight=. zipcode=92330 City=Sceaux Department=Hauts-de-Seine Persona=Henry _ERROR_=0 _N_=3&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Name=Henry Sex=M Age=14 Height=. Weight=. zipcode=93140 City=Bondy Department=Seine-Saint-Denis Persona=Henry _ERROR_=0 _N_=4&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Name=Alice Sex=F Age=13 Height=. Weight=. zipcode=94150 City=Rungis Department=Val-de-Marne Persona=Alice _ERROR_=0 _N_=5&lt;/DIV&gt;
&lt;DIV&gt;data Set1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Thanks&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Aug 2023 19:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888844#M351147</guid>
      <dc:creator>ssafmed</dc:creator>
      <dc:date>2023-08-10T19:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888847#M351148</link>
      <description>&lt;P&gt;This is a&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1nnrzzsw6rzrjn1p2jfky6pdv23.htm" target="_blank" rel="noopener"&gt;KEEP Statement&lt;/A&gt;, not a&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ledsoptsref/p0vw9lyyxk1cxkn0zzfemrsr3t9a.htm" target="_blank" rel="noopener"&gt;KEEP= Dataset Option&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 19:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888847#M351148</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-10T19:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888869#M351154</link>
      <description>&lt;P&gt;Below how I would code for this. Make sure that you load the table with the lower volume into the hash. That's from a memory consumption and performance perspective much more important than if you've got a few more variables than you would need in the PDV. As long as you only write variables to the output table that you need (drop/keep) the difference to performance is negligible.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Set1;
  if _n_ = 1 then
    do;
      if 0 then set class(keep=name sex age);
      declare Hash Match1 (dataset:'class');
      Match1.DefineKey ('Name');
      Match1.DefineData ('Name','Sex','Age');
      Match1.DefineDone ();
    end;
  call missing(of _all_);

  set cities(keep=Persona department);

  if Match1.find(key:Persona) = 0;

  /* potentially more statements */
  drop persona;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also be aware that at least in your sample data column Persona has a length of 10 but Name only a length of 8. Should the string length stored in Persona exceed 8 characters then the hash lookup will return an error like:&amp;nbsp;ERROR: Argument length greater than length of key variable Name&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 22:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888869#M351154</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-10T22:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888915#M351174</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;It's what I did but still not solve the problem!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN&gt;if 0 then set class cities;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;keep Name Sex Age Persona Department;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;if _n_ = 1 then do;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;declare Hash Match1 (dataset:'class');&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 11 Aug 2023 11:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888915#M351174</guid>
      <dc:creator>ssafmed</dc:creator>
      <dc:date>2023-08-11T11:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888960#M351185</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/196305"&gt;@ssafmed&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;It's what I did but still not solve the problem!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;SPAN&gt;if 0 then set class cities;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;keep Name Sex Age Persona Department;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;if _n_ = 1 then do;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;declare Hash Match1 (dataset:'class');&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are still using the statement instead of the dataset option. Please read the documentation I linked for you.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 15:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888960#M351185</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-11T15:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888965#M351187</link>
      <description>&lt;P&gt;Let's see what your code does:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 0 then set class cities; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since SAS will evaluate zero as FALSE the SET statement will never run.&amp;nbsp; But the data step compiler will see it and add all of the variables from both the CLASS and CITIES datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;keep Name Sex Age Persona Department;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This says to only output these 5 specific variables.&amp;nbsp; If CLASS is like SASHELP.CLASS then the first three will be defined as in CLASS and the second two will be defined as in CITIES.&amp;nbsp; If any of those five variables do not exist in either CLASS or CITIES and are not later defined explicitly or implicitly by other code in the step then SAS not create them and instead write a WARNING message to the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you meant to do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 0 then set class(keep=Name Sex Age) cities(keep=Persona Department); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the data step compile step will only add those specific 5 variables.&amp;nbsp; But you will have to also check other places where you use either CLASS or CITIES in another SET or MERGE statement to make sure that does not bring in other variables.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 16:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/888965#M351187</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-11T16:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/970250#M377052</link>
      <description>&lt;P&gt;Hi this is the answer base on others' reply and codes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
input Name$ Sex$ Age Height Weight;
datalines;
Alfred M 14 69.0 112.5
Alice F 13 56.5 84.0
Barbara F 13 65.3 98.0
Carol F 14 62.8 102.5
Henry M 14 63.5 102.5
;
run;
data cities;
input zipcode City :$30. Department :$30. Persona:$10.;
infile datalines dlm=',' dsd;
datalines;
75008, Paris 8è ,Paris,Alice
91940, Les Ulis, Essonne,Carol
92330,Sceaux, Hauts-de-Seine,Henry
93140, Bondy , Seine-Saint-Denis,Henry
94150, Rungis, Val-de-Marne,Alice
;
run;
proc print data=class;run;
proc print data=cities;run;
data set1;
   if _n_=1 then do;
      if 0 then set class(keep=name sex age);
      declare hash match1(dataset:'class');
      match1.definekey('name');
      match1.definedata('sex','age');
      match1.definedone();
   end;
   set cities(keep=persona department);
      name=persona;
      rc=match1.find(key:name);
      if rc=0;
      drop persona rc;
run;
proc print data=set1;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_2-1751652922575.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/108168i0A3667E75C5AF068/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_2-1751652922575.png" alt="dxiao2017_2-1751652922575.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_4-1751653012061.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/108170i03052A8AC0A7AA94/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_4-1751653012061.png" alt="dxiao2017_4-1751653012061.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jul 2025 18:17:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/970250#M377052</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-07-04T18:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/970253#M377053</link>
      <description>&lt;P&gt;That seems to work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The extra assignment statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name=persona;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will prevent the issue mentioned above about values of PERSONA that are longer than the 8 bytes reserved for the NAME variable used as the key in the hash object.&amp;nbsp; &amp;nbsp;The assignment operation will truncate the value to fit into the NAME variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you could have done that in the .FIND() method call and avoided the need for the assignment statement.&amp;nbsp; &amp;nbsp;If you know the length needed you could put PUT function with $ format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;match1.find(key: put(persona,$8.) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you don't then use VLENGTH() to find it and use the SUBSTRN() function to truncate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;match1.find(key:substrn(persona,1,vlength(name)))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jul 2025 22:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-Hash-Object/m-p/970253#M377053</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-04T22:11:23Z</dc:date>
    </item>
  </channel>
</rss>

