You will find my code below. However, I would like to check if the dataset exist before making the proc datasets but
my if statement does not seems to work. Is there a way to correct that or an options with the proc datasets to avoid trying to copy a dataset that does not exist.
Please note that the call execute with the proc datasets seems to work properly except due to the if statement that is not
working properly, it may try to copy a dataset that does not exist giving error into the log file
/******* Check if a dataset exist using a macro function % and the macrovariable exist (1 for yes, 0 for no)*/ /* Example of call for the macro function %checkds : %checkds(sashelp.class); %put &=exist; *************/ %macro checkds(dsn); %global exist; %if %sysfunc(exist(&dsn)) %then %do; %let exist=1; run; %end; %else %do; %let exist=0; %end; %mend checkds;
/***********************************************************/ %let path1=/source; %let path2=/destination;
data _null_; length folderpath1 folderpath2 $60 fname $20 L 3.; array ld {9} $8 ('20210729' '20210730' '20210731' '20210801' '20210802' '20210803' '20210804' '20210805' '20210806'); array lcp {5} $2 ('A' 'B' 'C' 'D' 'E'); array bc {2} $4 ('auto' 'habi'); do i=1 to 1 /*dim(lcp)*/;*do i=1 to 5; if lcp(i) in ('A','B') then L=1; else L=2; put L; do j=1 to L;*do j=1 to L (1 or 2); folderpath1=catx('/',"&path1.",lcp(i),bc(j)); folderpath2=catx('/',"&path2.",lcp(i),bc(j));
/******* assign two libraries ****/ call execute(cat('libname src1 spde'," ","'",folderpath1,"';")); call execute(cat('libname dest1 spde'," ","'",folderpath2,"';")); /********* copying the dataset for src1 to dest1 ************************/
do k=1 to dim(ld); fname=cat(lcp(i),bc(j),'_prm_d',ld(k)); /* checking if the dataset exist */ call execute(cats('%checkds(src1.',fname,');')); if "&exist." eq 1 then do; put fname; call execute(cat('proc datasets lib=src1;','copy out=dest1 memtype=(data);','select ',cats(fname),';run;')); end; end; end; end; run;
... View more