<?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: merge two data sets in macro using proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409663#M100092</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58152"&gt;@panpan1215&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the reply but it still gives me errors.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt; ERROR: The following columns were not found in the contributing tables&lt;/SPAN&gt;"&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Was that the complete error or did it list the actual variables (Strongly suspect Yes)&lt;/P&gt;
&lt;P&gt;This error message is very clear: your code is referencing something in the position SAS expects a variable and the value you supply is not actually a variable in the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post the log including the SQL and the error after running :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mprint symbolgen;&lt;/P&gt;
&lt;P&gt;%merge (&amp;lt;your parameters go here&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the only explicitly mentioned variable name is in the macro parameter ID that is the likely problem: the value you supplied is not an actual variable in both sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Nov 2017 22:13:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-11-01T22:13:46Z</dc:date>
    <item>
      <title>merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409651#M100082</link>
      <description>&lt;P&gt;Hi all! I'm write a macro to merge two datasets by their ID. Each subject has multiple IDs, so the variable name has to be passed as an argument in the macro. Here's my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro merge(data1 =, data2 =, ID =, new=, );
	proc sql;
	create table &amp;amp;new AS	
		Select *
		from &amp;amp;data1 as a Full join &amp;amp;data2 as b on &amp;amp;data1&amp;amp;ID = &amp;amp;data2&amp;amp;ID;
quit;
run;
%mend&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;May I know what went wrong? Thanks for the help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 21:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409651#M100082</guid>
      <dc:creator>panpan1215</dc:creator>
      <dc:date>2017-11-01T21:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409654#M100085</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;merge&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;data1 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; data2 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; new&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;new AS	
		&lt;SPAN class="token statement"&gt;Select&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;
		&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;data1 as a Full join &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;data2 as b on a.&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; b.&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Nov 2017 21:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409654#M100085</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-11-01T21:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409661#M100090</link>
      <description>&lt;P&gt;Thanks for the reply but it still gives me errors.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt; ERROR: The following columns were not found in the contributing tables&lt;/SPAN&gt;"&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 22:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409661#M100090</guid>
      <dc:creator>panpan1215</dc:creator>
      <dc:date>2017-11-01T22:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409663#M100092</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58152"&gt;@panpan1215&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the reply but it still gives me errors.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt; ERROR: The following columns were not found in the contributing tables&lt;/SPAN&gt;"&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Was that the complete error or did it list the actual variables (Strongly suspect Yes)&lt;/P&gt;
&lt;P&gt;This error message is very clear: your code is referencing something in the position SAS expects a variable and the value you supply is not actually a variable in the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post the log including the SQL and the error after running :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mprint symbolgen;&lt;/P&gt;
&lt;P&gt;%merge (&amp;lt;your parameters go here&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the only explicitly mentioned variable name is in the macro parameter ID that is the likely problem: the value you supplied is not an actual variable in both sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 22:13:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409663#M100092</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-01T22:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409670#M100094</link>
      <description>&lt;P&gt;Okay and thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My invoke the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%merge(data1 = Mainp, data2 = Cross, ID = siteID, new= test);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And it displays&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;ERROR: The following columns were not found in the contributing tables: CrossiteID,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Main&lt;/SPAN&gt;&lt;SPAN&gt;siteID.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you notice that my two datasets are called Cross and Main. Some how the macro concatenate data name and variable name.&amp;nbsp; I used&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A id="link_13" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64404" target="_self"&gt;SAS_inquisitive&lt;/A&gt;'s suggestion to write the macro. Please see reference above. Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 22:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409670#M100094</guid>
      <dc:creator>panpan1215</dc:creator>
      <dc:date>2017-11-01T22:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409675#M100096</link>
      <description>&lt;P&gt;And where is the log generated with the MPRINT option?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately just because you say you used &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64404"&gt;@SAS_inquisitive&lt;/a&gt;'s suggestion we cannot verify that you spelled everything correctly.&lt;/P&gt;
&lt;P&gt;The log would show us that.&lt;/P&gt;
&lt;P&gt;Your error message strongly suggests that you used&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from &amp;amp;data1 as a Full join &amp;amp;data2 as b on &amp;amp;data1&amp;amp;ID = &amp;amp;data2&amp;amp;ID;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from your original code&lt;/P&gt;
&lt;P&gt;and not the suggested&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from &amp;amp;data1 as a Full join &amp;amp;data2 as b on a.&amp;amp;ID = b.&amp;amp;ID;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you had an error on compiling and it did not replace the original macro that failed.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 22:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409675#M100096</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-01T22:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409677#M100098</link>
      <description>&lt;P&gt;You have too many commas in the %MACRO statement.&lt;/P&gt;
&lt;P&gt;You are missing a semi-colon after the %MEND statement.&lt;/P&gt;
&lt;P&gt;You have an unneeded/unwanted RUN statement.&lt;/P&gt;
&lt;P&gt;But your biggest mistake is trying to use the macro variables as the dataset aliases in your ON clause instead of the A and B aliases that specifically created in the FROM and FULL JOIN clauses.&amp;nbsp; The whole purpose of added the AS A and AS B to the query is you can use A. and B. to tell SQL which dataset the variable you are referencing is coming from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro merge
(data1=
,data2=
,ID=
,new=
);
proc sql;
create table &amp;amp;new AS	
  select *
  from &amp;amp;data1 as a 
  full join &amp;amp;data2 as b 
    on a.&amp;amp;ID = b.&amp;amp;ID
;
quit;
%mend merge;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Nov 2017 23:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409677#M100098</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-01T23:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409716#M100120</link>
      <description>&lt;P&gt;Keep in mind that your SQL is sloppy programming. By using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select *&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and assuming the same key variable in both datasets, you will always get a WARNING from the SQL, and a batch job including that macro will always end with a minimum return code of 1. Since you'll be forced to ignore a return code 1 (or a WARNING in the EG/SAS Studio log), you will sooner or later miss another WARNING that should be of interest for you.&lt;/P&gt;
&lt;P&gt;It's also fact that schedulers consider any non-zero return code as a problem and flag your job as defective.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 07:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409716#M100120</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-02T07:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409915#M100190</link>
      <description>&lt;P&gt;I'm new to sas community and I will be more mindful of posting all the relevant information the next time. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 16:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409915#M100190</guid>
      <dc:creator>panpan1215</dc:creator>
      <dc:date>2017-11-02T16:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409927#M100195</link>
      <description>Hi! I did notice whenever I write code about join, there's always a warning about some variable already exist in the dataset. Would you mind showing me how to write this without generating warning message? Thanks.</description>
      <pubDate>Thu, 02 Nov 2017 16:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409927#M100195</guid>
      <dc:creator>panpan1215</dc:creator>
      <dc:date>2017-11-02T16:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409943#M100198</link>
      <description>&lt;P&gt;You have to select&amp;nbsp; that variable from either one of the data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;like select a.variable,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;a is alias for that data set .&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 17:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409943#M100198</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-11-02T17:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: merge two data sets in macro using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409994#M100209</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58152"&gt;@panpan1215&lt;/a&gt; wrote:&lt;BR /&gt;Hi! I did notice whenever I write code about join, there's always a warning about some variable already exist in the dataset. Would you mind showing me how to write this without generating warning message? Thanks.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is a side-effect of using the asterisk in select. If variables with the same name are present in both datasets, only one will be taken, and a WARNING given because of the possible loss of information. The way to avoid this is to explicitly name all variables that shall be included in the output.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 20:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-data-sets-in-macro-using-proc-sql/m-p/409994#M100209</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-02T20:02:18Z</dc:date>
    </item>
  </channel>
</rss>

