<?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: Key hash variable does not exist in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232243#M42313</link>
    <description>&lt;P&gt;yes this will help in case I have to search the same variabe, but if i need to search a different variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To be more precise. Let's say I have the following syntax:&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if _n_=1 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&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;call missing(age);&lt;BR /&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; declare hash pr(dataset:"sashelp.class");&lt;BR /&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; pr.definekey('age');&lt;BR /&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; pr.definedata('name');&lt;BR /&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; pr.definedone();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&lt;BR /&gt;rc=pr.find(key:age_search);&lt;BR /&gt;if rc eq 0 then x=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At one moment somebody changes the database and the variable &lt;STRONG&gt;age_search&lt;/STRONG&gt; is no more present in the database &lt;STRONG&gt;have&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;How can I force SAS to drop a note or even stop so I can change the program before the users see the incorect results .&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2015 15:54:18 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2015-10-29T15:54:18Z</dc:date>
    <item>
      <title>Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232233#M42310</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I force SAS to throw a message , a note or anything to make me careful in case I use, &lt;STRONG&gt;by mistake&lt;/STRONG&gt;, a variable&lt;/P&gt;&lt;P&gt;in hash find method, variable which does not exist in data step.&lt;/P&gt;&lt;P&gt;Consider the following example (only to better explain my question):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;if _n_=1 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&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; declare hash pr(dataset:"sashelp.class");&lt;BR /&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; pr.definekey('age');&lt;BR /&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; pr.definedata('name');&lt;BR /&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; pr.definedone();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&lt;BR /&gt;rc=pr.find(key:agee);&lt;BR /&gt;if rc eq 0 then x=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS does not throw any note, message in the log. It only creates the numeric variable agee which is missing and as a consequence nothing is find in hash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simple way , maybe an option or something similar, to identify such typing mistakes ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;10x&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 15:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232233#M42310</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2015-10-29T15:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232238#M42311</link>
      <description>pr.find()</description>
      <pubDate>Thu, 29 Oct 2015 15:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232238#M42311</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-10-29T15:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232243#M42313</link>
      <description>&lt;P&gt;yes this will help in case I have to search the same variabe, but if i need to search a different variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To be more precise. Let's say I have the following syntax:&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if _n_=1 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&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;call missing(age);&lt;BR /&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; declare hash pr(dataset:"sashelp.class");&lt;BR /&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; pr.definekey('age');&lt;BR /&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; pr.definedata('name');&lt;BR /&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; pr.definedone();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&lt;BR /&gt;rc=pr.find(key:age_search);&lt;BR /&gt;if rc eq 0 then x=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At one moment somebody changes the database and the variable &lt;STRONG&gt;age_search&lt;/STRONG&gt; is no more present in the database &lt;STRONG&gt;have&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;How can I force SAS to drop a note or even stop so I can change the program before the users see the incorect results .&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 15:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232243#M42313</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2015-10-29T15:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232254#M42316</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33792"&gt;@Loko&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS does not throw any note, message in the log. It only creates the numeric variable agee which is missing and as a consequence nothing is find in hash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;SAS is just a software, so it does what it&amp;nbsp;is told and it can't read your mind. In your case, SAS does not know whether or not&amp;nbsp;it is your intention to create a new variable like that.&amp;nbsp;What you are asking, I am afraid, is beyond what any software&amp;nbsp;&amp;nbsp;can offer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can, though, leverage Macro languge, to kinda get what you want . However, it still does not change SAS's behavior.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 16:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232254#M42316</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-10-29T16:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232258#M42318</link>
      <description>You can program a check for the existence of the variable AGE_SEARCH in HAVE before the data step.</description>
      <pubDate>Thu, 29 Oct 2015 16:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232258#M42318</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-10-29T16:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232262#M42321</link>
      <description>&lt;P&gt;One way though not the most robust:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   if missing(age_search) then do;
      put "ERROR: Missing value for variable age_search in dataset have";
      stop;
   end;
   if _n_=1 then
           do;
                   call missing(age);
                   declare hash pr(dataset:"sashelp.class");
                   pr.definekey('age');
                   pr.definedata('name');
                   pr.definedone();
           end;

   rc=pr.find(key:age_search);
   if rc eq 0 then x=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your data source is likely to change many of your variables then you would check for each one. The Want data set will have no observations but will be created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 16:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232262#M42321</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-10-29T16:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232386#M42359</link>
      <description>&lt;P&gt;Ok, I was affraid there is no simple for solution for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt; I don't think is about reading my mind, I believe it is just something that can be improved in SAS since , for example it can throw "Uninitialise notes" in situations like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;if xxx &amp;lt; 9 then c=9;&lt;BR /&gt;a=yyy+1;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2015 08:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232386#M42359</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2015-10-30T08:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232442#M42366</link>
      <description>&lt;P&gt;In a somewhat snarky mode, I would say if this is a production data base then however arbitrarily changes a data table needs to have a serious attitude adjustment.&lt;/P&gt;
&lt;P&gt;If you are working with a developing database then your operating&amp;nbsp;procedures should have something about when such changes are made and notification rules.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2015 14:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232442#M42366</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-10-30T14:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Key hash variable does not exist in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232450#M42368</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33792"&gt;@Loko﻿&lt;/a&gt;&amp;nbsp;In light of your example, I agree that it does seem to have some inconsistency here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2015 15:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-hash-variable-does-not-exist-in-data-set/m-p/232450#M42368</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-10-30T15:04:20Z</dc:date>
    </item>
  </channel>
</rss>

