Hoi,
I want to use the folowing method to copy .egp and .sas files from source folder (sas grid) to destination folder (sas grid).
Is this the fastest and the saves way to copy files (egp and sas) to destination folder without corrupting the source and destination files.
Is this bullet proof, so when a developer opens the egp file when this macro is executing, etc.
%macro copy_files(destdir=,totobs=,type=);
%if &totobs. > 0 %then %do; %do i = 1 %to &totobs.; data _null_; TempPath= "&&©_&type._&i."; InName = reverse(TempPath); InName = substr( InName, 1, index( InName, '/') -1 ); InName = left( reverse( InName ) );
call symputx( 'Inname', Inname ); run;
%put %str(N)OTE: [ Copy from: &&©_&type._&i. ]; %put %str(N)OTE: [ Copy to: &destdir/&&Inname. ];
filename insource "&&&KOPIE_&type._&i."; filename outsource "&doeldir/&&Inname."; /* Byte for byte copy file */ data _null_; length filein 8 fileid 8; filein = fopen('insource','I',1,'B'); fileid = fopen('outsource','O',1,'B'); rec = '20'x; do while(fread(filein)=0); rc = fget(filein,rec,1); rc = fput(fileid, rec); rc =fwrite(fileid); end; rc = fclose(filein); rc = fclose(fileid); run;
filename insource clear; filename outsource clear;
%end; %end;
%mend copy_files;
Before i execute the macro, ik created a table with list of files in folders. The results of te table ar used to create variables that i passed to the macro. So assume that the work table exists with these rows as example:
enviroment
dir
sourcefile
fullpath
dirniveau
label
O
/srv/SAS/data/source/dev
project_a.egp
/srv/SAS/data/source/dev/project_a.egp
1
dev_source
O
/srv/SAS/data/source/dev
project_b.egp
/srv/SAS/data/source/dev/project_b.egp
1
dev_source
O
/srv/SAS/data/source/prod
project_a.sas
/srv/SAS/data/source/dev/project_a.sas
1
prod_source
O
/srv/SAS/data/source/prod
project_c.egp
/srv/SAS/data/source/dev/project_c.egp
1
prod_source
O
/srv/SAS/data/source/prod
project_c.sas
/srv/SAS/data/source/dev/project_c.sas
1
prod_source
%if (&TABLE_EXISTS eq 1) %then %do;
proc sql noprint; select fullpath into :COPY_SOURCEFILE_1 - :COPY_SOURCEFILE_999999 from WORK.FILELIST; %let SOURCEFILEOBS = &SYSNOBS.; quit; %put &SOURCEFILEOBS. files are found;
%put %str(NOTE: FILELIST existst and files are copied...);
%copy_files(destdir=/srv/destinationdir, totobs=&SOURCEFILEOBS, type=SOURCEFILE);
%end;
... View more