Hello Experts,
Actually, I rename the file with move statement :
proc sort data=pdf_corr nodupkey;
by NOM_PDF1;
run;
DATA _null_;
call symputx ('nb', nobs);
SET pdf_corr nobs=nobs;
run;
%put valeur &nb.;
%do i=1 %to &nb.;
data _NULL_;
set pdf_corr(obs=&i);
CALL SYMPUTX(COMPRESS('PDFACOL_CORR_ANO'),NOM_PDF);
CALL SYMPUTX(COMPRESS('PDFACOL_CORR'),NOM_PDF1);
run;
option xwait xsync;
X move "\\xxxxxx\PDF_20230427\&PDFACOL_CORR_ANO."
"\\xxxxxxx\PDF_20230427_V2\&PDFACOL_CORR.";
%end;
I would like to rename the file by creating multiple documents, for example, if I have the file LPKPT.pdf I would like to rename this file on LPKP_M2.pdf, LKP_E.pdf. Do I need to use the copy statement ?
Precisely, I have one file in one side and I would like to copy this file into multiple files. Is it possible?
Thank you for your help!
data results;
set pdf_corr;
length src dst $ 8 ;
*create path to files;
source_file =catt("\\xxxxx\PDF_20230427\", NOM_PDF1);
dest_file = catt("\\xxxxx\PDF_20230427_V2\", NOM_PDF1);
*create filerefs for copy function;
rc1=filename(src,source_file,,'recfm=n');
rc2=filename(dst,dest_file,,'recfm=n');
*copy;
rc3=fcopy(src,dst);
*deassign filerefs;
rc4=filename(src);
rc5=filename(dst);
run;
data results;
set pdf_corr;
length src dst dst2 $ 8 ; *create path to files;
source_file =catt("\\xxxxx\PDF_20230427\", NOM_PDF1);
dest_file = catt("\\xxxxx\PDF_20230427_V2\", NOM_PDF1); *create filerefs for copy function;
dest_file2 = dest_file = catt("\\xxxxx\PDF_20230427_V2\", NOM_PDF2);
rc1=filename(src,source_file,,'recfm=n');
rc2=filename(dst,dest_file,,'recfm=n');
rc2_1 = filename(dst2, dest_file2, , 'recfm=n');
rc3_1=fcopy(src,dst); *deassign filerefs;
rc3_2=fcopy(src,dst2); *deassign filerefs;
rc4=filename(src);
rc5=filename(dst);
rc6 = filename(dst2);
run;
Assuming you have another variable with the name, then the above is a brief example. If every file is copied multiple times you can generate those names and create a loop to loop over the names rather than repeat the code but it depends on exactly what you're doing.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.