<?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: Check if table exists in database in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617060#M180755</link>
    <description>&lt;P&gt;Remember when pasting in text (or editing it) to use the Insert Code or Insert SAS code buttons.&lt;/P&gt;
&lt;P&gt;Try this fixed version:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check_table(db_name,table_name);
%local dsname ;
%let dsname=&amp;amp;table_name ;
%if %length(&amp;amp;db_name) %then %let dsname=&amp;amp;db_name..&amp;amp;dsname;

%if %sysfunc(exist(&amp;amp;dsname)) %then %do;
  %put Found table &amp;amp;dsname ;
  proc delete data=&amp;amp;dsname; run;
%end;
%else %do;
  %put Could not find &amp;amp;dsname ;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;827   options mprint;
828   %check_table(,abc);
Could not find abc
829   data abc;
830   run;

NOTE: The data set WORK.ABC has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


831   %check_table(,abc);
Found table abc
MPRINT(CHECK_TABLE):   proc delete data=abc;
MPRINT(CHECK_TABLE):   run;

NOTE: Deleting WORK.ABC (memtype=DATA).
NOTE: PROCEDURE DELETE used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2020 21:17:06 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-01-13T21:17:06Z</dc:date>
    <item>
      <title>Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617033#M180743</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on a code that will help determine if a table exists in a database or not. If it does, then the table is deleted, if it doesn't exist then it creates that table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname db1 teradata user="xxx" password="xxx" tdpid=rchtera mode=ansi database=xx; 


%macro check_table(db_name,table_name);
  %if %sysfunc(exist(&amp;amp;db_name.&amp;amp;table_name.)) %then %do;
    %put The table exists.;
proc sql;
 drop table (&amp;amp;db_name.&amp;amp;table_name.) ;
quit;
  %end;
  %else %do;
      %Put Table does not exist;
  %end;
%mend;

%check_table(db1,T1_data);

proc sql;
connect to teradata (user="xx" password="xx" tdpid=RCHTERA mode=teradata); 
create table db1.T1_data (FASTLOAD=YES) as 
select * from work.T1_data;
disconnect from teradata;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I test this, even though the table&amp;nbsp;&lt;CODE class=" language-sas"&gt;db1.T1_data exists, it still keeps displaying 'Table does not exist' as output. Why would the exist condition not work?&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;I also checked to see that the correct values of&amp;nbsp;&amp;amp;db_name.&amp;amp;table_name. are being passed into the macro.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;Appreciate the help in helping me understand what I'm missing!&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;Thank you.&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 20:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617033#M180743</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-01-13T20:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617041#M180745</link>
      <description>I don't think the exist function will work on an external DB. You can try and query the server metadata via the dictionary.table table depending on the server.</description>
      <pubDate>Mon, 13 Jan 2020 20:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617041#M180745</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-13T20:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617043#M180746</link>
      <description>&lt;P&gt;What I had to do to check if a Teradata table or view existed was query the Teradata metadata directly instead.&lt;/P&gt;
&lt;P&gt;Here is part of a macro I made:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*----------------------------------------------------------------------------;
* Check if table or view exists ;
*----------------------------------------------------------------------------;
select obj into :result trimmed from connection to &amp;amp;connection
  (select case when (tablekind in ('T','O')) then 'TABLE'
          else 'VIEW' end as obj
    from dbc.tablesv
    where databasename = %squote(&amp;amp;db) and tablename= %squote(&amp;amp;table)
      and tablekind in ('V','T','O')
  )
;
%let exists=&amp;amp;sqlobs;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also included code to check if there is any Volatile table with that name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (^&amp;amp;exists and &amp;amp;db=&amp;amp;userid) %then %do;
*----------------------------------------------------------------------------;
* Check for any Volatile tables ;
*----------------------------------------------------------------------------;
  select 1 into :exists from connection to &amp;amp;connection (help volatile table) ;

  %if (&amp;amp;exists) %then %do;
*----------------------------------------------------------------------------;
* Check if this Volatile table exists ;
*----------------------------------------------------------------------------;
    select 'VOLATILE TABLE' into :result
      from connection to &amp;amp;connection (help volatile table)
