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;
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.
You are still missing a blank before the clear; statement in the separator when you build your myfiles macro variable.
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 !
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
Why not use :
libname _all_ clear;
filename _all_ clear;
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.
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.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: