<?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: Use a macro list value to define dynamically list of keys in SQL join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481081#M286713</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Note that a join like this is bad programming practice, as it will unvariably throw a&amp;nbsp; WARNING for a variable that already exists.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jul 2018 11:24:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-07-25T11:24:02Z</dc:date>
    <item>
      <title>Use a macro list value to define dynamically list of keys in SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481073#M286711</link>
      <description>&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; example=Gender Age;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; *&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; table1 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;inner&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;join&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; table2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* i want to use &amp;amp;example in order to define dynamically the key of my join*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;on&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1.gender=t2.gender &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1.Age=t2.Age&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*******/&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&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>Wed, 25 Jul 2018 10:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481073#M286711</guid>
      <dc:creator>bebess</dc:creator>
      <dc:date>2018-07-25T10:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Use a macro list value to define dynamically list of keys in SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481075#M286712</link>
      <description>&lt;P&gt;Not easily, you would need macro code to loop over each word in the list, then generate out the on part of it.&amp;nbsp; I would question why?&amp;nbsp; If your rules are strict enough to allow a join like that, it is strict enough to just write the join and not need a macro list.&amp;nbsp; Otherwise what happens if the variable isn't in both, if its different types, if the join is correct for the data etc.&amp;nbsp; Far more problems will be created than solved by this.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 10:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481075#M286712</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-25T10:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Use a macro list value to define dynamically list of keys in SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481081#M286713</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Note that a join like this is bad programming practice, as it will unvariably throw a&amp;nbsp; WARNING for a variable that already exists.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 11:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481081#M286713</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-25T11:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Use a macro list value to define dynamically list of keys in SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481083#M286714</link>
      <description>I have all controls before doing the join , i am sure i have the same data structure between tables ( same variables with same type and format ... ) .&lt;BR /&gt;Do i need to generate by a loop the syntax : on a.first_item=b.item and a.second.item=B.item in a different macro variable then use it my sql code?</description>
      <pubDate>Wed, 25 Jul 2018 11:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481083#M286714</guid>
      <dc:creator>bebess</dc:creator>
      <dc:date>2018-07-25T11:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Use a macro list value to define dynamically list of keys in SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481086#M286715</link>
      <description>&lt;P&gt;Yes, as a start:&lt;/P&gt;
&lt;PRE&gt;%do i=1 to ...
  %let tmp=%scan(&amp;amp;example.,&amp;amp;i);
    on t1.&amp;amp;tmp.=t2.&amp;amp;tmp.
  %end;
%end;
...&lt;/PRE&gt;
&lt;P&gt;Really not worth doing though as risky, even if you have done loads of pre-checks, the logic of the join based on your data may not be what is wanted.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 11:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481086#M286715</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-25T11:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: Use a macro list value to define dynamically list of keys in SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481148#M286716</link>
      <description>&lt;P&gt;It is much easier if you just use SAS code instead of SQL code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let example=Gender Age;
data want ;
  merge table1 (in=in1) table2 (in=in2);
  by &amp;amp;example;
  if in1 and in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jul 2018 14:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481148#M286716</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-25T14:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Use a macro list value to define dynamically list of keys in SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481154#M286717</link>
      <description>Yes thanks it could be another solution , but the merge involve a sort of the 2 table , more time consuming i think ?</description>
      <pubDate>Wed, 25 Jul 2018 15:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-macro-list-value-to-define-dynamically-list-of-keys-in-SQL/m-p/481154#M286717</guid>
      <dc:creator>bebess</dc:creator>
      <dc:date>2018-07-25T15:19:55Z</dc:date>
    </item>
  </channel>
</rss>

