<?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 exist function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373892#M89455</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to check if a table exist and I can't manage this, can you help?&lt;/P&gt;&lt;P&gt;I call a macro A:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%A (&lt;BR /&gt; ext_output_table = GG&lt;BR /&gt; );&lt;/PRE&gt;&lt;P&gt;In this macro, there is a loop. For each item I create a temporary table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;amp;ext_output_table._tmp&lt;/PRE&gt;&lt;P&gt;Then (still inside the loop) I call another macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;	%union(
		input_table = &amp;amp;ext_output_table._tmp.,
		output_table = &amp;amp;ext_output_table.);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The union macro is defined like this:&lt;/P&gt;&lt;PRE&gt;%macro union(
	input_table,
	output_table);
%if NOT(%sysfunc(exist(WORK.&amp;amp;output_table.)))  %then %do;
	data &amp;amp;output_table.; set &amp;amp;input_table.; run;
%end;
%else %do;
	PROC APPEND BASE= &amp;amp;output_table. DATA= &amp;amp;input_table. force;
%end;
PROC DELETE DATA= &amp;amp;input_table.;
%mend union;&lt;/PRE&gt;&lt;P&gt;The purpose of this is to create the table as equal to the temporary table if it is not existing otherwise&amp;nbsp;just append the current version of the table by adding the rows of the temporary table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the log I receive the opposite answer than the one I should, &amp;nbsp;&lt;/P&gt;&lt;PRE&gt;NOT(%sysfunc(exist(WORK.&amp;amp;output_table.))) IS FALSE&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the first item of my loop, it should be true.&lt;/P&gt;&lt;P&gt;Do you know what could go wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2017 11:04:21 GMT</pubDate>
    <dc:creator>Planck</dc:creator>
    <dc:date>2017-07-07T11:04:21Z</dc:date>
    <item>
      <title>exist function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373892#M89455</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to check if a table exist and I can't manage this, can you help?&lt;/P&gt;&lt;P&gt;I call a macro A:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%A (&lt;BR /&gt; ext_output_table = GG&lt;BR /&gt; );&lt;/PRE&gt;&lt;P&gt;In this macro, there is a loop. For each item I create a temporary table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;amp;ext_output_table._tmp&lt;/PRE&gt;&lt;P&gt;Then (still inside the loop) I call another macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;	%union(
		input_table = &amp;amp;ext_output_table._tmp.,
		output_table = &amp;amp;ext_output_table.);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The union macro is defined like this:&lt;/P&gt;&lt;PRE&gt;%macro union(
	input_table,
	output_table);
%if NOT(%sysfunc(exist(WORK.&amp;amp;output_table.)))  %then %do;
	data &amp;amp;output_table.; set &amp;amp;input_table.; run;
%end;
%else %do;
	PROC APPEND BASE= &amp;amp;output_table. DATA= &amp;amp;input_table. force;
%end;
PROC DELETE DATA= &amp;amp;input_table.;
%mend union;&lt;/PRE&gt;&lt;P&gt;The purpose of this is to create the table as equal to the temporary table if it is not existing otherwise&amp;nbsp;just append the current version of the table by adding the rows of the temporary table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the log I receive the opposite answer than the one I should, &amp;nbsp;&lt;/P&gt;&lt;PRE&gt;NOT(%sysfunc(exist(WORK.&amp;amp;output_table.))) IS FALSE&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the first item of my loop, it should be true.&lt;/P&gt;&lt;P&gt;Do you know what could go wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 11:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373892#M89455</guid>
      <dc:creator>Planck</dc:creator>
      <dc:date>2017-07-07T11:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: exist function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373894#M89457</link>
      <description>&lt;P&gt;Firstly, you should post your code as is, and not mostly unrelated snippets. It is very hard to make sense of all of this.&lt;/P&gt;
&lt;P&gt;This got my attention:&lt;/P&gt;
&lt;PRE&gt;&amp;amp;ext_output_table._tmp&lt;/PRE&gt;
&lt;P&gt;How do you use that text?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 11:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373894#M89457</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-07T11:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: exist function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373899#M89461</link>
      <description>&lt;P&gt;Sorry, a mess of snippets and macro code undefined is not a good example. &amp;nbsp;If you want to append a dataset if it exist, then as always, keep it simple:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="WORK" and memname="UPDATE"));
  call execute('proc append base=total data=update; run;');
run;
&lt;/PRE&gt;
&lt;P&gt;The above will only generate the proc append if a dataset update exists in work. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although a second question, why do you not know if a dataset exists or not? &amp;nbsp;There is only one instance (from a proc freq perhaps) where no output dataset is created, so sounds like you have issue before in yur logic.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 11:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373899#M89461</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-07T11:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: exist function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373947#M89486</link>
      <description>&lt;P&gt;PROC APPEND does exactly what you would like without any fancy macros:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc append base=&amp;amp;out_table. data=&amp;amp;input_table. force;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's perfectly OK if the BASE= data set does not exist. &amp;nbsp;PROC APPEND then copies the DATA= data set to the BASE= location.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 12:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/exist-function/m-p/373947#M89486</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-07T12:56:53Z</dc:date>
    </item>
  </channel>
</rss>

