<?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 not working while sorting a data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646482#M193402</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19264"&gt;@dennis_oz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unlike the OUTPUT statement in a DATA step, the OUTPUT method of a hash object writes the &lt;EM&gt;entire&lt;/EM&gt; hash table to the dataset specified in the "&lt;FONT face="courier new,courier"&gt;dataset:&lt;/FONT&gt;" argument tag, not only a single record. That is, you are trying to write the 1.5 million observations (unnecessarily) 1.5 million times to dataset &lt;FONT face="courier new,courier"&gt;x1234&lt;/FONT&gt;&amp;nbsp;(which is, of course, much more time-consuming than to create a copy of SASHELP.CARS and to overwrite it 427 times again).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you don't need the hash iterator object. Remove the DO loop and execute the OUTPUT method only once.&lt;/P&gt;</description>
    <pubDate>Sun, 10 May 2020 10:01:01 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2020-05-10T10:01:01Z</dc:date>
    <item>
      <title>Hash not working while sorting a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646479#M193401</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;I am trying to perform a sort on a dataset on a oracle table by referencing the dataset&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as Oracle_schema.table1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*--------------------------------------------------------------------------------------*&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;if 0 then set &lt;FONT color="#FF0000"&gt;DW.Table1&lt;/FONT&gt; ;&lt;BR /&gt;dcl hash hh ( dataset: ' &lt;FONT color="#FF0000"&gt;DW.Table1&lt;/FONT&gt;', ordered: 'A', multidata: 'Y') ;&lt;BR /&gt;dcl hiter hi ( 'hh' ) ;&lt;BR /&gt;hh.DefineKey ( 'ADMIT_MONTH','PAtientid') ;&lt;BR /&gt;hh.DefineData ('FUND_MAJOR_DESC' ,'generic_month','ADMIT_MONTH','PAtientid') ;&lt;BR /&gt;hh.DefineDone () ;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;do rc = hi.first () by 0 while ( rc = 0 ) ;&lt;/P&gt;
&lt;P&gt;hh.output (dataset: "x1234") ;&lt;BR /&gt;rc = hi.next () ;&lt;BR /&gt;end ;&lt;/P&gt;
&lt;P&gt;stop ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;****------------------------------------------------------------------**&lt;/P&gt;
&lt;P&gt;But&amp;nbsp; it's taking forever to execute . hasn't still completed execution.&lt;FONT color="#FF0000"&gt; the table1 has 1.5 million records&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I in parallel execute a proc sort for the above method but it took only&amp;nbsp; 3 minutes to execute .&lt;/P&gt;
&lt;P&gt;Could some one explain why the above hash code won't execute&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data= &lt;FONT color="#FF0000"&gt;DW.Table1&lt;/FONT&gt;&lt;BR /&gt;(keep=FUND_MAJOR_DESC generic_month ADMIT_MONTH PAtientid)&lt;BR /&gt;out=x1234 ;&lt;BR /&gt;by ADMIT_MONTH PAtientid;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;to confirm my hash code i executed with sashelp.cars and it works , so i presume the syntax is correct&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;if 0 then set sashelp.cars ;&lt;BR /&gt;dcl hash hh ( dataset: 'sashelp.cars', ordered: 'a',multidata: "Y") ;&lt;BR /&gt;dcl hiter hi ( 'hh' ) ;&lt;BR /&gt;hh.DefineKey ( 'make' ) ;&lt;BR /&gt;hh.DefineData ( 'invoice' , 'model','make') ;&lt;BR /&gt;hh.DefineDone () ;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;do rc = hi.first () by 0 while ( rc = 0 ) ;&lt;BR /&gt;hh.output (dataset: "x1") ;&lt;BR /&gt;rc = hi.next () ;&lt;BR /&gt;end ;&lt;BR /&gt;put 13 * '-' ;&lt;BR /&gt;stop ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Sun, 10 May 2020 09:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646479#M193401</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2020-05-10T09:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Hash not working while sorting a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646482#M193402</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19264"&gt;@dennis_oz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unlike the OUTPUT statement in a DATA step, the OUTPUT method of a hash object writes the &lt;EM&gt;entire&lt;/EM&gt; hash table to the dataset specified in the "&lt;FONT face="courier new,courier"&gt;dataset:&lt;/FONT&gt;" argument tag, not only a single record. That is, you are trying to write the 1.5 million observations (unnecessarily) 1.5 million times to dataset &lt;FONT face="courier new,courier"&gt;x1234&lt;/FONT&gt;&amp;nbsp;(which is, of course, much more time-consuming than to create a copy of SASHELP.CARS and to overwrite it 427 times again).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you don't need the hash iterator object. Remove the DO loop and execute the OUTPUT method only once.&lt;/P&gt;</description>
      <pubDate>Sun, 10 May 2020 10:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646482#M193402</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-05-10T10:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Hash not working while sorting a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646490#M193407</link>
      <description>&lt;P&gt;do youmean to take out the&amp;nbsp; hiter statement and remove the do statement like below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have submitted the code and it has been more than 10 minutes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*----------------------------------------------------------------------*&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;if 0 then set sashelp.cars ;&lt;BR /&gt;dcl hash hh ( dataset: 'sashelp.cars', ordered: 'a',multidata: "Y") ;&lt;BR /&gt;&lt;BR /&gt;hh.DefineKey ( 'make' ) ;&lt;BR /&gt;hh.DefineData ( 'invoice' , 'model','make') ;&lt;BR /&gt;hh.DefineDone () ;&lt;/P&gt;
&lt;P&gt;hh.output (dataset: "x1") ;&lt;BR /&gt;put 13 * '-' ;&lt;BR /&gt;stop ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Sun, 10 May 2020 10:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646490#M193407</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2020-05-10T10:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Hash not working while sorting a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646491#M193408</link>
      <description>&lt;P&gt;Exactly. At least for SASHELP.CARS it should definitely not take 10 minutes, see below.&lt;/P&gt;
&lt;PRE&gt;13   data _null_;
14   if 0 then set sashelp.cars ;
15   dcl hash hh ( dataset: 'sashelp.cars', ordered: 'a',multidata: "Y") ;
16
17   hh.DefineKey ( 'make' ) ;
18   hh.DefineData ( 'invoice' , 'model','make') ;
19   hh.DefineDone () ;
20
21   hh.output (dataset: "x1") ;
22   put 13 * '-' ;
23   stop ;
24   run ;

NOTE: There were 428 observations read from the data set SASHELP.CARS.
NOTE: The data set WORK.X1 has 428 observations and 3 variables.
-------------
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;P&gt;For a much larger dataset I would not be surprised if PROC SORT was the most efficient approach to sorting.&lt;/P&gt;</description>
      <pubDate>Sun, 10 May 2020 11:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646491#M193408</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-05-10T11:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Hash not working while sorting a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646498#M193414</link>
      <description>it is working seamleasly .&lt;BR /&gt;&lt;BR /&gt;thank u</description>
      <pubDate>Sun, 10 May 2020 11:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-not-working-while-sorting-a-data-set/m-p/646498#M193414</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2020-05-10T11:47:41Z</dc:date>
    </item>
  </channel>
</rss>

