BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WendyT
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

WendyT
Pyrite | Level 9

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

data_null__
Jade | Level 19

Why not use the NOWARN proc datasets statement option.

 

proc datasets nowarn
WendyT
Pyrite | Level 9

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 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2376 views
  • 0 likes
  • 3 in conversation