I was trying to delete png files (500000+) using systask command in a do loop.
My loop stops in the 6482 loop count. Is there any reason or limit set in the loop while deleting the files this way.
%MACRO LOOP;
PROC SQL;
create table DSNAME as SELECT distinct memname FROM DICTIONARY.COLUMNS
WHERE UPCASE(LIBNAME)="WORK" AND
UPCASE(MEMNAME)LIKE "FINAL_SPLIT%";
select count(*) into :datasetcnt from DSNAME;
QUIT;
%put &datasetcnt.;
%do p=1 %to &datasetcnt.;
DATA _null_;
SET FINAL_SPLIT_&p.;
CALL SYMPUT( "FN" || LEFT(TRIM(_N_)) , trim(file_name) );
CALL SYMPUT( "totcnt",_N_ );
run;
/*%put &fn1.;*/
libname mylib &clrfold.;
%do i = 1 %to &totcnt.;
%let path=%sysfunc(pathname(mylib));
systask command
"del ""&path.\&&fn&i.."""
wait taskname="deleting";
%end;
%end;
%MEND LOOP;
%LOOP;
run;
I would recommend a non-macro, non-systask approach.
libname mylib &clrfold.;
%let path=%sysfunc(pathname(mylib));
data list_files;
*combines all files that start with the prefix final_split into one dataset;
set work.final_split: ;
*creates file path;
file_path = catx("\", "&path.", file_name);
fname = "tempfile";
*checks if file exists and deletes file;
rc=filename(fname, file_path);
if rc = 0 and fexist(fname) then
rc_delete=fdelete(fname);
rc=filename(fname);
run;
Why are you using %SYSTASK?
Why are you calling is separately for every file?
I cannot figure out what the beginning of your program has to do with the question about deleting PNG files.
If you have dataset with a list of files to delete.
data files;
infile cards truncover ;
input filename $200.;
cards;
file1.png
file2.png
;
Then use that to generate one DEL command for each file named. So something like this:
data want ;
set files;
length cmd $300 msg $300 ;
cmd = 'DEL '||quote(trim(filename)) ;
infile dummy pipe filevar=cmd end=eof;
do while(not eof);
input ;
msg=catx(' ',msg,_infile_);
end;
run;
I would recommend a non-macro, non-systask approach.
libname mylib &clrfold.;
%let path=%sysfunc(pathname(mylib));
data list_files;
*combines all files that start with the prefix final_split into one dataset;
set work.final_split: ;
*creates file path;
file_path = catx("\", "&path.", file_name);
fname = "tempfile";
*checks if file exists and deletes file;
rc=filename(fname, file_path);
if rc = 0 and fexist(fname) then
rc_delete=fdelete(fname);
rc=filename(fname);
run;
Thank you for helping to solve the issue. Your suggested solution worked for me!!
You can use OS command to get all these png's path. and issue X command to delete them all.
If you are using Windows OS . and c:\temp\ is ROOT directory for all the PNG files.
filename x pipe 'dir c:\temp\*.png /s /b';
filename z 'c:\temp\del.bat';
data _null_;
infile x length=len;
input x $varying200. len;
com='del '||x;
file z;
put com;
run;
options noxwait;
x 'c:\temp\del.bat';
Hi,
I was trying to archive/zip some selected date files and once the archival is done i am trying to delete those related files. Thank you for trying to help me!!! I will use your solution when its best suited.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.