BookmarkSubscribeRSS Feed
annypanny
Quartz | Level 8
sure, how can I move a dataset in to different location?
By using X command?
annypanny
Quartz | Level 8
And how can I delete a file if it's age is more than 30 days?
Kurt_Bremser
Super User

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.

kelxxx
Quartz | Level 8
/*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.

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 20 replies
  • 4842 views
  • 9 likes
  • 5 in conversation