BookmarkSubscribeRSS Feed
RTelang
Fluorite | Level 6

here is my macro to delete dataset from worklib & clear all filename libname statments. but i am having issues in the filename code & how can i add delete macro global variable code to my clean up macro??? 

 

%macro cleanup;
proc datasets
library = work
kill;
quit;

proc sql noprint;
select unique libname into :mylibs separated by ' clear; libname '
from dictionary.libnames
where libname not in ('MAPS','SASHELP','SASUSER','WORK');
quit;
libname &mylibs clear;

proc sql noprint;
select unique fileref into :myfiles separated by 'clear; filename '
from dictionary.extfiles
where substr(fileref,1);
quit;
filename &myfiles;
%cleanup;

18 REPLIES 18
RTelang
Fluorite | Level 6

WARNING: Apparent symbolic reference MYLIBS not resolved.
WARNING: Apparent symbolic reference MYLIBS not resolved.
ERROR: & is not a valid SAS name.
ERROR: Error in the LIBNAME statement.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds


ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: At least one file associated with fileref _RTFOUT is still in use.
ERROR: Error in the FILENAME statement.
RTelang
Fluorite | Level 6
delete all work datasets & clear all libname and filename statements
Kurt_Bremser
Super User

Run your code snippets outside of the macro one by one.

Add a

%put "&mylibs";

and

%put "&myfiles";

after the relevant steps that should have created them. Note the quotes that prevent the semicolons in the strings to be interpreted and executed as SAS code.

This will give you a clue what actually happens.

It might be (in the first step) that no libraries apart from the four you specified are present, and therefore the macro variable will not be created. The same might be true for your filerefs. You are also missing a blank before the clear; when creating the myfiles macro variable.

RTelang
Fluorite | Level 6
still the error exist in the file name statement

62 filename &myfiles;
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
NOTE: Line generated by the macro variable "MYFILES".
62 #LN00001clear ; filename#LN00002clear ; filename#LN00003clear ; filename#LN00027clear ; filename#LN00046clear ;
62 ! filename#LN00084clear ; filename#LN00085clear ; filename#LN00088clear ; filenameFILDES03clear ; filenameFILDES04clear ;
_____________________
180
62 ! filenameFILDES05clear
ERROR 180-322: Statement is not valid or it is used out of proper order.
RTelang
Fluorite | Level 6
i corrected the as u said but the error persists-->

56 proc sql noprint;
57 select unique fileref
58 into : myfiles separated by 'clear ; filename'
59 from dictionary.extfiles
60 where substr(fileref,1,1)^= '#';
61 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds


62 filename &myfiles;
ERROR: Invalid logical name.
ERROR: Error in the FILENAME statement.
NOTE: Line generated by the macro variable "MYFILES".
62 FILDES03clear ; filenameFILDES04clear ; filenameFILDES05clear ; filenameFILDES07clear ; filenameFILDES08clear ;
_____________________
180
62 ! filenameFILDES09clear ; filenameSTDERRclear ; filenameSTDINclear ; filenameSTDOUTclear ; filename_DATAOUTclear ;
62 ! filename_GSFNAMEclear ;
ERROR 180-322: Statement is not valid or it is used out of proper order.
Kurt_Bremser
Super User

LOOK HERE:

 

58 into : myfiles separated by 'clear ; filename'

 

There is NO blank in the separator BEFORE the clear; and NO blank AFTER the filename. This causes your invalid statements like filenameFILDES04clear !

 

Astounding
PROC Star

I agree ... strongly ... with those who say that _ALL_ is the answer and you can still use _ALL_ inside a macro.  But if you insist on complicating the program unnecessarily, here is a way to proceed:

 

proc sql noprint;
select distinct 'filename ' || fileref || ' clear;'
into : myfiles separated by ' '
from dictionary.extfiles
where substr(fileref,1,1)^= '#';
quit;

&myfiles

Ksharp
Super User

Why not use :

 

libname _all_ clear;
filename _all_ clear;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I totally agree @Ksharp.  There is no value in creating obfuscated code rather than use base sas code.  Proc datasets is present in Base SAS to alter files, and the libname statement to handle libnames.  Wrapping these in unecessary macro code merely makes them less robust, and harder to understand.  

 

As mentioned before, there is a time and place for macros, but it is wise to use Base SAS as much as possible, for a number of reasons.

RTelang
Fluorite | Level 6
@RW9 @Ksharp but i need a macro so am using it
Kurt_Bremser
Super User

At least in the case of the libnames, libname _all_ clear; will do EXACTLY what your macro is supposed to do, so insisting on using a macro is an exercise in unnecessity.

RTelang
Fluorite | Level 6
k but i need macro so am doing it. i know simple libnme clear is k but i need macro for bigger amt of data

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 18 replies
  • 2540 views
  • 0 likes
  • 6 in conversation