BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sathyarajamohan
Calcite | Level 5

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

 

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;

 

 

 

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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;

 

 

 

Reeza
Super User

 

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;

 

 

 

sathyarajamohan
Calcite | Level 5

Thank you for helping to solve the issue. Your suggested solution worked for me!!

Ksharp
Super User

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';
sathyarajamohan
Calcite | Level 5

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.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 5 replies
  • 559 views
  • 1 like
  • 4 in conversation