<?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: Keeping only highest values in hash table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175948#M302218</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I thought this would take me forever but I somehow nailed it on the first pass although I might be overlooking something. Anyway here's the solution - sorry for the copy/paste cluter. This may not be the absolute best case to demonstrate hash of hashes but nonetheless it worked out alright.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the event that your data is already sorted by ID but not subsequently by SCORE (as then using a first. logic and retained counter would be far more efficient than hashing), it is possible to simplify it a lot by reusing constantly the same inner/hinner and using the .clear() or .delete() and a new declare for each by group (can be managed with first. and last.). It would obviously significantly reduce memory consumption since you only keep a small subset of data in hash and output it through a loop with the hiterator upon last.ID type of logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As for the rationale why it can be worthwhile to learn hashing hashes, if you have data with many data points where a large subset of the variables retain the same values, by using hash of hashes you actually allocate memory only once for all the data in the outer hash and then only the varying portion however small n times in the inner hash object. So for instance, if you had pacemaker data (bear with me here I don't work with health statistics but it's the first thing that came up to mind) with millions of timestamps with some data elements about vital signs provided by the pacemaker at each such timestamp but then you needed to carry tons of invariants or little variants (Age sex marital s tatus working status etc.) as well as some slightly more variant data like medical visits and the additional health measuers done at each such visits. Well you could play with 3 hashes, the outer having the age/sex/etc, the middle one with the medical visits data and ther inner one with timestamps+pacemaker data. So you might have 1M timestamps total for a single person but you only use memory once for all of his invariants, say 12 times (once a year) for his little variants and then the 1M timestamps with just a few variables taking up bulk memory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On top of that, this allows you to do some funky data manipulation as you have 3 layers of searches. For instance, if you have twins that have a specific twin_id, you might be interested in adding a 4rth layer of hashing with just twin ID as key and data and loop over twin pairs to track events and then use the fourth (inner most) hash object to see if the twin had a similar event shortly before or shortly after the timestamp where it occured on the first twin. Anyway I'm digressing here but even though they are quite complex to code and especially hard to transfer or exchange with colleagues as Hashing is still foreign grounds for most SAS end-users, there are many niches left to be explored where hash objects and in particular the capacity to store other objects as data in hash objects can significantly improve quality of life.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Let n_highest=3;&lt;/P&gt;&lt;P&gt;%let hashexp=%sysfunc(ceil(%sysfunc(sqrt(&amp;amp;n_highest.))));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Input ID $ Score;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;A.B. 10&lt;/P&gt;&lt;P&gt;A.B. 10&lt;/P&gt;&lt;P&gt;A.B. 5&lt;/P&gt;&lt;P&gt;A.B. 8&lt;/P&gt;&lt;P&gt;A.B. 10&lt;/P&gt;&lt;P&gt;A.B. 7&lt;/P&gt;&lt;P&gt;A.B. 23&lt;/P&gt;&lt;P&gt;A.B. 10&lt;/P&gt;&lt;P&gt;K.L. 9&lt;/P&gt;&lt;P&gt;K.L. 12&lt;/P&gt;&lt;P&gt;K.L. 11&lt;/P&gt;&lt;P&gt;K.L. 11&lt;/P&gt;&lt;P&gt;K.L. 11&lt;/P&gt;&lt;P&gt;K.L. 2&lt;/P&gt;&lt;P&gt;K.L. 9&lt;/P&gt;&lt;P&gt;K.L. 7&lt;/P&gt;&lt;P&gt;;&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;data want2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length id $8. score 8. counter 8.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If _n_=1 Then Do;&lt;BR /&gt; declare hash inner; /* not yet instanciated */&lt;BR /&gt; declare hiter hinner; /* not yet instanciated */&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash outer(Ordered:'a', multidata: 'n'); /* load*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hiter houter('outer'); /* hash iterator object declared on hash object HT */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outer.DefineKey('ID');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outer.DefineData('ID','inner', 'hinner');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outer.DefineDone();&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt;set have end=last;&lt;/P&gt;&lt;P&gt;if outer.find() NE 0 then do; /* ID does not exist, create its own new hash object and iterator to track scores */&lt;BR /&gt;&amp;nbsp; inner = _new_ hash(ordered: 'y', multidata: 'n', hashexp: &amp;amp;hashexp.); /* instanciating / multidata:'n' is default but for clarity, we use the counter variable instead of an additional hash to mimic NUM_KEYS attribute */&lt;BR /&gt;&amp;nbsp; hinner = _new_ hiter('inner'); /* instanciating */&lt;BR /&gt;&amp;nbsp; inner.definekey('score');&lt;BR /&gt;&amp;nbsp; inner.definedata('score', 'counter');&lt;BR /&gt;&amp;nbsp; inner.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; outer.add(); /* add the ID and the related inner objects to the outer hash object */&lt;BR /&gt;&amp;nbsp; counter=1; /* Initiate inner counter variable */&lt;BR /&gt;&amp;nbsp; inner.add(); /* add the score and counter to the inner object */&lt;BR /&gt; end; else do; /* Else, an inner object already exists for this ID */&lt;BR /&gt;&amp;nbsp; if inner.find()=0 then do; /* If the score exists, increment its counter variable and replace. Otherwise, add it and handle the possibility of 4 distinct score now existing in the object */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; counter=counter+1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; inner.replace();&lt;BR /&gt;&amp;nbsp; end; else do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; counter=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; inner.add();&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if inner.num_items&amp;gt;&amp;amp;n_highest. then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; hinner.first(); /* set pointer to first aka lowest score due to sorting order */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=hinner.prev(); /* Clear the pointer in an idiotic way so that lowest key can be removed - this way inner hiterators will also have null pointers for the output at the end so noneed to do special handling of .first() instead of .next() to reinitialize */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=inner.remove();&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; /* hashes logic is built, now we need a method to output all of this data. */&lt;/P&gt;&lt;P&gt;if last then do;&lt;BR /&gt;&amp;nbsp; do while(houter.next()=0); /* loop on all IDs */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do while(hinner.next()=0); /* loop on all scores for that ID*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to counter; /* use our counter variable to recreate the appropriate number of records for an ID/Score pair */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt;drop rc i counter;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers and wish you great holidays!&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Dec 2013 14:25:20 GMT</pubDate>
    <dc:creator>Vince28_Statcan</dc:creator>
    <dc:date>2013-12-24T14:25:20Z</dc:date>
    <item>
      <title>Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175928#M302198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When going through dataset "have" shown in the example below I only want to keep the three highest scores:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "want1": three entries with the highest scores would be nice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "want2": entries with the three highest scores would be even nicer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As soon as I try to accomplish this my code gets pretty complicated and its not really working...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I'm new to hash tables, I have a feeling that there is an easy solution that I'm just missing... Any help is appreciated!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Input Name $ Score;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;A.B. 6&lt;/P&gt;&lt;P&gt;C.D. 10&lt;/P&gt;&lt;P&gt;E.F. 5&lt;/P&gt;&lt;P&gt;G.H. 3&lt;/P&gt;&lt;P&gt;I.J. 10&lt;/P&gt;&lt;P&gt;K.L. 9&lt;/P&gt;&lt;P&gt;M.N 3&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;Data _Null_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set have End=done;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If _n_=1 Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Declare Hash ht(Ordered:'d');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineKey('Score');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineData('Name','Score');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If ht.Num_Items&amp;lt;3 Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.Add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Need something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If ht.Last/Score &amp;lt; Score Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.RemoveLast;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.Add;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If done Then ht.Output(Dataset:'So_far');&lt;/P&gt;&lt;P&gt;&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;Data want1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Input Name $ Score;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;C.D. 10&lt;/P&gt;&lt;P&gt;I.J. 10&lt;/P&gt;&lt;P&gt;K.L. 9&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data want2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Input Name $ Score;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;C.D. 10&lt;/P&gt;&lt;P&gt;I.J. 10&lt;/P&gt;&lt;P&gt;K.L. 9&lt;/P&gt;&lt;P&gt;A.B. 6&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 16:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175928#M302198</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-17T16:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175929#M302199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you really need hash for this?&lt;/P&gt;&lt;P&gt;I ask, because you can easily do it using Proc Rank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc rank data=have out=want descending ties=dense;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var score;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ranks scoreRank;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=want; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where scoreRank &amp;lt;= 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by descending score ; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=want; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 17:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175929#M302199</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2013-12-17T17:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175930#M302200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, dataset "have" is so large, that I'm going through it via "File" &amp;amp; "Input" without creating output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, unfortunately, "Proc Rank" is not an option...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 17:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175930#M302200</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-17T17:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175931#M302201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have/view=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile "My Documents/sample_have.txt";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Input Name $ Score;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc rank data=have out=want(where=(scoreRank &amp;lt;= 3)) descending ties=dense;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var score;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ranks scoreRank;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 18:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175931#M302201</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2013-12-17T18:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175932#M302202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for this solution!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since I became really fond of hash tables, I'll just wait a little longer to see if there's also a nice solution that takes advantage of them before I mark your answer and close the topic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The real dataset "have" requires some more grooming that can be easily done using hash tables... There's only the problem of extracting data with certain features (highest values etc.) which I thought could be accomplished by having the hash table sortered in descendant order.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 18:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175932#M302202</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-17T18:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175933#M302203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The way you have described it, it seems like you need to find the 3 highest scores, and the names associated with those scores.&amp;nbsp; I would think that arrays would be a much better bet.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array scores {3} score1-score3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; array names {3} $8 name1-name3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (done);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have end=done;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if score &amp;gt; score1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; score3=score2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; score2=score1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; score1=score;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name3=name2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name2=name1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name1=name;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if score &amp;gt; score2 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; score3=score2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; score2=score;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name3=name2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name2=name;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if score &amp;gt; score3 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; score3=score;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name3=name;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; keep name1-name3 score1-score3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because of the DO loop, there is no need to retain any of the variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need this information for processing another data set, you could use _TEMPORARY_ arrays instead of permanent.&amp;nbsp; _TEMPORARY_ array elements do not get erased.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could in theory replace the OUTPUT and STOP statements with a SET statement that reads another data set and processes observations based on NAME1-NAME3 and SCORE1-SCORE3.&amp;nbsp; In that case, however, you would have to make sure that either these variables are retained or that you switch to _TEMPORARY_ arrays.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure if you were hoping to get practice with hash tables here instead.&amp;nbsp; But I would think that arrays are at least a good approach to the problem you described.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 19:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175933#M302203</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-12-17T19:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175934#M302204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Arrays are also a very nice solution. Only the fact that "have" has 96 variables might cause some trouble, but otherwise this should work nicely.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hash tables are an ideal solution for the operations I need to perform on "have". It's all working perfectly fine and very fast...&lt;/P&gt;&lt;P&gt;...up to the point that I don't want to populate my hash table with ALL entries, but only want to keep the nth highest values regarding certain fields...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 19:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175934#M302204</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-17T19:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175935#M302205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, the plot always thickens.&amp;nbsp; In that case, don't bother saving NAME1-NAME3.&amp;nbsp; Instead, save OBSNO1-OBSNO3, the observation number from HAVE.&amp;nbsp; It should be a simple matter afterwards to retrieve just those three observations using SET and POINT=.&amp;nbsp; I'd need further details of how you intend to use those observations to consider whether it makes sense to load them into a hash table at that point.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 20:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175935#M302205</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-12-17T20:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175936#M302206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I concur &lt;A __default_attr="5253" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; 's sentiment and comment. From the nature of a Hash table, as long as your RAM can hold it, the bigger the table, the better&amp;nbsp; benefits you get from it. Only a few highest scores in the a Hash table seems to be an overkill of using it. But without knowing the whole picture, it is too soon to call. Technical speaking it is of course doable using Hash table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;Data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Input&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; Name $ Score;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Datalines&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;OL style="list-style-type: upper-alpha;"&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;A.B. 6&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;C.D. 10&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;E.F. 5&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;G.H. 3&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;I.J. 10&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;K.L. 9&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;M.N 3&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Run&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;/*Want1*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;Data&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;_Null_&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; have End=done;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;If&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; _n_=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Declare&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Hash&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ht(Ordered:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'d'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;, multidata:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'y'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineKey(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'_Score'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineData(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'_Name'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'_Score'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineDone();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;declare&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;hiter&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; hi(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'ht'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;End&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; _n_ &amp;lt;= &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;3&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;; _name=name;_score=score; rc=ht.add();&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;else&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; rc=hi.last();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; score &amp;gt; _score &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _ss=_score;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _score=score;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _name=name;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=ht.add();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=hi.first();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=ht.remove(key:_ss);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;If&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; done &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ht.Output(Dataset:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'ties_count'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Run&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: green; background: white;"&gt;/*Want2*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;Data&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;_Null_&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; have End=done;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;If&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; _n_=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Declare&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Hash&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ht(Ordered:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'d'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;, multidata:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'y'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineKey(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'_Score'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineData(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'_Name'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'_Score'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineDone();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;declare&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;hiter&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; hi(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'ht'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;End&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; _n_ &amp;lt;= &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;3&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;; _name=name;_score=score; rc=ht.add();&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;else&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ht.find(key:score) = &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;; _name=name;_score=score; rc=ht.add();&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;else&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; rc=hi.last();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; score &amp;gt; _score &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _ss=_score;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _score=score;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _name=name;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=ht.add();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=hi.first();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=ht.remove(key:_ss);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;If&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; done &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ht.Output(Dataset:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'ties_not_count'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;Run&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;Haikuo &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 21:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175936#M302206</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-12-17T21:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175937#M302207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Solution using hash tables power to ease things up...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You've gone the right way using ordering, however, you misunderstood how your datarows are appended to the hash object when you don't use a dataset: statement. You would need to use a hash iterator object to retrieve first or last 3 hash object items after all of it has been loaded and sorted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a simple hash solution that still uses data step to output. You could use hash object output but you would need to create 2 or 3 hashes for simplicity or do some hardcore .remove() implementation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Input Name $ Score;&lt;BR /&gt;Datalines;&lt;BR /&gt;A.B. 6&lt;BR /&gt;C.D. 10&lt;BR /&gt;E.F. 5&lt;BR /&gt;G.H. 3&lt;BR /&gt;I.J. 10&lt;BR /&gt;K.L. 9&lt;BR /&gt;M.N 3&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want1 want2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 0 then set have; /* avoid length statements */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If _n_=1 Then Do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Declare Hash ht(&lt;STRONG&gt;dataset: 'have',&lt;/STRONG&gt; Ordered:'d', &lt;STRONG&gt;multidata: 'Y');&lt;/STRONG&gt; /* load*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Declare Hiter hi('ht');&lt;/STRONG&gt; /* hash iterator object declared on hash object HT */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineKey('Score');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineData('Name','Score');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht.DefineDone();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* to achieve want1 and want2 logic */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=0; j=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do while (j&amp;lt;3);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt; hi.next(); /* loop through sorted data using iterator. If iterator has not been used before, then hi.next() is equivalent to hi.first() */&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i&amp;lt;3 then output want1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output want2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last_score NE score then j+1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_score=score;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop i j last_score;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've put the interesting hash elements in bold the rest is similar logic that you would hard code if you used sorted data. Please note the use of multidata:'y' option as otherwise only CD or IJ could exist within the hash object as their KEY is identical.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Dec 2013 21:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175937#M302207</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-12-17T21:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175938#M302208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's exactly what I was looking for!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Dec 2013 11:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175938#M302208</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-18T11:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175939#M302209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for pointing out this alternative!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Considering the size of the "real" have-dataset, I'm trying to populate the hash table with as few data as possible.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Dec 2013 12:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175939#M302209</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-18T12:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175940#M302210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see. Well obviously, my solution causes a single pass on the data instead of two cutting I/O by ~half (well only input but still a large chunk of your total I/O). However loading a full hash object isn't always manageable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is possible however to manage to output each want1 and want2 in a single read of the data using 3 hash objects each with at most 4 distinct key values at any given time so reasonably little total memory space saving a giant input operation. I will try to come provide the additionnal example during my lunch break as the logic is slightly less natural at least for my hash habits to spare a small break for it. It won't necessarily be a giant breakthrough but if I think it's a worthwhile self-learning I would assume it can benefit to others as well!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vincent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Dec 2013 13:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175940#M302210</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-12-18T13:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175941#M302211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As mentionned, here's an alternative that will produce both output within a single pass on the data effectively saving you a large I/O since the reason why you didn't load the entire table in a hash was for memory issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 0 then set have; /* avoid length statements */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If _n_=1 Then Do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Declare Hash ht1(Ordered:'d', multidata: 'Y', hashexp: 2); /* load*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Declare Hiter hi1('ht1'); /* hash iterator object declared on hash object HT */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht1.DefineKey('Score');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht1.DefineData('Name','Score');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht1.DefineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; declare hash ht2(ordered:'d', multidata: 'Y', hashexp: 2);&lt;BR /&gt;&amp;nbsp; declare hiter hi2('ht2');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht2.DefineKey('Score');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht2.DefineData('Name','Score');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ht2.DefineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; declare hash kt2(ordered: 'd', hashexp: 2);&lt;BR /&gt;&amp;nbsp; declare hiter ki2('kt2');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kt2.DefineKey('Score');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kt2.DefineData('Score');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kt2.DefineDone();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt; set have end=done;&lt;BR /&gt; ht1.add();&lt;BR /&gt; kt2.replace();&lt;BR /&gt; ht2.add();&lt;/P&gt;&lt;P&gt; if ht1.num_items&amp;gt;3 then do;&lt;BR /&gt;&amp;nbsp; hi1.last();&lt;BR /&gt;&amp;nbsp; rc=hi1.next();&lt;BR /&gt;&amp;nbsp; ht1.remove();&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt; if kt2.num_items&amp;gt;3 then do;&lt;BR /&gt;&amp;nbsp; ki2.last();&lt;BR /&gt;&amp;nbsp; rc=ki2.next();&lt;BR /&gt;&amp;nbsp; kt2.remove();&lt;BR /&gt;&amp;nbsp; ht2.remove();&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt; if done then do;&lt;BR /&gt;&amp;nbsp; ht1.output(dataset: "want1");&lt;BR /&gt;&amp;nbsp; ht2.output(dataset: "want2");&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On a side note, I was very disappointed to realize that there is no documented method or trick to set the hash iterator pointer to NULL after using it to retrieve the last or first item for the purpose of removing data. Anyone knows a trick that is more straight forward, especially when it comes to reading the code, other than having to use next() after a last() to clear the pointer without changing PDV values since you ought to reuse the same keys? The approach above saves from having to declare and call missing every data step loop on a full subset of variables with the same name as the set itself and it solely uses the sortation within the hash and an iterator to remove data but because there exists no way to set an iterator pointer to NULL, I had to waste PDV space and a bunch of useless iteration for RC=iterator.next() as without the RC=, it creates an error (data step still processes). Plus, it does not feel natural to have to tell a pointer on the known last element of a sequence to point to the next element so as to clear it from locking the removal of data/key elements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway end of the rant about iterator having no method to change the pointer position without affecting PDV other than next on a last or prev on a first. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Dec 2013 18:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175941#M302211</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-12-18T18:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175942#M302212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for taking the time! I learnt a lot from your examples!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Dec 2013 18:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175942#M302212</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-19T18:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175943#M302213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="818277" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/" modifiedtitle="true" title="Vince28@Statcan,"&gt;&lt;/A&gt; I was quite puzzled by your comments regarding on "I/O" issues until I saw this post of yours. I was thinking OP wants either 'nice' or 'nicer', but not both, hence my solution. If&amp;nbsp; wanting both, I would opt using my /*Want2*/ with a little tweak, such as using removedup() instead of remove() method, and then do a subset using "obs=3" to get /*want1*/, paying little to zero extra to 'I/O', but the benefit is obvious: 1. Avoiding strenuously Hash coding with multiple Hash objects. 2. Remove() method is not quite ready for dup-keys in this case, try following data you will know what I mean.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Input Name $ Score;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;A.B. 11&lt;/P&gt;&lt;P&gt;C.D. 9&lt;/P&gt;&lt;P&gt;C.D. 9&lt;/P&gt;&lt;P&gt;C.D. 9&lt;/P&gt;&lt;P&gt;C.D. 9&lt;/P&gt;&lt;P&gt;E.F. 5&lt;/P&gt;&lt;P&gt;G.H. 3&lt;/P&gt;&lt;P&gt;M.N 3&lt;/P&gt;&lt;P&gt;I.J. 10&lt;/P&gt;&lt;P&gt;I.J. 10&lt;/P&gt;&lt;P&gt;I.J. 10&lt;/P&gt;&lt;P&gt;I.J. 10&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Dec 2013 19:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175943#M302213</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-12-19T19:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175944#M302214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did indeed simply assume that he might want to achieve both and not either or hence programming both within a single data step to save what is the longest processing element which is to input the data through the set statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't think the output method supports dataset option like OBS=3 for output so you'd need to replace data _null_ with data want1 and use the iterator on the 2nd hash object to just retrieve the top three values. In fact, this would also solve the bug you've pointed out with my want1 output. However, I still do think there's a lot fo learn playing with hashing around and the 2-hash solution for want2. It also solves the bug pointed out by your own dataset for your want2 output and detailed below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The issue with not using double hash object for WANT2 is that there does not exist a num_key property to hash objects for multidata. The data set you've examplified above also fails for your want2 because the threshold to adding new keys is _N_=3 so if there are only 1 or 2 keys across the first 3 lines of the input dataset, the output will only have one or two keys as well (and however many records share these keys). Still, it means that you have to consider the odd cases of your data in your "initialization phase" of the object. For most scenarios andi n particualr the one examplified here it is fairly simple, you can just create a new counter variable and increment it if find() fails on the hash prior to addition and then repalce the _N_ by that new counter variable instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The main reason I went with other approach was that it is completely independant from initialization. It uses NUM_ITEMS on the "KT" (key table) hash as a mean to mimic a missing NUM_KEYS property on the object I really care for. If NUM_KEYS property existed, it could've been done in a single hash as well but still using the sorting power of the hash to avoid having to manually code a bunch of additionnal variables to keep track of what to add/remove. You simply systematically add to your hash object and remove the last key (and all data associated to the key) if the NUM_KEYS is above your set threshold. This is also one of the beauty of hash object if you ever have to manipulate timestamp data from a system (like a voice recognition system or electronic questionaire or transaction records etc). You can use hash of hashes to rebuild the sequence of events regardless of any existing sortation and the internal instances of the hashes act as BY-groups sorted by the timestamp so you can iterate through and go back and forth if need be for decision logic and output a single row all within a single data step instead of a couple sorts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway I'm digressing because I did have to work with odd sortation masive call system data not so long ago where if I had had the hash knowledge I have now would've made my life so much easier (and I still have a lot of twists to learn).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But for all I know, even though the hash object has significantly improved in 9.2 from all documentation I could find, it is still missing quite a few tools.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. A way to clear the hash iterator pointer so as to not lock remove() from happening&lt;/P&gt;&lt;P&gt;2. A hash iterator tool that allows to remove the current element (not the entire key but just the data element - similar to removedup but less tedious to use - it would also be extremely useful for traversing through the hash object and removing rows after sortation or other constructs have happened)&lt;/P&gt;&lt;P&gt;3. A NUM_KEYS property&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some might exist and are undocumented but I haven't found any paper discussing any such issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nonetheless, very interesting discussion so far&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 16:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175944#M302214</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-12-20T16:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175945#M302215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Turned out that we actually needed just the n highest scores ("want2"), but we needed them for every name (or ID). This is the solution I came up with. Unfortunately, it needs not one but two additional tables, but it's working and it's really fast... However, any suggestions are always welcome!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Let n_highest=3;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Input ID $ Score;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;A.B. 10&lt;/P&gt;&lt;P&gt;A.B. 10&lt;/P&gt;&lt;P&gt;A.B. 5&lt;/P&gt;&lt;P&gt;A.B. 8&lt;/P&gt;&lt;P&gt;A.B. 10&lt;/P&gt;&lt;P&gt;A.B. 7&lt;/P&gt;&lt;P&gt;K.L. 9&lt;/P&gt;&lt;P&gt;K.L. 2&lt;/P&gt;&lt;P&gt;K.L. 9&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data _null_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If 0 Then Set have;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If _n_=1 Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Declare Hash extra_tab1(Ordered:'a');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab1.DefineKey('ID');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab1.DefineData('ID','lowest','no');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab1.DefineDone();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Declare Hash extra_tab2(Ordered:'a');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2.DefineKey('ID','Score');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2.DefineData('ID','Score');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2.DefineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Declare Hiter extra_tab2_hit('extra_tab2');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Declare Hash tab(Ordered:'a',Multidata:'y');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tab.DefineKey('ID','Score');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tab.DefineData('ID','Score');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tab.DefineDone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set have End=Done;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If extra_tab1.Find() ne 0 Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; no=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lowest=Score;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab1.Add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2.Add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tab.Add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else If no&amp;lt;&amp;amp;n_highest. Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If extra_tab2.Find() ne 0 Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; no=no+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lowest=Min(lowest,Score);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab1.Replace();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2.Add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tab.Add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else If Score&amp;gt;=lowest Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tab.Add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If extra_tab2.Find() ne 0 Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2.Add();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2_hit.SetCur(Key:ID,Key:lowest);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2_hit.Next();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _lowest_new=Score;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2.Remove(Key:ID,Key:lowest);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tab.Remove(Key:ID,Key:lowest);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lowest=_lowest_new;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab1.Replace();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Done Then Do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab1.Output(Dataset:"extra_tab1");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extra_tab2.Output(Dataset:"extra_tab2");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tab.Output(Dataset:"want2");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 01:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175945#M302215</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-23T01:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175946#M302216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe it could be reduced in #hash, #of statements and logic by using hash of hashes but it adds an additionnal layer of complexity for code transferability (e.g. you leave your current position and someone has to pickup from it, if he's not already familliar with the hash object he will struggle far more figuring out what the code does with hash of hashes than in the current implementation).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I'll gladly take a stab at it and provide the code if you request it.&lt;/STRONG&gt; But otherwise I'll assume it is not needed. I don't think it would be significantly faster than the current implementation either.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was actually amazed when I first read Black Belt Hashigana by Paul Dorfman about hash of hashes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*edit* In practice, there would actually be n+1 hash objects where n is the number of distinct IDs but programatically speaking, they would just be new instances of a single hash so there would only need to be 2 hash objects defined. One with the current approach of instanciating upon declaration (followed with (), empty or with options like dataset: or sorted: ). The other ones would be built through a loop. The conditionnal logic would also be simpler with hash of hashes. Only the gist of understanding how multiple instances of a hash object all with the same name are handled is what would make the code difficult to understand.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*edit* Furthermore, in the perspective of wanting to use hash objects with complex conditional searches and/or with reduced memory usage, hash of hashes allow you to keep a by-variable only once in memory instead of however many multidata rows exist. It is really only worthwhile if you have big multidata groups and/or may want to search according to different keys based on the first key search success.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 17:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175946#M302216</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-12-23T17:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping only highest values in hash table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175947#M302217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm always on the look out and would highly appreciate to see another solution!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Dec 2013 02:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-only-highest-values-in-hash-table/m-p/175947#M302217</guid>
      <dc:creator>Georg_UPB</dc:creator>
      <dc:date>2013-12-24T02:49:17Z</dc:date>
    </item>
  </channel>
</rss>

