See my answer in your other thread.
@annypanny wrote:
and what if it is a extrnal file not sas dataset? just asking for curiosity then we can't use libname then how can I do that?
SAS provides a function for copying files:
The documentation for the FDELETE function is just one down from the one for FCOPY. Everything else is just a matter of conditions and date calculations, read: basic data step programming.
/*Where the files in*/
%let repfic=H:\;
/*Where to move*/
%let repmove=H:\Batch;
/*ficrep contains all files name in the &refic*/
FILENAME ficrep PIPE "dir /b &repfic";
/*create table SAS = ficrep, it is necessary if in ficrep have the other file*/
data toto;
infile ficrep end=eof;
length x $50;
input x;
run;
/*traitement*/
data tata; /*data _null_;*/
set toto(where=(x like "online%"));
length _repname _repmove $200;
_y=put(date(),yymmddN.); /*date today 20200414*/
_over30=put(date()-30,yymmddN.); /*date aged 30day 20200315*/
_datex=substr(x,11,8); /*date in filename*/
_repname=cats("&repfic",x); /*H:\onlineuseryyyymmdd.txt*/
_repmove=catx(" ",x,"&repmove"); /* onlineuseryyyymmdd.txt H:\batch*/
if _datex le _over30 then do;
delete=1; /*if file aged over 30 days */
Call system(catx(" ","del /Q",_repname)); /*execute a command line windows del /q H:\onlineuseryyyymmdd.txt */
end; /* = suppress the file*/
if _datex = _y then do;
move=1;
call system(cats("move /Y &repfic\",_repmove)); /*move /y h:\onlineuseryyyymmdd.txt H:\batch*/
end; /* move the file to the path spécified*/
drop _:;
run;
I'm not sure thit is what you want but i hope this can help you.
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.