03-16-2012 10:05 AM
How do I delete all datasets in a library except those that contain, say, _MEANS2, in the dataset name ?
03-16-2012 10:48 AM
If they started with _MEANS2 it would be really easy.
proc datasets library=... memtype=data;
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.
03-16-2012 11:06 AM
Thanks, Data_null_. And here is the code following his instruction:
select DISTINCT memname INTO :NAMES SEPARATED BY ' '
from dictionary.columns where libname='WORK' AND memname ? '_means2'
proc datasets library=WORK memtype=data;
Note: I have use work library as an example.
03-16-2012 11:29 AM
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.
03-16-2012 11:12 AM
PROC SQL NOPRINT;
,MEMNAME INTO : CONT, : NAME
SEPARATED BY " "
UPCASE(LIBNAME) EQ "&LIB."
MEMNAME NOT CONTAINS '_MEANS2';
%DO %UNTIL (&CONT.);
PROC DATASETS LIB = &LIB. MEMTYPE = DATA NOLIST;
03-16-2012 11:20 AM
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!