<?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 tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271957#M54098</link>
    <description>&lt;P&gt;If you post test data (form of a datastep) for each and what the output should look like we can provide code. &amp;nbsp;What happens for instance if there are multiple examples of KEY? &amp;nbsp;What is a "correct" value? &amp;nbsp;Its sounds like the best solution, based on what you provided is the datastep with update setup.&lt;/P&gt;</description>
    <pubDate>Fri, 20 May 2016 12:32:40 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-05-20T12:32:40Z</dc:date>
    <item>
      <title>hash tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271942#M54093</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've searched for a solution but I didn't find it.&amp;nbsp; Hopefully someone can give me some advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an input_table which contains a KEY variable (unique value) with 1 data variable "variable_to_be_corrected".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on another table, tableX, (which will be the hash table) I want to lookup the KEY and correct the variable "variable_to_be_corrected"&amp;nbsp; based on the value for the variable 'correction' in the hash table tableX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I manage this correctly?&amp;nbsp; I thought the find method could be used here, but I can't make it work.&lt;/P&gt;
&lt;P&gt;The last line of code&amp;nbsp; doesn't work, which I indicated in the code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;

if _n_=1 then do; 
	
  if 0 then set tableX;
  declare hash o(dataset:'tableX');
  o.definekey('KEY');
  o.defineData('correction');
  o.definedone();

end;

set input_table;

if o.check(key:KEY)=0 then variable_to_be_corrected = o.find('correction') ; /* &amp;lt;-- ERROR HERE */&lt;BR /&gt;run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&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>Fri, 20 May 2016 11:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271942#M54093</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2016-05-20T11:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: hash tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271946#M54094</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The hash does not work like this. I think you shall start by reading some useful papers, for example:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings10/151-2010.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings10/151-2010.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/forum2008/029-2008.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/forum2008/029-2008.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/236-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/236-30.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 11:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271946#M54094</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-05-20T11:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: hash tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271948#M54095</link>
      <description>&lt;P&gt;You can do such updating in a couple of different ways:&lt;/P&gt;
&lt;P&gt;- Datastep with update statement&lt;/P&gt;
&lt;P&gt;- Datastep with if then construct&lt;/P&gt;
&lt;P&gt;Or SQL (just an example as no test datstep provided):&lt;/P&gt;
&lt;PRE&gt;proc sql;
  update DATA_TO_BE_UPDATED
  set VARIABLE=xyz
  where  &amp;lt;condition&amp;gt;;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 May 2016 11:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271948#M54095</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-20T11:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: hash tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271955#M54097</link>
      <description>&lt;P&gt;Thank you both for your feedback.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I wanted to realise is to correct some observations in table A based on observations in table B in a datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table A:&lt;/P&gt;
&lt;P&gt;KEY&lt;/P&gt;
&lt;P&gt;variable_A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table B:&lt;/P&gt;
&lt;P&gt;KEY&lt;/P&gt;
&lt;P&gt;variable_A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table A contains mostly correct values for variable A, but sometimes not.&lt;/P&gt;
&lt;P&gt;For each value in table A, my program has to look if there is an occurance in table B (based on KEY), and if so, it has to update the value from variable_A in table A with the value from variable_A in table B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I understand, hash tables is not the best approach.&lt;/P&gt;
&lt;P&gt;I was looking for a solution using a data step, but maybe with a proc SQL, it will be easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 12:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271955#M54097</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2016-05-20T12:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: hash tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271957#M54098</link>
      <description>&lt;P&gt;If you post test data (form of a datastep) for each and what the output should look like we can provide code. &amp;nbsp;What happens for instance if there are multiple examples of KEY? &amp;nbsp;What is a "correct" value? &amp;nbsp;Its sounds like the best solution, based on what you provided is the datastep with update setup.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 12:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271957#M54098</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-20T12:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: hash tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271963#M54100</link>
      <description>&lt;P&gt;okay, see here some testdata:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given are the following tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- table A:&lt;/P&gt;
&lt;P&gt;KEY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Variable_A&lt;/P&gt;
&lt;P&gt;001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- table B:&lt;/P&gt;
&lt;P&gt;KEY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Variable_A&lt;/P&gt;
&lt;P&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What code would I need if I want this output:&lt;/P&gt;
&lt;P&gt;- table C:&lt;/P&gt;
&lt;P&gt;KEY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Variable_A&lt;/P&gt;
&lt;P&gt;001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table C is the same as Table A, except for the observatons that occur in table B.&lt;/P&gt;
&lt;P&gt;How could this be done in a datastep?&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 12:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271963#M54100</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2016-05-20T12:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: hash tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271970#M54101</link>
      <description>&lt;P&gt;So:&lt;/P&gt;
&lt;PRE&gt;data tablea;
  input key $ variable_a;
datalines;
001          1 
002          1
003          2
004          5
;
run;
 
data tableb;
  input key $ variable_a;
datalines;
003          3
;
run;

data want;
  update tablea tableb;
  by key;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 May 2016 13:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271970#M54101</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-20T13:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: hash tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271982#M54105</link>
      <description>&lt;P&gt;Thank you very much.&amp;nbsp; This is indeed a very simple and compact way.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 13:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/hash-tables/m-p/271982#M54105</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2016-05-20T13:43:00Z</dc:date>
    </item>
  </channel>
</rss>

