<?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: joins in Datastep issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/joins-in-Datastep-issue/m-p/875757#M346032</link>
    <description>&lt;P&gt;If you use multiple variables in a BY statement,&amp;nbsp;&lt;U&gt;all&lt;/U&gt; of them need to be contained in&amp;nbsp;&lt;U&gt;all&lt;/U&gt; datasets used in the MERGE.&lt;/P&gt;</description>
    <pubDate>Mon, 15 May 2023 08:41:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-05-15T08:41:34Z</dc:date>
    <item>
      <title>joins in Datastep issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joins-in-Datastep-issue/m-p/875736#M346024</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
input value1;
datalines;
1
2
3
5
;
run;


data table2;
input value2;
datalines;
1
2
4
;
run;


/*Scenario:1 Join columns having unique values */

/*Merge with Datastep*/

proc sort data=table1;
by value1;
run;


proc sort data=table2;
by value2;
run;



/* inner join with Datastep */
data innerjoin;
merge table1(in=a) table2(in=b);
by value1 value2;
if a and b;
proc print noobs;
run;

/* inner join with proc sql */

proc sql;
select t1.value1, t2.value2
from table1 t1 
inner join 
     table2 t2
on t1.value1=t2.value2;
quit;


/* left join with Datastep */
data leftjoin;
merge table1(in=a) table2(in=b);
by value1 value2;
if a then output;
proc print noobs;
run;


proc sql;
select t1.value1,t2.value2
from table1 t1
left join
     table2 t2
on t1.value1=t2.value2;
quit;

/* right join with Datastep */

data rightjoin;
merge table1(in=a) table2(in=b);
by value1 value2;
if b then output;
proc print noobs;
run;


/* right join proc sql */

proc sql;
select t1.value1 ,t2.value2
from table1 t1
right join 
     table2 t2
on t1.value1=t2.value2;
quit;


/* full join with Datastep */
data fulljoin;
merge table1(in=a) table2(in=b);
by value1 value2;
proc print noobs;
run;

/* full join proc sql */

proc sql;
select t1.value1,t2.value2
from table1 t1
full join
     table2 t2
on t1.value1=t2.value2;     
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;using data step merge for joins i am getting below error&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anandkvn_0-1684130874736.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83971iE8BAF59626AC9E54/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Anandkvn_0-1684130874736.png" alt="Anandkvn_0-1684130874736.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 06:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joins-in-Datastep-issue/m-p/875736#M346024</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2023-05-15T06:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: joins in Datastep issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joins-in-Datastep-issue/m-p/875749#M346028</link>
      <description>&lt;P&gt;You need to use the same 'by' variables in your dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* inner join with Datastep */
data innerjoin;
merge table1(in=a) table2(in=b rename=(value2=value1));
by value1;
if a and b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 May 2023 07:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joins-in-Datastep-issue/m-p/875749#M346028</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-15T07:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: joins in Datastep issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joins-in-Datastep-issue/m-p/875757#M346032</link>
      <description>&lt;P&gt;If you use multiple variables in a BY statement,&amp;nbsp;&lt;U&gt;all&lt;/U&gt; of them need to be contained in&amp;nbsp;&lt;U&gt;all&lt;/U&gt; datasets used in the MERGE.&lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 08:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joins-in-Datastep-issue/m-p/875757#M346032</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-15T08:41:34Z</dc:date>
    </item>
  </channel>
</rss>

