Hello
I want to delete data sets that appear in column "memname" in data set tables_tbl.
What is the way to do it please?
The only step that I know to do it to create data set that included the names of the data sets that I want to delete.
Please note that I know to delete each data set manually using PROC DELETE but the question is how to delete the data sets in one step
Data ttt1;
X=10;
Run;
Data ttt2;
X=15;
Run;
Data WWW1;
Z=10;
Run;
PROC SQL;
CREATE TABLE tables_tbl AS
SELECT *
FROM dictionary.tables
WHERE libname = 'WORK' and memname like '%TTT%'
;
QUIT;
Simple:
proc sql noprint;
select catx(".",libname,memname) into :dslist separated by " "
from tables_tbl;
quit;
proc delete data=&dslist.;
run;
From your own example, do this
Data ttt1;
X=10;
Run;
Data ttt2;
X=15;
Run;
Data WWW1;
Z=10;
Run;
PROC SQL noprint;
select memname
into :t separated by ' '
from dictionary.tables
WHERE libname = 'WORK' and memname like '%TTT%'
;
quit;
%put &t.;
proc datasets lib = work nolist;
delete &t.;
quit;
Please see again the list of data sets that I want to delete
Data ttt1;
X=10;
Run;
Data ttt2;
X=15;
Run;
Data WWW1;
Z=10;
Run;
data revenue_tbl;
input ID revenue;
cards;
1 100
2 200
;
Run;
PROC SQL;
CREATE TABLE tables_tbl AS
SELECT *
FROM dictionary.tables
WHERE libname = 'WORK' and (memname like '%TTT%' OR memname='REVENUE_TBL' OR memname='WWW1')
;
QUIT;
But, when you create the tables_tbl data set, you specify the rules manually for what data sets are to be deleted?
Simple:
proc sql noprint;
select catx(".",libname,memname) into :dslist separated by " "
from tables_tbl;
quit;
proc delete data=&dslist.;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.