Reputation: 87
I want to delete files from backup if there are more than three files.
filename parent '/abc/cde';
if is less than three files in parent directory sas code does nothing. The name of sample file: ABC_1117_02MAY2016.txt - all have the same length.
if count()>3 then sas code returns all dates from substring: 02MAY2016, because I want to delete all files with dates less than the third largest.
data all_files;
keep substr_date;
did=dopen("parent");
if dnum(did)>3 then do;
do i=1 to dnum(did);
wycinek_z_daty=substr(dread(did,i),10,9);
output;
end;
end;
run;
I sort it
proc sort data=all_files;
by descending substr_date;
run;
It is what I don't want to delete
data backup;
set all_files(obs=3);
run;
I create a table with all what I want to delete.
proc sql;
create table delete as
select*from all_files except select*from backup;
quit;
How I can remove these files that I have in 'delete' table? I know I supposed to use fdelete funtion
%macro test;
%do i=1 %to &sqlobs;
fdelete('/abc/cde/ABC_1117_&something. Can I use macro variable for i? because only date in name is changing?)
%end;
%mend;
Thanks for help, aola
Upvotes: 0
Views: 903
Reputation: 63424
Once you have the delete
table, I would write the macro like so:
%macro delete_file(file=);
fdelete("&file.");
%mend;
Then you can call it:
proc sql;
select cats('%delete_file(file=abc_1117_',substr_date,')')
into :dellist separated by ' '
from delete;
quit;
&dellist.;
I would probably just save the whole filename in delete
dataset and then use that rather than hardcoding abc_1117_
, but that's your call.
Upvotes: 0