<?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 Conditionally Concatenate 2 Tables in a DATA step with two library names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503208#M134416</link>
    <description>&lt;P&gt;In a data step I would like to conditionally concatenate (stack) two SAS tables.&amp;nbsp; One of the tables may not always be created and would not need to be stacked.&amp;nbsp; When I have a blank library or table name, I am getting errors.&amp;nbsp; Here is the sample code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME LIB1 "Filepath";
LIBNAME LIB2 "";
%LET LIB1_TABLE = table_name;
%LET LIB2_TABLE = ;
%LET USE_LIB2 = N;

DATA STACK_TEST;
IF "&amp;amp;USE_LIB1" = "Y" THEN SET LIB1.&amp;amp;LIB1_TABLE. LIB2.&amp;amp;LIB2_TABLE.;
ELSE SET LIB1.&amp;amp;LIB1_TABLE.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;With this setup, I would expect the code to revert to the else portion of the "if-then-else" but I get errors in my log.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET LIB1_TABLE = table_name;&lt;BR /&gt;%LET LIB2_TABLE = ;&lt;BR /&gt;%LET USE_LIB2 = N;&lt;BR /&gt;&lt;BR /&gt;DATA STACK_TEST;&lt;BR /&gt;IF "&amp;amp;USE_LIB2" = "Y" THEN SET LIB1.&amp;amp;LIB1_TABLE. LIB2.&amp;amp;LIB2_TABLE.;&lt;BR /&gt;NOTE: Line generated by the macro variable "LIB2_TABLE".&lt;BR /&gt;LIB2.&lt;BR /&gt;_____&lt;BR /&gt;22&lt;BR /&gt;201&lt;BR /&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY,&lt;BR /&gt;KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;ERROR 201-322: The option is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;ELSE SET LIB1.&amp;amp;LIB1_TABLE.;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does someone have a solution on how to go about conditionally concatenating the two tables in a data step when one of the libraries is not populated because the table does not exist?&amp;nbsp; I am using SAS Enterprise Guide 6.1 (64-bit). I need to perform other tasks within this data step after getting the data from the table(s) which is why I am not using the Append procedure.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Oct 2018 19:17:04 GMT</pubDate>
    <dc:creator>Philmingo</dc:creator>
    <dc:date>2018-10-10T19:17:04Z</dc:date>
    <item>
      <title>Conditionally Concatenate 2 Tables in a DATA step with two library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503208#M134416</link>
      <description>&lt;P&gt;In a data step I would like to conditionally concatenate (stack) two SAS tables.&amp;nbsp; One of the tables may not always be created and would not need to be stacked.&amp;nbsp; When I have a blank library or table name, I am getting errors.&amp;nbsp; Here is the sample code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME LIB1 "Filepath";
LIBNAME LIB2 "";
%LET LIB1_TABLE = table_name;
%LET LIB2_TABLE = ;
%LET USE_LIB2 = N;

DATA STACK_TEST;
IF "&amp;amp;USE_LIB1" = "Y" THEN SET LIB1.&amp;amp;LIB1_TABLE. LIB2.&amp;amp;LIB2_TABLE.;
ELSE SET LIB1.&amp;amp;LIB1_TABLE.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;With this setup, I would expect the code to revert to the else portion of the "if-then-else" but I get errors in my log.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET LIB1_TABLE = table_name;&lt;BR /&gt;%LET LIB2_TABLE = ;&lt;BR /&gt;%LET USE_LIB2 = N;&lt;BR /&gt;&lt;BR /&gt;DATA STACK_TEST;&lt;BR /&gt;IF "&amp;amp;USE_LIB2" = "Y" THEN SET LIB1.&amp;amp;LIB1_TABLE. LIB2.&amp;amp;LIB2_TABLE.;&lt;BR /&gt;NOTE: Line generated by the macro variable "LIB2_TABLE".&lt;BR /&gt;LIB2.&lt;BR /&gt;_____&lt;BR /&gt;22&lt;BR /&gt;201&lt;BR /&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY,&lt;BR /&gt;KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;ERROR 201-322: The option is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;ELSE SET LIB1.&amp;amp;LIB1_TABLE.;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does someone have a solution on how to go about conditionally concatenating the two tables in a data step when one of the libraries is not populated because the table does not exist?&amp;nbsp; I am using SAS Enterprise Guide 6.1 (64-bit). I need to perform other tasks within this data step after getting the data from the table(s) which is why I am not using the Append procedure.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 19:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503208#M134416</guid>
      <dc:creator>Philmingo</dc:creator>
      <dc:date>2018-10-10T19:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Concatenate 2 Tables in a DATA step with two library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503211#M134417</link>
      <description>&lt;P&gt;something like this can help i think&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
LIBNAME LIB1 "Filepath";
LIBNAME LIB2 "";
%LET LIB1_TABLE = table_name;
%LET LIB2_TABLE = ;
%LET USE_LIB2 = N;
%macro t;
DATA STACK_TEST;
%IF &amp;amp;USE_LIB1 = Y %THEN %str(SET LIB1.&amp;amp;LIB1_TABLE. LIB2.&amp;amp;LIB2_TABLE.;);
%ELSE %str(SET LIB1.&amp;amp;LIB1_TABLE.;);
RUN;
%mend t;
%t
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Oct 2018 19:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503211#M134417</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-10T19:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Concatenate 2 Tables in a DATA step with two library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503220#M134421</link>
      <description>&lt;P&gt;IFC nested in SYSFUNC would be my prescription:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data stack_test;
   set lib1.&amp;amp;lib1_table  %sysfunc(ifc(&amp;amp;use_lib2=Y,lib2.&amp;amp;lib2_table,));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%sysfunc around IFN or IFC is a great way to do the equivalent of a macro %IF test in open code.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 19:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503220#M134421</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-10T19:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Concatenate 2 Tables in a DATA step with two library names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503228#M134427</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp; Your solution is exactly what I was looking for.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 20:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Concatenate-2-Tables-in-a-DATA-step-with-two/m-p/503228#M134427</guid>
      <dc:creator>Philmingo</dc:creator>
      <dc:date>2018-10-10T20:17:26Z</dc:date>
    </item>
  </channel>
</rss>