%*----------------------------------------------------------------------------
Set VARNAME based on VALIDVARNAME setting.
-----------------------------------------------------------------------------;
%if %sysfunc(getoption(validvarname))=ANY %then
      where upcase('table name'n) = "&amp;amp;table"
;%else
      where upcase(table_name) = "&amp;amp;table"
;
    ;
    %let exists=&amp;amp;sqlobs;
  %end;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2020 20:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617043#M180746</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-13T20:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617044#M180747</link>
      <description>Thank you!&lt;BR /&gt;I tried the same macro with the work table, but even for that it displayed that the table does not exist, even though it did. If it doesn't work on external DB, it should still work when I pass a table by work.abc</description>
      <pubDate>Mon, 13 Jan 2020 20:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617044#M180747</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-01-13T20:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617045#M180748</link>
      <description>Yes, it should work for an internal data set. Post the log from running it with an internal data set and the MPRINT/SYMBOLGEN options on.</description>
      <pubDate>Mon, 13 Jan 2020 20:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617045#M180748</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-13T20:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617047#M180750</link>
      <description>Please find the log:&lt;BR /&gt;&lt;BR /&gt;25 GOPTIONS ACCESSIBLE;&lt;BR /&gt;26 options mautosource nocenter source2 mlogic symbolgen mprint;&lt;BR /&gt;27&lt;BR /&gt;28 %macro check_table(db_name,table_name);&lt;BR /&gt;29 %if %sysfunc(exist(&amp;amp;db_name.&amp;amp;table_name.)) %then %do;&lt;BR /&gt;30 %put &amp;amp;=db_name ;&lt;BR /&gt;31 %put &amp;amp;=table_name ;&lt;BR /&gt;32 %put The table exists;&lt;BR /&gt;33 proc sql;&lt;BR /&gt;34 drop table (&amp;amp;db_name.&amp;amp;table_name.) ;&lt;BR /&gt;35 quit;&lt;BR /&gt;36 %end;&lt;BR /&gt;37 %else %do;&lt;BR /&gt;38 %put &amp;amp;=db_name ;&lt;BR /&gt;39 %put &amp;amp;=table_name ;&lt;BR /&gt;40 %Put Table does not exist;&lt;BR /&gt;41 %end;&lt;BR /&gt;42 %mend;&lt;BR /&gt;43&lt;BR /&gt;44 %check_table (work,abc);&lt;BR /&gt;MLOGIC(CHECK_TABLE): Beginning execution.&lt;BR /&gt;MLOGIC(CHECK_TABLE): Parameter DB_NAME has value work&lt;BR /&gt;MLOGIC(CHECK_TABLE): Parameter TABLE_NAME has value abc&lt;BR /&gt;SYMBOLGEN: Macro variable DB_NAME resolves to work&lt;BR /&gt;SYMBOLGEN: Macro variable TABLE_NAME resolves to abc&lt;BR /&gt;MLOGIC(CHECK_TABLE): %IF condition %sysfunc(exist(&amp;amp;db_name.&amp;amp;table_name.)) is FALSE&lt;BR /&gt;MLOGIC(CHECK_TABLE): %PUT &amp;amp;=db_name&lt;BR /&gt;SYMBOLGEN: Macro variable DB_NAME resolves to work&lt;BR /&gt;DB_NAME=work&lt;BR /&gt;2 The SAS System 13:16 Monday, January 13, 2020&lt;BR /&gt;&lt;BR /&gt;MLOGIC(CHECK_TABLE): %PUT &amp;amp;=table_name&lt;BR /&gt;SYMBOLGEN: Macro variable TABLE_NAME resolves to abc&lt;BR /&gt;TABLE_NAME=abc&lt;BR /&gt;MLOGIC(CHECK_TABLE): %PUT Table does not exist&lt;BR /&gt;Table does not exist&lt;BR /&gt;MLOGIC(CHECK_TABLE): Ending execution.&lt;BR /&gt;45&lt;BR /&gt;46</description>
      <pubDate>Mon, 13 Jan 2020 20:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617047#M180750</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-01-13T20:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617053#M180751</link>
      <description>&lt;P&gt;Your code is missing a period.&amp;nbsp; You are checking for the existence of the member named WORKABC in the default library (normally WORK) instead of checking for the member ABC in the WORK library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro processor will use the first period as an indication of where macro variable name ends.&amp;nbsp; So to include a period in the generated code you need to add another one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %sysfunc(exist(&amp;amp;db_name..&amp;amp;table_name.))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2020 20:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617053#M180751</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-13T20:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617054#M180752</link>
      <description>I tried that and it gave me this error:&lt;BR /&gt;MPRINT(CHECK_TABLE): proc sql;&lt;BR /&gt;SYMBOLGEN: Macro variable DB_NAME resolves to work&lt;BR /&gt;SYMBOLGEN: Macro variable TABLE_NAME resolves to abc&lt;BR /&gt;NOTE: Line generated by the invoked macro "CHECK_TABLE".&lt;BR /&gt;44 (&amp;amp;db_name..&amp;amp;table_name.) ; quit;&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;200&lt;BR /&gt;MPRINT(CHECK_TABLE): drop table () ;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.&lt;BR /&gt;&lt;BR /&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;BR /&gt;&lt;BR /&gt;So I then added quotes like this&lt;BR /&gt;("&amp;amp;db_name."."&amp;amp;table_name.")&lt;BR /&gt;and it went back to displaying table does not exist.&lt;BR /&gt;I also tried this ("&amp;amp;db_name.".&amp;amp;table_name.), that didn't make a difference either.</description>
      <pubDate>Mon, 13 Jan 2020 20:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617054#M180752</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-01-13T20:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617057#M180753</link>
      <description>&lt;P&gt;That error is from some other mistake.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 21:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617057#M180753</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-13T21:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617060#M180755</link>
      <description>&lt;P&gt;Remember when pasting in text (or editing it) to use the Insert Code or Insert SAS code buttons.&lt;/P&gt;
