BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gateux
Calcite | Level 5

I am using exactly this type of macro:

 

%MACRO EXPORT_TABLE(table, database, name);
	PROC EXPORT
	DATA = WORK.&table.
	OUTTABLE = "&name."
	DBMS = ACCESS REPLACE;
	DATABASE = &database.;
	RUN;
%MEND;

%EXPORT_TABLE(Somename, "path.mdb", Anothername);

However, if the file already exists, SAS doesn't replace it, but makes the file bigger in size (number of rows/cols are preserved, but size of the file is higher). You can imagine how many problems this causes.

 

Is there any way, how to deal with this? I have tried NEWFILE = yes;, but it doesn't work with access databases.

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Create a libname reference to the Access DB. Then use PROC SQL or PROC DATASETS to delete the table in the ACCESS DB that you're not interested in and THEN do your creation/insert step.

My assumption - you have an Access DB and are replacing a table in the DB. If otherwise, provide more details on your question.

View solution in original post

4 REPLIES 4
Reeza
Super User
Have you tried dropping the table first?
Gateux
Calcite | Level 5

Hi, thank you for reply. Could you be more specific about dropping the table? Access is first time referenced in the macro. Thanks

Reeza
Super User
Create a libname reference to the Access DB. Then use PROC SQL or PROC DATASETS to delete the table in the ACCESS DB that you're not interested in and THEN do your creation/insert step.

My assumption - you have an Access DB and are replacing a table in the DB. If otherwise, provide more details on your question.
Gateux
Calcite | Level 5

Unfortunately, this doesn't work. I implemented it into the macro in this way:

 

%MACRO EXPORT_TABLE(table, database, name);
LIBNAME ACC &database.;

PROC DATASETS LIB = ACC NOPRINT;
        DELETE &name.;
QUIT;


PROC EXPORT
	DATA = WORK.&table.
	OUTTABLE = "&name."
	DBMS = ACCESS REPLACE;
	DATABASE = &database.;
RUN;
%MEND;

%EXPORT_TABLE(Somename, "path.mdb", Anothername);

Log says that the libname was successfully assigned, also 'Deleting ACC.tablename"... but still, the file size is increasing.

 

Edit:

When using with DIRECT_EXE and PROC SQL:

LIBNAME ACC &database. DIRECT_EXE = DELETE;

PROC SQL; DELETE FROM ACC.&name.; QUIT;

LIBNAME ACC CLEAR;

It seems like working. The table itself is not deleted but just cleared (ie it is empty). However, the size doesn't apparently change.

 

Thank you for the solution. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1498 views
  • 0 likes
  • 2 in conversation