Hello friends, i am running below code (one of community user helped to build this code) and everything running fine, just wants to check couple of things.... Goal: goal to run this code to transfer files from one folder to another folder but only if files in target directory doesn't have today's date stamp. Good thing: is code running fine without any error need to check: is this code check date stamp for each file and then transfer all files to target directory correctly and then code check date stamp for next file and transferring all files again and doing something for every time... what i wants: is check date stamp for all files in target directory and if date is not today's date for any particular file then transfer that particular file then go for next file and then check for created date and if created date is not today then transfer that particular file only.....and same thing for every other file... please help... please let me know if any part is not clear... Thanks a lot...!!! /*in this filename statement, mentioned path has all NEW mdb files created which needs to be transfer*/ /*still checking created date for all these NEW mdb files*/ filename new_mdb pipe 'dir "j:\jim\db\*.mdb" /tw'; data new_files; attrib buffer format=$2000. file_last_written_date format=date9. file_last_written_time format=time5. am_pm format=$2. file_size format=$30. file_name format=$50.; infile new_mdb truncover ; input buffer $2000.; /* Remove some extra info */ if substr(buffer,1,5) in ("Volum","Direc") or index(buffer,"<DIR>")>0 or index(buffer,"Dir(s)")>0 or index(buffer,"File(s)")>0 then delete; file_last_written_date=input(put(scan(compbl(buffer),1,' '),$10.),mmddyy10.); /* note dependant on system settings */ file_last_written_time=input(put(scan(compbl(buffer),2,' '),$5.),time5.); am_pm=scan(compbl(buffer),3,' '); file_size=scan(compbl(buffer),4,' '); file_name=trim(scan(compbl(buffer),5,' ')) ; Username=scan(file_name,1,'_'); if file_name = ' ' then delete ; run ; proc print data=new_files; var file_name file_last_written_date; run; proc sort data=work.new_files; by Username; run; /*in this filename statement, mentioned path is where files need to be transfered to BUT only those files WHICH HAS NOT TODAY'S TIME STAMP*/ /*check for created date*/ filename abc_ex pipe 'dir "z:\SHARES\db\USA\*.mdb" /tw'; data exist_files; attrib buffer format=$2000. file_last_written_date format=date9. file_last_written_time format=time5. am_pm format=$2. file_size format=$30. file_name format=$50.; infile abc_ex truncover ; input buffer $2000.; /* Remove some extra info */ if substr(buffer,1,5) in ("Volum","Direc") or index(buffer,"<DIR>")>0 or index(buffer,"Dir(s)")>0 or index(buffer,"File(s)")>0 then delete; file_last_written_date=input(put(scan(compbl(buffer),1,' '),$10.),mmddyy10.); /* note dependant on system settings */ file_last_written_time=input(put(scan(compbl(buffer),2,' '),$5.),time5.); am_pm=scan(compbl(buffer),3,' '); file_size=scan(compbl(buffer),4,' '); file_name=trim(scan(compbl(buffer),5,' ')) ; Username=scan(file_name,1,'_'); if file_name = ' ' then delete ; run ; proc print data=exist_files; var file_name file_last_written_date; run; proc sort data=work.exist_files; by Username; run; /*creating macro variables*/ data work.chk_date; set work.exist_files end=EOF; call symput('file'||trim(left(_n_)), trim(file_name)); call symput('crdate'||trim(left(_n_)), put(file_last_written_date,date9.)); if eof then call symput('filecount',_n_); run; %put _all_; /*using control table to get "username" and "location"*/ /*tbl_user has all the user's name as "Username" Location as "USA" or "BRAZIL" or "INDIA"* / libname test 'g:\SHARES\jim'; data work.control_tbl; set test.tbl_user; run; proc sort data=control_tbl; by Username; run; /*Filter for USA users*/ data work.usa_users; set work.control_tbl; if Location="USA"; run; proc sort data=work.usa_users; by Username; run; /*PROC FORMAT for USA sharepoint*/ proc format; value $usa_location "USA"= "z:\SHARES\db\USA"; run; /*check output for PROC FORMAT*/ proc format library=work.formats fmtlib; select $usa_location; run; quit; /*one newly created variable "targetdir"*/ %let path=j:\jim\db; data transfer; merge new_files (in=in1) usa_users (in=in2); by Username; if in1 and Location="USA"; targetdir=put(Location,$usa_location.); copycmd=catx(' ', 'copy' ,quote(cats("&path\", file_name)) ,quote(cats(targetdir)) ); run; proc sort data=work.transfer; by file_name; run; options mprint mlogic symbolgen; %macro loop_files; %if &filecount>0 %then %do; %do i=1 %to &filecount; %check_new_date(&&file&i, &&crdate&i); /*recursive macro syntax - &i resolve first and then &file1*/ %end; %end; %mend loop_files; %macro check_new_date(thisfile, thiscrdate); %if "&thisfile"d =%sysfunc(today()) %then %do; data _null_; put "file got transferred by first process"; run; %end; %else %do; data _null_; set transfer; infile cmd pipe filevar=copycmd; input @; run; %end; %mend check_new_date; %loop_files;
... View more