&lt;P&gt;Try this fixed version:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check_table(db_name,table_name);
%local dsname ;
%let dsname=&amp;amp;table_name ;
%if %length(&amp;amp;db_name) %then %let dsname=&amp;amp;db_name..&amp;amp;dsname;

%if %sysfunc(exist(&amp;amp;dsname)) %then %do;
  %put Found table &amp;amp;dsname ;
  proc delete data=&amp;amp;dsname; run;
%end;
%else %do;
  %put Could not find &amp;amp;dsname ;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;827   options mprint;
828   %check_table(,abc);
Could not find abc
829   data abc;
830   run;

NOTE: The data set WORK.ABC has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


831   %check_table(,abc);
Found table abc
MPRINT(CHECK_TABLE):   proc delete data=abc;
MPRINT(CHECK_TABLE):   run;

NOTE: Deleting WORK.ABC (memtype=DATA).
NOTE: PROCEDURE DELETE used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 21:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617060#M180755</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-13T21:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617061#M180756</link>
      <description>This works. Could you help me understand how moving those 2 macro variable names into a single dsname made a difference? Or how could I have modified my code to correct that? Would help me avoid similar mistakes in the future &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you.</description>
      <pubDate>Mon, 13 Jan 2020 21:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617061#M180756</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-01-13T21:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617071#M180758</link>
      <description>As I said before all you needed to do was add the extra period, where ever you needed it.  Making the full dataset name from the two pieces into one macro variable just makes so you only have a single place to check to make sure the period is getting inserted properly.&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Jan 2020 21:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617071#M180758</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-13T21:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617075#M180759</link>
      <description>&lt;P&gt;Querying the database metadata directly as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;proposes is certainly an option. However this requires database specific syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below two alternative options.&lt;/P&gt;
