BookmarkSubscribeRSS Feed
Xinxin
Obsidian | Level 7

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

Thanks...

8 REPLIES 8
data_null__
Jade | Level 19

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.

Haikuo
Onyx | Level 15

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

Xinxin
Obsidian | Level 7

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.

Haikuo
Onyx | Level 15

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

Augusto
Obsidian | Level 7

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);

Xinxin
Obsidian | Level 7

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!

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!

What is Bayesian Analysis?

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.

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
  • 8 replies
  • 10715 views
  • 7 likes
  • 4 in conversation