<?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 Sas drop teradata table issues in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523634#M4669</link>
    <description>&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table in Teradata named DataLoad. It has two columns, LoadID and EmpAI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a simple script that will check the table DataLoad and see if it has any rows inside it, If it does it does nothing, if there is no data in the table it drops it. Any suggestions on how to achieve this?&lt;/P&gt;</description>
    <pubDate>Thu, 27 Dec 2018 15:19:17 GMT</pubDate>
    <dc:creator>Amicheals</dc:creator>
    <dc:date>2018-12-27T15:19:17Z</dc:date>
    <item>
      <title>Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523634#M4669</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table in Teradata named DataLoad. It has two columns, LoadID and EmpAI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a simple script that will check the table DataLoad and see if it has any rows inside it, If it does it does nothing, if there is no data in the table it drops it. Any suggestions on how to achieve this?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 15:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523634#M4669</guid>
      <dc:creator>Amicheals</dc:creator>
      <dc:date>2018-12-27T15:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523642#M4670</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252687"&gt;@Amicheals&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could check if there are any rows by trying to read the first one. If there is no first row then drop the table:&lt;/P&gt;
&lt;P&gt;There are other ways/. You say you do not want to do this using PROC SQL. That would normally need some explanation because that eliminates some techniques like explicit passthrough. But I am not inviting you to have that discussion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro deletewhenempty;

%let hasrows=0;
data _null_;
   set tdlib.DataLoad;
   call symput('hasrows', _n_);
   stop;
run;

%if &amp;amp;hasrows=0 %then %do;
   proc datasets lib=tdlib nolist nowarn;
      delete DataLoad;
   quit;
%end;

%mend;

%deletewhenempty;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 15:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523642#M4670</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2018-12-27T15:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523644#M4671</link>
      <description>&lt;P&gt;-Jan I spoke to soon, I can use a proc sql statement.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 15:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523644#M4671</guid>
      <dc:creator>Amicheals</dc:creator>
      <dc:date>2018-12-27T15:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523648#M4672</link>
      <description>&lt;P&gt;Then the code to drop the table could be as simple as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   connect to teradata as tera ( user=testuser password=testpass database=mydb );
   execute (drop table DataLoad) by tera;
   execute (commit) by tera;
   disconnect from tera;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The need for a commit depends on the mode of your connection, ANSI or Teradata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Taking it further you could wrap all the login in a Teradata stored procedure. This is however not my forte. And I think in the use case at hand is too simple to go that path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 15:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523648#M4672</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2018-12-27T15:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523660#M4674</link>
      <description>&lt;P&gt;Jan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there a way to add something into that proc sql so if the table does not exist it just moves on to the next step?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 16:25:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523660#M4674</guid>
      <dc:creator>Amicheals</dc:creator>
      <dc:date>2018-12-27T16:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523664#M4675</link>
      <description>&lt;P&gt;I would handle that in the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro deletewhenempty;

%if sysfunc(exist(tdlib.DataLoad)) %then %do;
   %let hasrows=0;
   data _null_;
      set tdlib.DataLoad;
      call symput('hasrows', _n_);
      stop;
   run;

   %if &amp;amp;hasrows=0 %then %do;
      proc datasets lib=tdlib nolist nowarn;
         delete DataLoad;
      quit;
   %end;
%end;
%mend;

%deletewhenempty;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code not yet enterprise ready. Eg. I would eliminate the repetition of lib and table name, but I leave that to you as home woirk. &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;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;-- Jan.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 16:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523664#M4675</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2018-12-27T16:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523666#M4676</link>
      <description>&lt;P&gt;Jan One last question. In that code you sent me above. What If I just wanted to drop the table regardless if there is data in it.&lt;/P&gt;&lt;P&gt;So check for DataLoad, if exists drop otherwise move to next step. Sorry to throw a wrench into it&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 17:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523666#M4676</guid>
      <dc:creator>Amicheals</dc:creator>
      <dc:date>2018-12-27T17:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523754#M4682</link>
      <description>&lt;P&gt;That would mean a simplification of the code. Take out the '%if hasrows' condition:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro deletewhenexists;

%if sysfunc(exist(tdlib.DataLoad)) %then %do;

   proc datasets lib=tdlib nolist nowarn;
      delete DataLoad;
   quit;

%end;
%mend;

%deletewhenexists;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also, amongst others, use PROC DELETE. see &lt;A href="https://blogs.sas.com/content/sasdummy/2013/07/08/proc-delete-its-not-dead-yet/" target="_blank"&gt;Chris Hemedinger's discussion&lt;/A&gt; on this for the pro's and con's of this procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;-- Jan.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 12:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523754#M4682</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2018-12-28T12:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523760#M4683</link>
      <description>&lt;P&gt;Jan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you. I am getting the following error when trying to run that code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Required operator not found in expression: sysfunc(exist(tdlib.DataLoad))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 14:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523760#M4683</guid>
      <dc:creator>Amicheals</dc:creator>
      <dc:date>2018-12-28T14:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sas drop teradata table issues</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523763#M4684</link>
      <description>&lt;P&gt;Ah yes, I never actually tested the code &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;It's&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &lt;STRONG&gt;%&lt;/STRONG&gt;sysfunc(exist(tdlib.DataLoad)) %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;sysfunc is a macro function so it needs to be prefixed with a percent sign.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please keep in mind that I present suggestions and not complete, robust and fully tested code. But I do hope I have now put you on the right path. Experience and further education will help you to troubleshoot and extrapolate on these suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;-- Jan.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 14:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sas-drop-teradata-table-issues/m-p/523763#M4684</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2018-12-28T14:44:11Z</dc:date>
    </item>
  </channel>
</rss>