&lt;P&gt;Option 2 is a bit "brute force" and I'm also not 100% sure that it will work for Teradata (it doesn't for Hadoop).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* option 1: query SAS dictionary tables */
%macro check_table(db_name,table_name);
  %local delflg;
  %let delflg=0;
  proc sql;
    select count(*) into :delflg
    from dictionary.tables
    where libname="%upcase(&amp;amp;db_name)" and memname="%upcase(&amp;amp;table_name)"
    ;
  quit;
  %if &amp;amp;delflg=1 %then %do;
    %put The table exists.;
      proc sql;
       drop table (&amp;amp;db_name..&amp;amp;table_name.) ;
      quit;
  %end;
  %else %do;
      %Put Table does not exist;
  %end;
%mend;
%check_table(db1,T1_data);

/* option 2: not 100% if this works with Teradata */
%macro dropTbl_ifExist(db_name,table_name);
  proc datasets lib=&amp;amp;db_name nolist nowarn;
    delete &amp;amp;table_name;
    run;
  quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2020 22:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617075#M180759</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-01-13T22:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617085#M180765</link>
      <description>Patrick, unfortunately DB tables do not end up in the dictionary.tables data set &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Mon, 13 Jan 2020 22:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617085#M180765</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-13T22:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617096#M180768</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Patrick, unfortunately DB tables do not end up in the dictionary.tables data set &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you get to such a conclusion? Below works for me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname oratest oracle user=&amp;lt;user&amp;gt; pw=&amp;lt;password&amp;gt;;
proc sql;
  select *
  from dictionary.tables
  where libname='ORATEST'
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35316i135795D1FC49418E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 00:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617096#M180768</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-01-14T00:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617105#M180773</link>
      <description>&lt;P&gt;Not sure how much the results from using SAS/Access to Oracle to access an Oracle database translate into using SAS/Access to ODBC to connect to a Teradata database.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 01:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617105#M180773</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-14T01:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617109#M180775</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Not sure how much the results from using SAS/Access to Oracle to access an Oracle database translate into using SAS/Access to ODBC to connect to a Teradata database.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It might not - but&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;statement was for "DB tables" in general and for this the Oracle engine appeared good enough to me.&lt;/P&gt;
&lt;P&gt;Also: If the information doesn't make it into the dictionary tables then how comes we can normally see such tables in UI's like SAS EG under the library node. So I'm rather guessing that if DB tables aren't available in the SAS dictionary then there are some DB permissions "missing" site specific which prohibit the SAS user to query the DB metadata.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 02:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617109#M180775</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-01-14T02:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617236#M180827</link>
      <description>It may depend on if your system registered the tables, but historically any time I would connect to DB2, MS SQL DB the table names would not show in the dictionary.table. &lt;BR /&gt;&lt;BR /&gt;It may vary based on the connection type (ODBC vs DB Specific drivers)?? &lt;BR /&gt;&lt;BR /&gt;It definitely does not work for all DB library so not sure what the rules are there.</description>
      <pubDate>Tue, 14 Jan 2020 16:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/617236#M180827</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-14T16:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exists in database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/785239#M250583</link>
      <description>This worked great for me.&lt;BR /&gt;And instead of this:&lt;BR /&gt;&lt;BR /&gt;%else %do;&lt;BR /&gt;%put Could not find &amp;amp;dsname ;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;I created an empty global temp table:&lt;BR /&gt;%else %do;&lt;BR /&gt;/* If Oracle table does not exists, create it */&lt;BR /&gt;proc sql ;&lt;BR /&gt;connect to oracle (path="hcemi" user=&amp;amp;hcemi_u. password="%superq(hcemi_p)"&lt;BR /&gt;connection=shared adjust_byte_semantic_column_lengths=yes);&lt;BR /&gt;execute (create global temporary table "%sysuserid..temptrans (mbr_id char(46))) by oracle ;&lt;BR /&gt;quit ;&lt;BR /&gt;%end ;&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Dec 2021 18:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-table-exists-in-database/m-p/785239#M250583</guid>
      <dc:creator>avellani</dc:creator>
      <dc:date>2021-12-09T18:45:13Z</dc:date>
    </item>
  </channel>
</rss>

