07-07-2017 07:04 AM
I try to check if a table exist and I can't manage this, can you help?
I call a macro A:
ext_output_table = GG
In this macro, there is a loop. For each item I create a temporary table:
Then (still inside the loop) I call another macro
%union( input_table = &ext_output_table._tmp., output_table = &ext_output_table.);
The union macro is defined like this:
%macro union( input_table, output_table); %if NOT(%sysfunc(exist(WORK.&output_table.))) %then %do; data &output_table.; set &input_table.; run; %end; %else %do; PROC APPEND BASE= &output_table. DATA= &input_table. force; %end; PROC DELETE DATA= &input_table.; %mend union;
The purpose of this is to create the table as equal to the temporary table if it is not existing otherwise just append the current version of the table by adding the rows of the temporary table.
In the log I receive the opposite answer than the one I should,
NOT(%sysfunc(exist(WORK.&output_table.))) IS FALSE
For the first item of my loop, it should be true.
Do you know what could go wrong here?
07-07-2017 07:12 AM - edited 07-07-2017 07:12 AM
Firstly, you should post your code as is, and not mostly unrelated snippets. It is very hard to make sense of all of this.
This got my attention:
How do you use that text?
07-07-2017 07:22 AM
Sorry, a mess of snippets and macro code undefined is not a good example. If you want to append a dataset if it exist, then as always, keep it simple:
data _null_; set sashelp.vtable (where=(libname="WORK" and memname="UPDATE")); call execute('proc append base=total data=update; run;'); run;
The above will only generate the proc append if a dataset update exists in work.
Although a second question, why do you not know if a dataset exists or not? 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.
07-07-2017 08:56 AM
PROC APPEND does exactly what you would like without any fancy macros:
proc append base=&out_table. data=&input_table. force;
It's perfectly OK if the BASE= data set does not exist. PROC APPEND then copies the DATA= data set to the BASE= location.