<?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 tables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/644923#M22015</link>
    <description>thanks, both of yours solutions really helped</description>
    <pubDate>Mon, 04 May 2020 07:56:10 GMT</pubDate>
    <dc:creator>Ram_s</dc:creator>
    <dc:date>2020-05-04T07:56:10Z</dc:date>
    <item>
      <title>Hash tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642486#M21863</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got two tables like&lt;/P&gt;&lt;P&gt;data pos;&lt;BR /&gt;input date :mmddyy. positive;&lt;BR /&gt;format date yymmdd10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1/12/2014 0&lt;BR /&gt;1/13/2014 1&lt;BR /&gt;1/14/2014 0&lt;BR /&gt;1/15/2014 0&lt;BR /&gt;1/16/2014 0&lt;BR /&gt;1/17/2014 1&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data dat;&lt;BR /&gt;input datee :mmddyy. cnt;&lt;BR /&gt;format datee yymmdd10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1/12/2014 23&lt;BR /&gt;1/14/2014 32&lt;BR /&gt;1/16/2014 54&lt;BR /&gt;1/15/2014 21&lt;BR /&gt;1/15/2014 34&lt;BR /&gt;1/13/2014 42&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;and i would like to join them with hash to get table like&lt;/P&gt;&lt;P&gt;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;datee&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cnt&lt;/P&gt;&lt;P&gt;1/13/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/12/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23&lt;BR /&gt;1/17/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/14/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;32&lt;BR /&gt;1/17/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/16/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;54&lt;BR /&gt;1/17/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/15/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21&lt;BR /&gt;1/17/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/15/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;34&lt;BR /&gt;1/13/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/13/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;42&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it means to each date from dat join next date from pos with 1 on column positive.&lt;/P&gt;&lt;P&gt;By now I've got this code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data def;&lt;BR /&gt;format date yymmdd10. ;&lt;BR /&gt;length positive 8;&lt;BR /&gt;dcl hash nwd (dataset: 'pos');&lt;BR /&gt;nwd.definekey('date');&lt;BR /&gt;nwd.definedata('positive');&lt;BR /&gt;nwd.definedone();&lt;/P&gt;&lt;P&gt;do until (eof);&lt;BR /&gt;set dat end=eof;&lt;/P&gt;&lt;P&gt;rc=nwd.find(key: datee);&lt;BR /&gt;if (positive=0) then do;&lt;BR /&gt;date=date+1;&lt;BR /&gt;end;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it adds only one day.&lt;/P&gt;&lt;P&gt;Thanks for help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 09:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642486#M21863</guid>
      <dc:creator>Ram_s</dc:creator>
      <dc:date>2020-04-24T09:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642492#M21865</link>
      <description>&lt;P&gt;Why not use a SQL query?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    t2.date,
    t1.datee,
    t1.cnt
  from dat t1 left join pos (where=(positive)) t2
  on t1.datee le t2.date
  group by t1.datee
  having t2.date = min(t2.date)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;1	2014-01-13	2014-01-12	23	
2	2014-01-13	2014-01-13	42	
3	2014-01-17	2014-01-14	32	
4	2014-01-17	2014-01-15	34	
5	2014-01-17	2014-01-15	21	
6	2014-01-17	2014-01-16	54	
&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 09:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642492#M21865</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-24T09:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642493#M21866</link>
      <description>&lt;P&gt;My 2 cents&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = rc);
   if _N_ = 1 then do;
      declare hash h (dataset : 'pos(where=(positive=1))', ordered : 'A');
      h.definekey ('date');
      h.definedone ();
      declare hiter hi ('h');
   end;

   set dat;
   date = .;

   do until (date &amp;gt;= datee);
      rc = hi.next();
   end;

   format date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;datee       cnt date 
