<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593606#M170386</link>
    <description>&lt;P&gt;&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;Yes, it can be coded this way. However, unfortunately, the way SAS designed the return codes is counter-intuitive from the standpoint of the normal SAS Boolean conventions. Hence, for a SAS programmer not quite familiar with the way the hash methods' return codes are set up, IF NOT H.FIND() is semantically perceived as "if key not found", while it's just the opposite.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This incongruence has caused quite a bit of costernation to my coauthor &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13569"&gt;@DonH&lt;/a&gt;&amp;nbsp;when he was loading himself with the SAS hash knowledge for the same reason as to me: Naturally, he and I would much rather prefer to have RC=1 if the call is successful and RC=0 otherwise. If that were the case, IF H.FIND() would mean "found" and IF NOT H.FIND() would mean "not found", and no confusion would arise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More unfortunately, some hash object methods offer argument tags assigned a variable name whose value is set to 1 in case of success and to 0 in case of failure, just the way the things ought to be. For all these reasons, I prefer to code return codes explicitly rather than to turn them into Booleans, just to avoid disorientation both for myself and those reading my hash code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 06:27:08 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-10-03T06:27:08Z</dc:date>
    <item>
      <title>Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593464#M170307</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset labelled as Final1 of patients with 84 records which has INST_NO i.e. the institution where they received some care&lt;/P&gt;&lt;P&gt;I want to compare the above dataset with another dataset (Inst_dsc) in which I have a list of Institution Nos&amp;nbsp;labelled as INST_AT&lt;/P&gt;&lt;P&gt;How would i write a code to check if the INST_No in the 1st dataset is present in the 2nd dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically want to flag the cases or records&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data match (Keep=INST_No INST_AT);&lt;/P&gt;&lt;P&gt;1227&amp;nbsp; length inst_AT 8 ;&lt;/P&gt;&lt;P&gt;1228&amp;nbsp; if _N_ then do;&lt;/P&gt;&lt;P&gt;1229&amp;nbsp; declare hash h (dataset:"work.inst_dsc");&lt;/P&gt;&lt;P&gt;1230&amp;nbsp; h.definekey ('INST_AT');&lt;/P&gt;&lt;P&gt;1231&amp;nbsp; call missing (INST_AT);&lt;/P&gt;&lt;P&gt;1232&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;1233&amp;nbsp; set Final1;&lt;/P&gt;&lt;P&gt;1234&amp;nbsp; rc=h.find(INST_AT);&lt;/P&gt;&lt;P&gt;1235&amp;nbsp; if rc=0 then output;&lt;/P&gt;&lt;P&gt;1236&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Uninitialized keys for hash object at line 1234 column 4.&lt;/P&gt;&lt;P&gt;ERROR: DATA STEP Component Object failure.&amp;nbsp; Aborted during the EXECUTION phase.&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;NOTE: There were 1 observations read from the data set Final1.&lt;/P&gt;&lt;P&gt;WARNING: The data set WORK.MATCH may be incomplete.&amp;nbsp; When this step was stopped there were 0 observations and 2 variables.&lt;/P&gt;&lt;P&gt;WARNING: Data set WORK.MATCH was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1237&amp;nbsp; proc print ;&lt;/P&gt;&lt;P&gt;1238&amp;nbsp; run;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 16:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593464#M170307</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-10-02T16:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593474#M170311</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if _N_ then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;means that you redefine the hash in every data step iteration (all numeric values except missing and zero are true).&lt;/P&gt;
&lt;P&gt;Change to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if _N_ = 1 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are also missing a call to the definedata() (if you have data columns) and definedone() methods.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 17:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593474#M170311</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-02T17:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593484#M170314</link>
      <description>&lt;P&gt;Moreover, in the FIND method you forgot the "key:" argument tag and used the wrong variable name. It should read&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc=h.find(key:INST_No);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or simplify the code by combining this with the subsequent IF-THEN statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if h.find(key:INST_No)=0 then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you've corrected this and the issues KurtBremser mentioned (&lt;FONT face="courier new,courier"&gt;define&lt;EM&gt;data&lt;/EM&gt;(...)&lt;/FONT&gt; is not required, though, only optional) your program should work. Of course, it doesn't really&amp;nbsp;&lt;EM&gt;flag&lt;/EM&gt; the matching cases, but &lt;EM&gt;selects&lt;/EM&gt; them from dataset Final1. This could be changed easily by replacing the OUTPUT statement with an assignment statement such as &lt;FONT face="courier new,courier"&gt;flag=1&lt;/FONT&gt;&amp;nbsp;(and adding &lt;FONT face="courier new,courier"&gt;flag&lt;/FONT&gt; to the KEEP list).&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 17:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593484#M170314</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-02T17:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593496#M170319</link>
      <description>&lt;P&gt;Thankyou Appreciate it&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 18:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593496#M170319</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-10-02T18:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593507#M170325</link>
      <description>&lt;P&gt;I would like to point out that the &lt;EM&gt;primary&lt;/EM&gt; mistake was the omission of &lt;FONT face="courier new,courier"&gt;definedone();&lt;/FONT&gt;. This caused the error messages in the log. Had it been inserted, the first error message would have changed to&lt;/P&gt;
