<?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: How to pass more than 2 Macro Variables as KEY to Hash Object in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227774#M41069</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let keys = 'Name', 'Account_Number';
data _null_;
  if _n_ = 1 then do;
    if 0 then set Some_Data_Set;
    declare hash h();
    h.definekey(&amp;amp;keys.);
    h.definedata(&amp;amp;keys.);
    h.definedone();
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;would be the clean way to pass those values&amp;nbsp;imho.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2015 22:11:44 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2015-09-29T22:11:44Z</dc:date>
    <item>
      <title>How to pass more than 2 Macro Variables as KEY to Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227697#M41044</link>
      <description>&lt;P&gt;I want to pass two or more macro variables as Key to a hash object.&lt;/P&gt;&lt;P&gt;%let KEY = Name Account_Number;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if _n_ = 1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if 0 then set Some_Data_Set;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; declare hash h();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; h.definekey("&amp;amp;KEY");&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; h.definedata("&amp;amp;KEY");&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; h.definedone();&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;The following is the error.&lt;/P&gt;&lt;P&gt;ERROR: Undeclared key symbol name account_number for hash object at line 2158 column 7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 15:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227697#M41044</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2015-09-29T15:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass more than 2 Macro Variables as KEY to Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227709#M41049</link>
      <description>&lt;P&gt;In this case, it would be appropriate for you to do the first half of the work.&amp;nbsp; Show us what the final program would look like if you were not using macro language, but just hard-coding the whole thing.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 16:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227709#M41049</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-09-29T16:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass more than 2 Macro Variables as KEY to Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227765#M41067</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I believe the issue here is syntax. Try setting your macro variable like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; KEY = Name", "Account_Number;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1"&gt;definekey and definedata are expecting each key and data variable to be surrounded by quotes and separated by a comma.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 21:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227765#M41067</guid>
      <dc:creator>michelle_delaurentis_sas_com</dc:creator>
      <dc:date>2015-09-29T21:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass more than 2 Macro Variables as KEY to Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227774#M41069</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let keys = 'Name', 'Account_Number';
data _null_;
  if _n_ = 1 then do;
    if 0 then set Some_Data_Set;
    declare hash h();
    h.definekey(&amp;amp;keys.);
    h.definedata(&amp;amp;keys.);
    h.definedone();
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;would be the clean way to pass those values&amp;nbsp;imho.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 22:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227774#M41069</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2015-09-29T22:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass more than 2 Macro Variables as KEY to Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227777#M41072</link>
      <description>&lt;P&gt;Michelle:&lt;/P&gt;&lt;P&gt;Your solution works. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ChrisNZ:&lt;/P&gt;&lt;P&gt;Your solution works too. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found that the KEY has also to be used in KEEP= SET option. I wanted to use in "data out(keep = &amp;amp;KEY);" . Both your suggestions will&lt;/P&gt;&lt;P&gt;not directly work. I found it convenient to split the KEY into two:&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let key1 = name;&lt;/P&gt;&lt;P&gt;%let key2 = account_number;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then I used&lt;/P&gt;&lt;P&gt;h.definekey("&amp;amp;key1", "&amp;amp;key2");&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 22:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227777#M41072</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2015-09-29T22:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass more than 2 Macro Variables as KEY to Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227878#M41102</link>
      <description>&lt;P&gt;I completely agree with ChrisNZ, much cleaner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One additional point...you can use call missing for any variables that are defined as data in the hash if they do not exist anywhere else in the data step, to avoid the warning you get in the log for undefined variables.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 17:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227878#M41102</guid>
      <dc:creator>michelle_delaurentis_sas_com</dc:creator>
      <dc:date>2015-09-30T17:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass more than 2 Macro Variables as KEY to Hash Object</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227900#M41109</link>
      <description>&lt;P&gt;Personally I have a utility macro that I use for things like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let KEY = Name Account_Number;
%put %qlist(&amp;amp;key);
('Name','Account_Number')


 h.definekey%qlist(&amp;amp;KEY);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2015 19:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-more-than-2-Macro-Variables-as-KEY-to-Hash-Object/m-p/227900#M41109</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-30T19:00:35Z</dc:date>
    </item>
  </channel>
</rss>

