<?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 Objects Find Greater than in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811455#M320065</link>
    <description>&lt;P&gt;My program showed the tools you need, but I am uncertain as to what you want the output to look like.&amp;nbsp; Show that to get a better response.&lt;/P&gt;</description>
    <pubDate>Wed, 04 May 2022 14:05:58 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-05-04T14:05:58Z</dc:date>
    <item>
      <title>Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811388#M320027</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In hash programming is there a way to find/lookup for keys which has greater than or less than the hashkey, instead of equal to?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example: in the below code output we have the final dataset created id&amp;nbsp;roll=2. I would like to know if there is a way to create the final dataset with data where roll&amp;gt;2 or roll&amp;lt;2 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;BR /&gt;input roll ;&lt;BR /&gt;cards;&lt;BR /&gt;1 &lt;BR /&gt;2 &lt;BR /&gt;4 &lt;BR /&gt;6 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data final;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;declare hash aa();&lt;BR /&gt;aa.definekey('roll');&lt;BR /&gt;aa.definedata('dat');&lt;BR /&gt;aa.definedone();&lt;BR /&gt;roll=2;&lt;BR /&gt;dat="Match";&lt;BR /&gt;aa.add();&lt;BR /&gt;end;&lt;BR /&gt;set one;&lt;BR /&gt;if aa.find() =0 then output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Mushy&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 08:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811388#M320027</guid>
      <dc:creator>Mushy</dc:creator>
      <dc:date>2022-05-04T08:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811396#M320029</link>
      <description>&lt;P&gt;It can be done but it is an unusual requirement with hash objects.&lt;/P&gt;
&lt;P&gt;You set the variable 'dat' to missing and replace the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if aa.find() =0 then output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;as&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if aa.find() NE 0 then output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 09:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811396#M320029</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2022-05-04T09:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811398#M320031</link>
      <description>&lt;P&gt;Hello Datasp,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the response!&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;the solution&amp;nbsp;provided by you:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if aa.find() NE 0 then output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;will produce output table with records where the key is not matching ie. all records which doesnt have roll=2, but i need all those greater that roll=2.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Mushy&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 09:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811398#M320031</guid>
      <dc:creator>Mushy</dc:creator>
      <dc:date>2022-05-04T09:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811399#M320032</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;In hash programming is there a way to find/lookup for keys which has greater than or less than the hashkey, instead of equal to?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, this is not possible. At least not without using a loop to query the hash object multiple times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you describe your task in more details? Most likely someone will suggest something helpful.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 10:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811399#M320032</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-05-04T10:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811403#M320034</link>
      <description>&lt;P&gt;Hello Andreas,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for responding!&lt;/P&gt;
&lt;P&gt;Indeed, the intention is to try to replace sql queries with selection criteria with different operators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Mushy&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 10:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811403#M320034</guid>
      <dc:creator>Mushy</dc:creator>
      <dc:date>2022-05-04T10:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811412#M320039</link>
      <description>&lt;P&gt;You could use a hash, and even better, a temporary array, if the space of valid keys is known beforehand. In your case, it is the numbers on dice, so 1 to 6.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
set have;
array lookup {1:6} $ _temporary_ ('low','match','greater','greater','greater','greater');
match = lookup{roll};
run;

data want2;
if 0 then set have;
if _n_ = 1
then do;
  declare hash lookup ();
  lookup.definekey("roll");
  lookup.definedata("next_lower","next_greater");
  lookup.definedone();
  do roll = 1 to 6;
    if roll lt 2
    then do;
      next_lower = 0;
      next_greater = 2;
    end;
    else if roll = 2
    then do;
      next_lower = 2;
      next_greater = 2;
    end;
    else do;
      next_lower = 2;
      next_greater = 99;
    end;
    rc = lookup.add();
  end;
end;
set have;
rc = lookup.find();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can find two variables (like I did in the second step) by using two arrays, and you can, of course, use only one target variable in the hash.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 11:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811412#M320039</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-04T11:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811435#M320048</link>
      <description>&lt;P&gt;In your original post you wanted roll &amp;lt; 2 and roll &amp;gt; 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your choice is to get one output data set when roll &amp;gt; 2 OR if you want it for roll &amp;lt; 2 here is one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let choice = &amp;gt;;
data final;
if _n_=1 then do;
declare hash aa();
aa.definekey('roll');
aa.definedata('dat');
aa.definedone();
roll=2;
dat="Match";
aa.add();
p_roll = roll;
drop p_roll;
end;
call missing(dat);
set one;
if roll &amp;amp;choice. p_roll and 
   aa.find() ne 0 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want for roll &amp;lt; 2, change the macro variable into "&amp;lt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want for roll &amp;lt; 2 and roll &amp;gt; 2 in one data step here is a way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lower upper;
if _n_=1 then do;
declare hash aa();
aa.definekey('roll');
aa.definedata('dat');
aa.definedone();
roll=2;
dat="Match";
aa.add();
p_roll = roll;
drop p_roll;
end;
call missing(dat);
set one;
if roll &amp;gt; p_roll and 
   aa.find() ne 0 then output upper;
else if roll &amp;lt; p_roll and
   aa.find() ne 0 then output lower;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2022 13:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811435#M320048</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2022-05-04T13:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811454#M320064</link>
      <description>&lt;P&gt;Use the "ordered" feature of hash objects, plus a hash iterator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand your goal to be to find all the keys greater than some test value.&amp;nbsp; Here are 3 test values 2,5, and 7, with a report of all ROLL values greater than the test:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input roll @@;
cards;
1  2  4  6
run;

data want;
  if 0 then set one;
  declare hash h (dataset:'one',ordered:'a');
    h.definekey('roll');
    h.definedata('roll');
    h.definedone();
  declare hiter hi ('h');

  do test=2,5,7;
    put test=;
    do rc=hi.last() by 0 while (roll&amp;gt;test and rc=0);
      put +3 roll= ;
      rc=hi.prev();
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2022 14:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811454#M320064</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-04T14:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811455#M320065</link>
      <description>&lt;P&gt;My program showed the tools you need, but I am uncertain as to what you want the output to look like.&amp;nbsp; Show that to get a better response.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 14:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811455#M320065</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-04T14:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811606#M320140</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461" target="_blank"&gt;mkeintz&lt;/A&gt;&amp;nbsp;and Kurt for helping me out with possible solutions. The solution I was looking for was an equivalent of an sql statement with a where condition &amp;gt; or &amp;lt; .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Mushy&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 06:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811606#M320140</guid>
      <dc:creator>Mushy</dc:creator>
      <dc:date>2022-05-05T06:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Hash Objects Find Greater than</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811616#M320143</link>
      <description>&lt;P&gt;You may want to support my recent Ballot Idea:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Provide-Sequential-Search-Capability-for-Hash-Objects/idi-p/811615" target="_blank" rel="noopener"&gt;Provide Sequential Search Capability for Hash Objects&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 08:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-Objects-Find-Greater-than/m-p/811616#M320143</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-05T08:07:34Z</dc:date>
    </item>
  </channel>
</rss>

