BookmarkSubscribeRSS Feed
sas_
Fluorite | Level 6
How can i delete a sas dataset from a library other than using SAS Datasets procedure.Any macro or functions are there to delete.
3 REPLIES 3
milts
Pyrite | Level 9
Hi,

How about using proc sql delete from or drop table?

Milton
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You also have PROC DELETE.

Scott Barry
SBBWorks, Inc.
Oleg_L
Obsidian | Level 7
Hello.

You can try this macro to delete SAS datasets or any other files in library.
You can also use Windows commands.

%macro dirclear(dir=d:\test,ext=xls);
%let ext=%upcase(&ext);
%let dlm=\;
%let filrf=;
%let rc=%sysfunc(filename(filrf,"&dir"));
%let did=%sysfunc(dopen(&filrf));
%let lstname=;
%let memcount=%sysfunc(dnum(&did));
%if &memcount > 0 %then %do;
%do i=1 %to &memcount;
%let lstname=%sysfunc(dread(&did,&i));
%let file=&dir&dlm&lstname;
%let ln=%length(&lstname);
data _null_;
c="&lstname"; c1=reverse(c); ln1=index(c1,'.'); ln=&ln-ln1+2; ln3=ln1-1;
ln4=upcase(substr(c,ln,ln3));
call symput('ln2',trim(left(ln4)));
run;
%if &ln2=&ext or &ext= %then %do;
%let rb=%sysfunc(filename(fname,"&file"));
%let rv=%sysfunc(fdelete(&fname));
%end; %end; %end;
%let rc=%sysfunc(dclose(&did));
%mend dirclear;

libname test v9 'd:\work\test';

%let l=%sysfunc(pathname(test));
/* use macro */
%dirclear(dir=&l,ext=sas7bdat);

/* use Windows command */
systask command "del ""&l.\*.sas7bdat""" wait taskname="del";

or use fdelete() function

data _null_;
rc=filename('fname', "&l.\recartis.sas7bdat");
if fexist('fname') then rc=fdelete('fname');
run;


Regards,
Oleg. Message was edited by: Oleg_1976

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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