- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You are still missing a blank before the clear; statement in the separator when you build your myfiles macro variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why not use :
libname _all_ clear;
filename _all_ clear;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content