Search code examples
sas

How to copy all datasets from one library to another, but skipping already copied datasets, in SAS


I wanna copy all existing datasets from one library to another, but skipping the datasets that I have already copied, without needing to specify the names of the previously copied datasets.

The context is the following: there was an issue in the first time that I was copying the library and the proccess was halted in the middle. I am doing a security backup of many libraries and this is an issue that happens often. Last time this happened, I specified all previously copied datasets in the exclude statement. But is there a way of SAS detecting the already existing datasets in the output library and skipping them from being copied again?

The code I used:


%macro BACKUP;
%do year=1983 %to 2000;

options compress=yes;
proc copy in=jobs&year. out=backup&year. memtype=data;
*exclude tmp_: data1 companies links education;
run;

%end;
%mend;
%BACKUP;


Solution

  • You can use the NOREPLACE option to prevent overwriting existing members in the destination library.

    options noreplace ;
    
    proc copy in=jobs&year. out=backup&year. memtype=data;
    *exclude tmp_: data1 companies links education;
    run;
    
    options replace ;