<?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 Sort in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718321#M222288</link>
    <description>&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 10 Feb 2021 17:25:57 GMT</pubDate>
    <dc:creator>JackoNewbie</dc:creator>
    <dc:date>2021-02-10T17:25:57Z</dc:date>
    <item>
      <title>Hash Sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718286#M222263</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to hash sas programming. I have found some useful code which will split my dataset in to different tables depending on a certain variable. I am looking to include a sort to the code for one of the columns in each table but struggling to see how this would fit in with the hash code. I know I can use a macro variable at the end then a proc sort but would rather have it included in the hash code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Outcome: Datasets one, two and three to be sorted in descending order on 'var1'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help at all would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID $ var1 var2;
datalines;
one 100 200
one 100 200
three 300 400
three 500 200
three 200 100
two 400 200
two 300 166
one 300 100
three 400 400
;

proc sort data=have;by id;run;
data _null_;
 if _n_=1 then do;
   if 0 then set have;
   declare hash h(dataset:'have(obs=0)',multidata:'y');
   h.definekey(all:'y');
   h.definedata(all:'y');
   h.definedone();
 end;
do until(last.id);
 set have;
 by id;
 h.add();
end;
h.output(dataset:id);
h.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 16:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718286#M222263</guid>
      <dc:creator>JackoNewbie</dc:creator>
      <dc:date>2021-02-10T16:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718306#M222277</link>
      <description>Simple specify the variable of interested only in the definekey and use the ordered:’y’ tag in the declare Statement</description>
      <pubDate>Wed, 10 Feb 2021 16:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718306#M222277</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T16:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718310#M222281</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277136"&gt;@JackoNewbie&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can add &lt;FONT face="courier new,courier"&gt;descending var1&lt;/FONT&gt; to the BY statement of the PROC SORT step and then use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;h.definekey('id');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or leave the PROC SORT step unchanged, insert the &lt;FONT face="courier new,courier"&gt;ordered:'d'&lt;/FONT&gt; argument tag in the DECLARE statement and use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;h.definekey('var1');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "&lt;FONT face="courier new,courier"&gt;if 0 then set have;&lt;/FONT&gt;" is redundant because of the other SET statement.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 16:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718310#M222281</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-10T16:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718321#M222288</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 17:25:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718321#M222288</guid>
      <dc:creator>JackoNewbie</dc:creator>
      <dc:date>2021-02-10T17:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718322#M222289</link>
      <description>First option worked. Thanks for the solution.</description>
      <pubDate>Wed, 10 Feb 2021 17:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718322#M222289</guid>
      <dc:creator>JackoNewbie</dc:creator>
      <dc:date>2021-02-10T17:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Sort</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718353#M222310</link>
      <description>&lt;P&gt;If you're interested, you can do the while split thing with no pre sorting using hash of hashes like this. Your data can't be too big though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID $ var1 var2;
datalines;
one 100 200
one 100 200
three 300 400
three 500 200
three 200 100
two 400 200
two 300 166
one 300 100
three 400 400
;

data _null_;
   dcl hash hh();
   hh.definekey("id");
   hh.definedata("h", "id");
   hh.definedone();
   dcl hiter i("hh");

   do until (z);
      set have end = z;
      if hh.find() ne 0 then do;
         dcl hash h(dataset : "have(obs = 0)", multidata : "Y", ordered : "Y");
         h.definekey("var1");
         h.definedata(all : "Y");
         h.definedone();
         hh.add();
      end;
      h.add();
   end;

   do while (i.next() = 0);
      h.output(dataset : id);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 19:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Sort/m-p/718353#M222310</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T19:02:47Z</dc:date>
    </item>
  </channel>
</rss>