&lt;PRE&gt;ERROR: Unknown argument tag at line ... column 4. Tag must be key.&lt;/PRE&gt;
&lt;P&gt;which might have helped you to find the solution. So, the most important response was actually&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;'s.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 18:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593507#M170325</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-02T18:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593591#M170376</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Your entire step can be condensed to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data match ;                           
  if _n_ = 1 then do ;                 
    dcl hash h (dataset:"inst_dsc") ;  
    h.definekey ("inst_at") ;          
    h.definedone () ;                  
  end ;                                
  set final1 (keep = inst_no inst_at) ;
  if h.check() = 0 ;                    
run ;                                  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You need neither LENGTH nor CALL MISSING, as the hash key is on file FINAL1, and parameter type matching (i.e. setting the hash host PDV variables) occurs when the compiler sees the SET reference to FINAL1. Most of the time, LENGTH and CALL MISSING aren't needed - they are just leftovers from the maladroitness in the documentation.&lt;/LI&gt;
&lt;LI&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&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;&amp;nbsp;have pointed out, _N_=1 is the condition you need to avoid (a) creating a new hash object instant at every observation read from FINAL1 and (b) loading the hash table at every observation.&lt;/LI&gt;
&lt;LI&gt;Keep the only variables you need &lt;EM&gt;on input&lt;/EM&gt;, &lt;EM&gt;not on output&lt;/EM&gt;, to prevent polluting the PDV with extraneous stuff and degrading performance.&lt;/LI&gt;
&lt;LI&gt;There's no need to use an assigned (i.e. RC=) method call because a call embedded in the IF statement prevents generating KEY NOT FOUND errors if there's no match.&lt;/LI&gt;
&lt;LI&gt;Likewise, there's no need for the OUTPUT statement since you can just use the subsetting IF.&lt;/LI&gt;
&lt;LI&gt;Since you don't need to retrieve any satellite information from the data portion of the hash table, you needn't use the FIND method. You're only checking if there's a match; so the CHECK method will suffice, not to mention that it's faster than FIND for&amp;nbsp; the obvious reason that it doesn't entail the extra burden of moving data from the hash table to the PDV host variables.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 06:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593591#M170376</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-03T06:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593598#M170378</link>
      <description>&lt;P&gt;One thing I might change:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if h.check() = 0 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not h.check();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 05:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593598#M170378</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-03T05:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593606#M170386</link>
      <description>&lt;P&gt;&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;Yes, it can be coded this way. However, unfortunately, the way SAS designed the return codes is counter-intuitive from the standpoint of the normal SAS Boolean conventions. Hence, for a SAS programmer not quite familiar with the way the hash methods' return codes are set up, IF NOT H.FIND() is semantically perceived as "if key not found", while it's just the opposite.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This incongruence has caused quite a bit of costernation to my coauthor &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13569"&gt;@DonH&lt;/a&gt;&amp;nbsp;when he was loading himself with the SAS hash knowledge for the same reason as to me: Naturally, he and I would much rather prefer to have RC=1 if the call is successful and RC=0 otherwise. If that were the case, IF H.FIND() would mean "found" and IF NOT H.FIND() would mean "not found", and no confusion would arise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More unfortunately, some hash object methods offer argument tags assigned a variable name whose value is set to 1 in case of success and to 0 in case of failure, just the way the things ought to be. For all these reasons, I prefer to code return codes explicitly rather than to turn them into Booleans, just to avoid disorientation both for myself and those reading my hash code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 06:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593606#M170386</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-03T06:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593644#M170400</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;: Very clear explanations, as always. I may be wrong, but my understanding was that variable &lt;FONT face="courier new,courier"&gt;inst_at&lt;/FONT&gt;&amp;nbsp;is in dataset &lt;FONT face="courier new,courier"&gt;inst_dsc&lt;/FONT&gt;, but &lt;EM&gt;not&lt;/EM&gt; in dataset &lt;FONT face="courier new,courier"&gt;Final1&lt;/FONT&gt;. In this case I would insert&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  inst_at=inst_no;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before the subsetting IF statement to support the simplifications you made to the code (and, of course, remove &lt;FONT face="courier new,courier"&gt;inst_at&lt;/FONT&gt; from the KEEP list).&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 08:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593644#M170400</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-03T08:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593839#M170504</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You may very well be correct on that head.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 18:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash/m-p/593839#M170504</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-03T18:06:29Z</dc:date>
    </item>
  </channel>
</rss>

