<?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: Counter Not Working in Hash Table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237576#M43544</link>
    <description>&lt;P&gt;An inexpensive book with examples is SAS Hash Object Programming Made Easy by Michele M. Burlew.&amp;nbsp; I am not a hash expert and am just learning myself but it's been helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
    <pubDate>Thu, 03 Dec 2015 13:33:36 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2015-12-03T13:33:36Z</dc:date>
    <item>
      <title>Counter Not Working in Hash Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237561#M43541</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am trying to create a hash code, which does the following:&lt;/P&gt;
&lt;P&gt;1) A table lookup with output showing matches,&lt;/P&gt;
&lt;P&gt;2) Provide a count of the output table (duplicate and nonduplicate)&amp;nbsp;and store value into a variable,&lt;/P&gt;
&lt;P&gt;I have provided the code in proc sql format which works. THis is the output that i want.&lt;/P&gt;
&lt;P&gt;I inserted the hash code as well, for any corrections/ changes.&lt;/P&gt;
&lt;P&gt;I am really keen on learning Hash programming - would u recommend any website/ books with examples?&lt;/P&gt;
&lt;P&gt;All help would be deeply appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my proc sql code that works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sat;
  input client $;
  datalines;
531 
620
531
908
620
143
 run;

 data main;
  input keys $;
  datalines;
530 
620
532
909
620
142
 run;

proc sql;
create table duplicates as 
select keys
from main
where keys in (select distinct client from sat);
select count(1) into :dupcnt
from duplicates;
run;


proc sql;
create table nonduplicates as 
select distinct keys
from main
where keys in (select distinct client from sat);
select count(1) into :nondupcnt
from nonduplicates;
run;

%Put Duplicate count: &amp;amp;dupcnt.;
%Put nonduplicate count: &amp;amp;nondupcnt.;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My Hash code is as below: (not working)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data duplicates nonduplicates (keep=client);
if _n_=1 then
		do;
		if 0 then set sat;
			declare hash w (dataset:"work.sat");
			rc=w.definekey('client');
			rc=w.definedata('client');
			rc=w.definedone();
		  end;
set work.main;
	rc= w.find(key:keys);
	if rc eq 0 then output duplicates;
	else output nonduplicates;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;many thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Sebastian&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2015 11:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237561#M43541</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2015-12-03T11:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Not Working in Hash Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237563#M43542</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its not clear to me why you are going to all that trouble. &amp;nbsp;This will create three tables, both has matches, p_sat has those only in sat, p_main only those in p_main. &amp;nbsp;You can then run freq's and things off this data to get counts?&lt;/P&gt;
&lt;PRE&gt;data sat;
  input client $;
  datalines;
531 
620
531
908
620
143
;
run;

 data main;
  input keys $;
  datalines;
530 
620
532
909
620
142
;
run;

proc sort data=sat;  
  by client;
run;
proc sort data=main (rename=(keys=client));
  by client;
run;

data both p_sat p_main;
  merge sat (in=sat) main (in=main);
  by client;
  if sat and main then output both;
  else if sat then output p_sat;
  else output p_main;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Dec 2015 11:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237563#M43542</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-03T11:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Not Working in Hash Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237568#M43543</link>
      <description>&lt;P&gt;Thank you for your reply RW9.&lt;/P&gt;
&lt;P&gt;You are right in your post. However, I have multiple massive datasets, with require long waiting times. I could brew my coffee between each session &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;After browsing a few forums and doing a bit of reading, i found HASH tables to be a quicker solution.&lt;/P&gt;
&lt;P&gt;I also, wanted to incoporate a min() and max() function&amp;nbsp;to show the min max values of a given variable, with some further´if statements, but want to solve this one step at a time by myself, after i understand the basic code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2015 11:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237568#M43543</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2015-12-03T11:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Not Working in Hash Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237576#M43544</link>
      <description>&lt;P&gt;An inexpensive book with examples is SAS Hash Object Programming Made Easy by Michele M. Burlew.&amp;nbsp; I am not a hash expert and am just learning myself but it's been helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2015 13:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237576#M43544</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-12-03T13:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Not Working in Hash Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237635#M43562</link>
      <description>&lt;P&gt;Here are some sample code based on your data.&lt;/P&gt;
&lt;PRE&gt;data sat;
	input client $;
	datalines;
531 
620
531
908
143
 run;

data main;
	input keys $;
	datalines;
530 
620
532
909
620
142
 run;

data _null_;
	if _n_=1 then
		do;
			dcl hash sat(dataset:'work.sat(keep=client)', multidata&amp;amp;colon;'y');
			sat.definekey('client');
			sat.definedone();
			length client $ 3;
			dcl hash uni();
			uni.definekey('keys');
			uni.definedone();
		end;

	set main end=last;

	if sat.check(key:keys)=0 then
		do;
			rc=uni.check();

			if rc ne 0 then
				do;
					unique+1;
					rc=uni.add();
				end;

			duplicate+1;
		end;

	if last then
		do;
			call symputx('dupcnt',duplicate);
			call symputx('nondupcnt',unique);
		end;
run;

%Put Total Matched count: &amp;amp;dupcnt.;
%Put Total Matched Distinct count: &amp;amp;nondupcnt.;&lt;/PRE&gt;
&lt;P&gt;Notice that I have used "Total Matched&amp;nbsp;count" and "Total Matched Distinct count" at the final output. Dup or nondup is a bit confusing.&amp;nbsp;Good Luck and Happy Learning!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2015 17:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237635#M43562</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-12-03T17:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Not Working in Hash Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237756#M43597</link>
      <description>&lt;P&gt;THank you Mark. I have already done the purchase on Amazon &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 08:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237756#M43597</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2015-12-04T08:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Not Working in Hash Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237757#M43598</link>
      <description>&lt;P&gt;THank you for this solution Haikuo. Its friday, and more time to crack some extra SAS features &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 08:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Not-Working-in-Hash-Table/m-p/237757#M43598</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2015-12-04T08:42:30Z</dc:date>
    </item>
  </channel>
</rss>