2014-01-12  23  2014-01-13 
2014-01-14  32  2014-01-17 
2014-01-16  54  2014-01-17 
2014-01-15  21  2014-01-17 
2014-01-15  34  2014-01-17 
2014-01-13  42  2014-01-13 &lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 09:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642493#M21866</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-04-24T09:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642495#M21867</link>
      <description>&lt;P&gt;My idea for using a hash:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select max(date) into :maxdate from pos
where positive;
quit;

data want;
set dat;
if _n_ =1
then do;
  declare hash pos (dataset:"pos (where=(positive))");
  pos.definekey("date");
  pos.definedone();
  format date yymmddd10.;
end;
date = datee;
do while (pos.find() ne 0 and date &amp;lt;= &amp;amp;maxdate);
  date + 1;
end;
if date &amp;gt; &amp;amp;maxdate
then do;
  date = .;
  put "no date found:" datee= cnt=;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 09:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642495#M21867</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-24T09:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642557#M21874</link>
      <description>&lt;P&gt;Good morning&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312479"&gt;@Ram_s&lt;/a&gt;&amp;nbsp;, If I understand you correctly, your approach basically loads the entire table "pos" in Hash memory resident table with values 0's and 1's. Are you trying to do something like &lt;EM&gt;Key enumerate&lt;/EM&gt; and &lt;EM&gt;Enumerate all&lt;/EM&gt; as a combination? Perhaps for some learning purpose or does the business mandate to ride from key enumerate find and pick the immediate available date in succession that occurs after the datee?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The logic seemingly makes me concur with approach of others in only loading positive=1 records in the Hash table, albeit your approach made me wonder whether your appetite for learning stretches to what methinks is likely the case. Otherwise, please ignore by all means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just tweaked your code with the above stated assumption:-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pos;
input date :mmddyy. positive;
format date yymmdd10.;
datalines;
1/12/2014 0
1/13/2014 1
1/14/2014 0
1/15/2014 0
1/16/2014 0
1/17/2014 1
;

data dat;
input datee :mmddyy. cnt;
format datee yymmdd10.;
datalines;
1/12/2014 23
1/14/2014 32
1/16/2014 54
1/15/2014 21
1/15/2014 34
1/13/2014 42
;

data def;
 dcl hash nwd (dataset: 'pos',ordered:'y');
 nwd.definekey('date');
 nwd.definedata('date','positive');
 nwd.definedone();
 dcl hiter nht('nwd');
 do until (eof);
  set dat end=eof;
  do rc=nht.setcur(key:datee) by 0 while(rc=0 and not positive);
   rc=nht.next();
  end;
  output;
 end;
 stop;
 set pos;
 drop rc;
run;

proc print noobs;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.DEF" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;datee&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;cnt&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;positive&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;date&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2014-01-12&lt;/TD&gt;
&lt;TD class="r data"&gt;23&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2014-01-13&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2014-01-14&lt;/TD&gt;
&lt;TD class="r data"&gt;32&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2014-01-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2014-01-16&lt;/TD&gt;
&lt;TD class="r data"&gt;54&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2014-01-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2014-01-15&lt;/TD&gt;
&lt;TD class="r data"&gt;21&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2014-01-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2014-01-15&lt;/TD&gt;
&lt;TD class="r data"&gt;34&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2014-01-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2014-01-13&lt;/TD&gt;
&lt;TD class="r data"&gt;42&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2014-01-13&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 12:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/642557#M21874</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-24T12:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/644922#M22014</link>
      <description>thanks, it works properly</description>
      <pubDate>Mon, 04 May 2020 07:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/644922#M22014</guid>
      <dc:creator>Ram_s</dc:creator>
      <dc:date>2020-05-04T07:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/644923#M22015</link>
      <description>thanks, both of yours solutions really helped</description>
      <pubDate>Mon, 04 May 2020 07:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hash-tables/m-p/644923#M22015</guid>
      <dc:creator>Ram_s</dc:creator>
      <dc:date>2020-05-04T07:56:10Z</dc:date>
    </item>
  </channel>
</rss>

