- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I need to move a sas data set from /workspace/data to /workspace/data/archive when it hasn't been used for more than 2 weeks. I need to run the program daily. May I know how to code this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Define "used". Date Created, modified or read are different ways of defining "used".
You can easily get the first two from SAS with code such as:
proc sql; create table work.junk as select memname, libname, crdate, modate from dictionary.tables where libname='WORK' ; quit;
You can use DATEPART on either of CRDATE or MODATE (both are datetime values) and compare to the TODAY() function value to create code to copy the data sets to a different library.
I don't think SAS keeps a "last read" anywhere which would lead to using the external file functions such as DOPEN, DNUM, DREAD, FOPEN, FOPTNUM, FOPTNAME and FINFO.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please try the below code, check the comments for code understanding, i tested it and it worked
But you need to run this everyday manually to move the files, please test and let me know if it helps.
/*use the x command in sas */
x 'ls -l --time-style="+%d/%m/%Y" ~path_of_files*.txt > ~path_of_sample_file_with_list_of_files/sample.txt';
/*get the files that need to be moved to other location*/
proc import datafile='~path_of_sample_file_with_list_of_files/sample.txt' out=test dbms=tab replace;
getnames=no;
run;
data test2;
length files filenames transfer $200.;
set test;
filedate=input(substr(var1,36,10),ddmmyy10.); /*get the file dates*/
filenames=scan(substr(var1,46),8,'/');/*get the filename*/
files=substr(var1,46);/*get the file path*/
today=input("&sysdate9.",date9.);/*todays date*/
format filedate today date9.;
if (today-filedate)>14 then flag=1;/*flag those records where the files are more than 2 weeks old i.e. more than 14 days */
transfer='mv '||strip(files)||" ~new_path_of_files_/"||strip(filenames); /*create a variable with mv i.e., move command to move the flagged files from present location to a differnt location*/
if flag=1 then do;
call execute('x '||strip(transfer)||';');/*call execute to use the x command to move the files*/
end;
run;
Jag