Help using Base SAS procedures

How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

Reply
Contributor
Posts: 40

How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

How do I delete all datasets in a library except those that contain, say, _MEANS2, in the dataset name ?

Thanks...

Respected Advisor
Posts: 3,799

How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

If they started with _MEANS2 it would be really easy.

proc datasets library=... memtype=data;

   save _means2:;

   run;

   quit;

For contains you will need to build the SAVE list from meta data DICTIONARY.MEMBERS perhaps.  Use SQL INTO macro variable and use macro variable in SAVE statement.  Easy enough.

Respected Advisor
Posts: 3,156

How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

Posted in reply to data_null__

Thanks, Data_null_. And here is the code following his instruction:

proc sql;

select DISTINCT memname INTO :NAMES SEPARATED BY ' '

  from dictionary.columns where libname='WORK' AND memname ? '_means2'

  ;

  QUIT;

proc datasets library=WORK memtype=data;

   save &NAMES;

   run;

   quit;

Note: I have use work library as an example.

Regards,

Haikuo

Contributor
Posts: 40

Re: How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

Thank you, Hai.kuo, for your reply. Although I had a lot of datasets in the work library with and without "_means2" in the dataset name, this code did not select anything into Names and so, in the next step the marco could not be resolved.

Respected Advisor
Posts: 3,156

Re: How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

Could we see your log?

Respected Advisor
Posts: 3,799

Re: How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

UPCASE

Respected Advisor
Posts: 3,156

Re: How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

Posted in reply to data_null__

Yep! Most likely! Also make sure there is a blank in separated by ' '.

Frequent Contributor
Posts: 80

How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

ANOTHER WAY

%MACRO WANT(LIB);
PROC SQL NOPRINT;
SELECT
   COUNT(*)
  ,MEMNAME INTO : CONT,  : NAME
SEPARATED BY " "
    FROM
DICTIONARY.TABLES
    WHERE
UPCASE(LIBNAME) EQ "&LIB."
    AND

MEMNAME NOT CONTAINS '_MEANS2';
  QUIT;

   %DO %UNTIL (&CONT.);
         PROC DATASETS LIB = &LIB. MEMTYPE = DATA NOLIST;
            DELETE &NAME.;
         RUN;
    %END;


%MEND;

%WANT (WORK);

Contributor
Posts: 40

Re: How do I delete all dataset in a library except those that contain, say, _MEANS2, in the dataset name ? Thanks...

Thank you, data_null_; , Hai.kuo and Augusto for your quick and very helpful replies ! This is better than writing out the datasets in a Proc Delete and I also learnt something new. Thanks again for your help!

Ask a Question
Discussion stats
  • 8 replies
  • 762 views
  • 3 likes
  • 4 in conversation