<?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 proc sql left join if data set  is not exisiting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-if-data-set-is-not-exisiting/m-p/785682#M250782</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to perform left join via proc sql&amp;nbsp; and it might happen the the data set&amp;nbsp; is not existing.&lt;/P&gt;
&lt;P&gt;In such case I want that the wanted data set will be created without fields from non existing data set (sex,revenue).&lt;/P&gt;
&lt;P&gt;I get an error in this code,&lt;/P&gt;
&lt;P&gt;may anyone help please?&lt;/P&gt;
&lt;P&gt;ERROR: There is no matching %DO statement for the %END. This statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data AAA;
input ID X y ;
cards;
1 10 20
2 30 40
3 50 60
;
Run;


%macro RRR;
proc sql;
create table wanted as
select a.*,
        %if %sysfunc(exist(BBB)) %then %do; 
		b.revenue,
        b.Sex
		%end
from AAA as a
%if %sysfunc(exist(BBB)) %then %do;
left join BBB  as b
on a.ID=b.ID 
%end;
;
quit;
%mend RRR;
%RRR;
/*ERROR: There is no matching %DO statement for the %END. This statement will be ignored.*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Dec 2021 05:50:13 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-12-13T05:50:13Z</dc:date>
    <item>
      <title>proc sql left join if data set  is not exisiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-if-data-set-is-not-exisiting/m-p/785682#M250782</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to perform left join via proc sql&amp;nbsp; and it might happen the the data set&amp;nbsp; is not existing.&lt;/P&gt;
&lt;P&gt;In such case I want that the wanted data set will be created without fields from non existing data set (sex,revenue).&lt;/P&gt;
&lt;P&gt;I get an error in this code,&lt;/P&gt;
&lt;P&gt;may anyone help please?&lt;/P&gt;
&lt;P&gt;ERROR: There is no matching %DO statement for the %END. This statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data AAA;
input ID X y ;
cards;
1 10 20
2 30 40
3 50 60
;
Run;


%macro RRR;
proc sql;
create table wanted as
select a.*,
        %if %sysfunc(exist(BBB)) %then %do; 
		b.revenue,
        b.Sex
		%end
from AAA as a
%if %sysfunc(exist(BBB)) %then %do;
left join BBB  as b
on a.ID=b.ID 
%end;
;
quit;
%mend RRR;
%RRR;
/*ERROR: There is no matching %DO statement for the %END. This statement will be ignored.*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 05:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-if-data-set-is-not-exisiting/m-p/785682#M250782</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-13T05:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql left join if data set  is not exisiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-if-data-set-is-not-exisiting/m-p/785684#M250783</link>
      <description>&lt;P&gt;You just have to get the commas and semicolons right &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data AAA;
input ID X y ;
cards;
1 10 20
2 30 40
3 50 60
;
Run;


%macro RRR;
proc sql;
create table wanted as
select a.*
        %if %sysfunc(exist(BBB)) %then %do; 
        ,b.revenue
        ,b.Sex
      %end;
from AAA as a
%if %sysfunc(exist(BBB)) %then %do;
left join BBB  as b
on a.ID=b.ID 
%end;
;
quit;
%mend RRR;

options mprint;

%RRR&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Dec 2021 06:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-if-data-set-is-not-exisiting/m-p/785684#M250783</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-12-13T06:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql left join if data set  is not exisiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-if-data-set-is-not-exisiting/m-p/785785#M250817</link>
      <description>For simplicity I'd code that differently - check if the data set exists and if it does do the join, if not then add the empty columns alone without a SQL query using base macro logic. Simpler code is easier to maintain.</description>
      <pubDate>Mon, 13 Dec 2021 16:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-left-join-if-data-set-is-not-exisiting/m-p/785785#M250817</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-13T16:16:15Z</dc:date>
    </item>
  </channel>
</rss>

