Help using Base SAS procedures

debug delete sas environment

Reply
Regular Contributor
Posts: 190

debug delete sas environment

[ Edited ]

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;

Super User
Posts: 7,854

Re: debug delete sas environment

Well, what are the issues?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 190

Re: debug delete sas environment

Posted in reply to KurtBremser

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.
Regular Contributor
Posts: 190

Re: debug delete sas environment

Posted in reply to KurtBremser
delete all work datasets & clear all libname and filename statements
Super User
Posts: 7,854

Re: debug delete sas environment

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 190

Re: debug delete sas environment

Posted in reply to KurtBremser
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.
Super User
Posts: 7,854

Re: debug delete sas environment

You are still missing a blank before the clear; statement in the separator when you build your myfiles macro variable.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 190

Re: debug delete sas environment

Posted in reply to KurtBremser
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.
Super User
Posts: 7,854

Re: debug delete sas environment

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 !

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,516

Re: debug delete sas environment

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

Super User
Posts: 10,044

Re: debug delete sas environment

Why not use :

 

libname _all_ clear;
filename _all_ clear;
Super User
Super User
Posts: 7,988

Re: debug delete sas environment

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.

Regular Contributor
Posts: 190

Re: debug delete sas environment

@RW9 @Ksharp but i need a macro so am using it
Super User
Posts: 7,854

Re: debug delete sas environment

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 190

Re: debug delete sas environment

Posted in reply to KurtBremser
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
Ask a Question
Discussion stats
  • 18 replies
  • 552 views
  • 0 likes
  • 6 in conversation