<?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: optional drop table in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924778#M41499</link>
    <description>&lt;P&gt;The IF EXIST clause doesn't exist in the SAS SQL flavor which is why you're getting an error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following syntax works for deleting SAS tables that may or may not exist.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=work nolist nowarn;
  delete mytable;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Apr 2024 02:29:53 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-04-18T02:29:53Z</dc:date>
    <item>
      <title>optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924734#M41493</link>
      <description>&lt;P&gt;Hi friends,&lt;/P&gt;&lt;P&gt;I don't now how to drop a table which maybe don´t exist:&lt;/P&gt;&lt;P&gt;If I use this code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
if exist(select * from x) then
drop table x;
quit;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get this &lt;STRONG&gt;error message&lt;/STRONG&gt;: "Statement is not valid or it is used out of proper order."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
drop table if exists x;
quit;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;SAS says: "ERROR: &lt;STRONG&gt;Syntax error&lt;/STRONG&gt;, expecting one of the following: ;, (, ',', '.', INDEX, TABLE, VIEW. "&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;¿Anybody knows how to&amp;nbsp; do it?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 17:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924734#M41493</guid>
      <dc:creator>ppinedo</dc:creator>
      <dc:date>2024-04-17T17:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924736#M41494</link>
      <description>&lt;P&gt;When you get an error you should copy from the log the code for the procedure or step and all the messages related. Then on the forum open a text box on the forum by clicking on the &amp;lt;/&amp;gt; icon that appears above the message window.&lt;/P&gt;
&lt;P&gt;That would show something like:&lt;/P&gt;
&lt;PRE&gt;110  proc sql;
111  if exist(select * from x) then
     --
     180
ERROR 180-322: Statement is not valid or it is used out of proper order.

112  drop table x;
113  quit;
&lt;/PRE&gt;
&lt;P&gt;Which the -- is under the word IF, indicating that is the problem. SQL does not use IF/Then. There is a CASE When for selecting variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think that the proc sql Drop to remove tables will use a variable read from a table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 17:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924736#M41494</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-17T17:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924737#M41495</link>
      <description>&lt;P&gt;That code is from another post in this foro, it use "IF" in his/her code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 18:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924737#M41495</guid>
      <dc:creator>ppinedo</dc:creator>
      <dc:date>2024-04-17T18:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924743#M41496</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465268"&gt;@ppinedo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That code is from another post in this foro, it use "IF" in his/her code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Proc SQL can be used with a connection to external databases to pass through code that is specific to that data base that often has extensions that will not run with "pure" SAS SQL. So with out seeing the specific post to tell if that was the case I'll stand by the the error is related to the IF.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 19:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924743#M41496</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-17T19:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924744#M41497</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
  x=42;
run;

proc sql;
  %sysfunc(ifc(%sysfunc(exist(x)),
    drop table x,
  ));;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 19:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924744#M41497</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-04-17T19:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924746#M41498</link>
      <description>&lt;P&gt;Please clarify what you are trying to do.&lt;/P&gt;
&lt;P&gt;Your words make it sound like you want to drop the dataset when it does exist (you cannot drop a dataset that does not exist).&amp;nbsp; Perhaps you are worried about a warning message if you try to drop a dataset that does not exist?&lt;/P&gt;
&lt;PRE&gt;1    proc delete data=no_such_data ; run;

WARNING: File WORK.NO_SUCH_DATA.DATA does not exist.
NOTE: PROCEDURE DELETE used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2    proc sql;
3     drop table no_such_data;
WARNING: File WORK.NO_SUCH_DATA.DATA does not exist.
WARNING: Table WORK.NO_SUCH_DATA has not been dropped.
4    quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


&lt;/PRE&gt;
&lt;P&gt;If so then you probably need to conditionally generate CODE.&lt;/P&gt;
&lt;P&gt;The SAS macro language is good at that.&lt;/P&gt;
&lt;PRE&gt;5    proc sql;
6    %if %sysfunc(exist(no_such_data)) %then %do;
7     drop table no_such_data;
8    %end;
9    quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds

&lt;/PRE&gt;
&lt;P&gt;If instead you meant to drop the table when it has no observations then you will need a different test.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 19:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924746#M41498</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-17T19:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924778#M41499</link>
      <description>&lt;P&gt;The IF EXIST clause doesn't exist in the SAS SQL flavor which is why you're getting an error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following syntax works for deleting SAS tables that may or may not exist.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=work nolist nowarn;
  delete mytable;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Apr 2024 02:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/924778#M41499</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-18T02:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/925362#M41539</link>
      <description>&lt;P&gt;Sorry for my delay &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, you're right &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; ( IF don't exist in SQL, I used it in &lt;A href="https://stackoverflow.com/questions/5528854/usage-of-mysqls-if-exists" target="_self"&gt;MySQL&lt;/A&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;amp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; yours codes are perfect for me &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;, I don't want receive WARNINGs if table doesn't exist&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 12:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/925362#M41539</guid>
      <dc:creator>ppinedo</dc:creator>
      <dc:date>2024-04-23T12:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: optional drop table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/925493#M41548</link>
      <description>&lt;P&gt;An alternative way like Patrick is using PROC DELETE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options nodsnferr;
proc delete data=work.mytable;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2024 05:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/optional-drop-table/m-p/925493#M41548</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-04-24T05:35:03Z</dc:date>
    </item>
  </channel>
</rss>

