<?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.ref() behaviour in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125027#M25561</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have never found this note to actually hold true.&amp;nbsp; The ref method is supposed to be a combination of the 'find' and 'add' methods, which would do what you are seeking when used separately.&amp;nbsp; This seems to hold true in both 9.2 and 9.3 and I have never seen it replace the data value in PDV when a key is found when using the ref method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt; dcl hash m();&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.definekey('k');&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.definedata('d');&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.definedone();&lt;/P&gt;&lt;P&gt; k='Labrador'; d='Retriever';&lt;/P&gt;&lt;P&gt; m.add();&lt;/P&gt;&lt;P&gt; d='TEST';&lt;/P&gt;&lt;P&gt; rc=m.ref();&lt;/P&gt;&lt;P&gt; put _all_;&lt;/P&gt;&lt;P&gt;/* k=Labrador d=TEST rc=0 _ERROR_=0 _N_=1 */&lt;/P&gt;&lt;P&gt; rc=m.ref(key:'Labrador',data:'blah');&lt;/P&gt;&lt;P&gt; put _all_;&lt;/P&gt;&lt;P&gt;/* k=Labrador d=TEST rc=0 _ERROR_=0 _N_=1 */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* how the ref method is expected to behave */&lt;/P&gt;&lt;P&gt; rc=m.find();&lt;/P&gt;&lt;P&gt;&amp;nbsp; if rc^=0 then rc=m.add();&lt;/P&gt;&lt;P&gt; put _all_;&lt;/P&gt;&lt;P&gt;/* k=Labrador d=Retriever rc=0 _ERROR_=0 _N_=1 */&lt;/P&gt;&lt;P&gt; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The ref method, to me, seems to be more accurately defined as a combination of the check and add methods rather than the find and add methods.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 May 2012 18:58:27 GMT</pubDate>
    <dc:creator>FriedEgg</dc:creator>
    <dc:date>2012-05-23T18:58:27Z</dc:date>
    <item>
      <title>Hash.ref() behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125026#M25560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Hash experts, I'm trying to teach myself to use the hash and hiter component objects (v9.3) and there is something I don't understand. It is about the ref() method of the hash object. It says in the doc:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="noteGenText"&gt;Note: &lt;/SPAN&gt;&lt;/STRONG&gt;The REF method sets the data variable to the value of the data item so that it is available for use after the method call. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That would be very usefull indeed. But the following little test seems to contradict that statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;length k $15;&lt;/P&gt;&lt;P&gt;length d $15;&lt;/P&gt;&lt;P&gt;/* Declare and instantiate hash object "myhash" */ &lt;/P&gt;&lt;P&gt;declare hash myhash;&lt;/P&gt;&lt;P&gt;myhash = _new_ hash( );&lt;/P&gt;&lt;P&gt;/* Define key and data variables */&lt;/P&gt;&lt;P&gt;rc = myhash.defineKey('k');&lt;/P&gt;&lt;P&gt;rc = myhash.defineData('d');&lt;/P&gt;&lt;P&gt;rc = myhash.defineDone( );&lt;/P&gt;&lt;P&gt;/* avoid uninitialized variable notes */&lt;/P&gt;&lt;P&gt;call missing(k, d);&lt;/P&gt;&lt;P&gt;/* Create constant key and data values */&lt;/P&gt;&lt;P&gt;rc = myhash.add(key: 'Labrador', data: 'Retriever');&lt;/P&gt;&lt;P&gt;/* Give initial value to data variable */&lt;/P&gt;&lt;P&gt;d = 'TEST';&lt;/P&gt;&lt;P&gt;/* Call ref method with existing key */&lt;/P&gt;&lt;P&gt;rc = myhash.ref(key: 'Labrador', data: 'Golden');&lt;/P&gt;&lt;P&gt;/* Check data variable */&lt;/P&gt;&lt;P&gt;put d;&lt;/P&gt;&lt;P&gt;stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TEST&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was expecting Retriever.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can somebody explain?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2012 18:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125026#M25560</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-05-23T18:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Hash.ref() behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125027#M25561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have never found this note to actually hold true.&amp;nbsp; The ref method is supposed to be a combination of the 'find' and 'add' methods, which would do what you are seeking when used separately.&amp;nbsp; This seems to hold true in both 9.2 and 9.3 and I have never seen it replace the data value in PDV when a key is found when using the ref method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt; dcl hash m();&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.definekey('k');&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.definedata('d');&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.definedone();&lt;/P&gt;&lt;P&gt; k='Labrador'; d='Retriever';&lt;/P&gt;&lt;P&gt; m.add();&lt;/P&gt;&lt;P&gt; d='TEST';&lt;/P&gt;&lt;P&gt; rc=m.ref();&lt;/P&gt;&lt;P&gt; put _all_;&lt;/P&gt;&lt;P&gt;/* k=Labrador d=TEST rc=0 _ERROR_=0 _N_=1 */&lt;/P&gt;&lt;P&gt; rc=m.ref(key:'Labrador',data:'blah');&lt;/P&gt;&lt;P&gt; put _all_;&lt;/P&gt;&lt;P&gt;/* k=Labrador d=TEST rc=0 _ERROR_=0 _N_=1 */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* how the ref method is expected to behave */&lt;/P&gt;&lt;P&gt; rc=m.find();&lt;/P&gt;&lt;P&gt;&amp;nbsp; if rc^=0 then rc=m.add();&lt;/P&gt;&lt;P&gt; put _all_;&lt;/P&gt;&lt;P&gt;/* k=Labrador d=Retriever rc=0 _ERROR_=0 _N_=1 */&lt;/P&gt;&lt;P&gt; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The ref method, to me, seems to be more accurately defined as a combination of the check and add methods rather than the find and add methods.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2012 18:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125027#M25561</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2012-05-23T18:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Hash.ref() behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125028#M25562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you FriedEgg. Do you know of other inaccuracies in the component objects documentation? - PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2012 19:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125028#M25562</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-05-23T19:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Hash.ref() behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125029#M25563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I concur. The help doc for ref() is erroneous at least for SAS 9.2.&lt;/P&gt;&lt;P class="sgml"&gt;Where it says:&lt;/P&gt;&lt;P&gt;"You can consolidate FIND and ADD methods into a single REF method. You can change the following code: &lt;/P&gt;&lt;PRE class="jive-pre"&gt;rc = h.find(); if (rc ne = 0) then rc = h.add();&lt;/PRE&gt;&lt;P&gt;to &lt;/P&gt;&lt;PRE class="jive-pre"&gt;rc = h.ref();&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;While like FriedEgg said, it should be:&lt;/P&gt;&lt;P&gt;rc=h.check();&lt;/P&gt;&lt;P&gt;if rc ne 0 then rc=h.add();&lt;/P&gt;&lt;P&gt;else do nothing. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; It also occurs to me rc=ref() has always been '0'. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2012 19:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125029#M25563</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-05-23T19:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Hash.ref() behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125030#M25564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not familiar with any other issues like this as far as hash and hash iterator methods are concerned.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2012 19:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125030#M25564</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2012-05-23T19:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Hash.ref() behaviour</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125031#M25565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SAS has recognized the issue in this usage note:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://support.sas.com/kb/45/093.html" title="http://support.sas.com/kb/45/093.html"&gt;http://support.sas.com/kb/45/093.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The REF method is a consolidation of the CHECK and ADD methods.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2012 19:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-ref-behaviour/m-p/125031#M25565</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2012-05-23T19:58:41Z</dc:date>
    </item>
  </channel>
</rss>

