BookmarkSubscribeRSS Feed
SASdevAnneMarie
Barite | Level 11

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!

5 REPLIES 5
Reeza
Super User
It would be easier to use FCOPY and FILENAME as then you don't need the macro loop or x command.

Alternatively if you're moving all files in the folder, you can use a wildcard operator in the x move statement instead.

Reeza
Super User
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;
SASdevAnneMarie
Barite | Level 11
Thank you Reeza! Actually, I have one file in one side and I would like to copy this file into multiple files. Is it possible?
Reeza
Super User
Sure, just do multiple calls to fcopy with the different file references. You may need to also do the filename statements again to create the references.
Reeza
Super User
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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 768 views
  • 0 likes
  • 2 in conversation