SAS Folks-
Does anyone know a shortcut for dataset names with the same pattern in the EXIST function?
I want to clear all datasets in the WORK library with the filename pattern MASTER before I start a macro to read external files, and I use : to get them all.
proc datasets library=WORK ;
delete MASTER: ;
run ;
quit ;
However, if there are no existing MASTER: datasets, it generates a note.
NOTE: The file WORK.MASTER: (memtype=DATA) was not found, but appears on a DELETE statement.
Just for neatness, I would like to test to here are no existing MASTER: datasets before I do the deletion, maybe something along this line.
%macro DEL_MASTER(NAME);
%if %sysfunc(exist(&name)) %then %do ;
proc datasets library=WORK ;
delete MASTER: ;
run ;
quit ;
%end ;
%mend ;
%DEL_MASTER(MASTER_somedataset);
The only drawback is that it requires that I know at least one of the MASTER dataset names.
I use MASTER datasets in varying forms quite frequently when reading external data, and would love to be able to set up a macro to do this deletion without having to know any of the actual MASTER filenames.
%DEL_MASTER(MASTER:);
does not work. Does anyone know a shortcut that does?
If not, I could use the alternative of SASHELP.VMEMBER on LIBNAME and MEMNAME.
We are running 9.4 (TS1M3) on a 64-bit Windows 7 virtual server by remote login.
Thanks for your help!
Wendy T
Hi,
data _null_; set sashelp.vtable (where=(libname="WORK" and index(memname,"MASTER") > 0)); if _n_=1 then call execute('proc datasets library=WORK; delete MASTER:; run; quit;'); run;
Only if a dataset master exists in work then the proc datasets code will get generated. TBH though, is it a good idea to have master datasets in a tempoprary area? Having to remove datasets - especially in macros - seems to me to show the process is not very good. Why do you need to delete them? Why does the import of new data not overwite? What is your import process? I would suggest a sound import process would principally be responsible for importing data to a fixed area and validating it. Any other process can then just assume the data is there and ready.
Hi,
data _null_; set sashelp.vtable (where=(libname="WORK" and index(memname,"MASTER") > 0)); if _n_=1 then call execute('proc datasets library=WORK; delete MASTER:; run; quit;'); run;
Only if a dataset master exists in work then the proc datasets code will get generated. TBH though, is it a good idea to have master datasets in a tempoprary area? Having to remove datasets - especially in macros - seems to me to show the process is not very good. Why do you need to delete them? Why does the import of new data not overwite? What is your import process? I would suggest a sound import process would principally be responsible for importing data to a fixed area and validating it. Any other process can then just assume the data is there and ready.
RW9-
Thanks for the call execute method - that didn't even cross my mind.
Just FYI...
The typical scenario I use for WORK.MASTER: is to put together a bunch of files into a SAS dataset (usually badly formatted Excel files). The name came from a project that I did with a colleague, and when the process changed, the name did not (my bad).
Once I have MASTER, then I proceed with whatever needs to be done, and save the dataset to a permanent library. At that point, the MASTER: dataset(s) can be deleted to keep everything tidy.
I also like to run the delete of MASTER before starting, just to make sure there aren't any leftovers from a previous process.
Thanks so much for your help!
Wendy T
Why not use the NOWARN proc datasets statement option.
proc datasets nowarn
Data _null_-
I thought about NOWARN, but I didn't want to turn off warnings in case there was another issue.
Thanks so much!
Wendy
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.