BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ashna
Obsidian | Level 7

I have 10 files in one directory in FTP which has to be moved to another directory in FTP. For file move process I'm using Fcopy. 

 

For all the 10files -starting of the filename is common (Report), Only the datepart and endpart of the file changes every month. I defiend datepart and endpart of the filenames to macro as the endpart of the filename are saved in table data as fname. 

 

Filename examples :

1. Report_31-10-2018_wind.xlsx

2. Report_31-10-2018_water.xlsx etc.

 

Dataset : Data

fname

wind

water

health

.

.

.

proc sql;
	select count(fname) into:n trimmed from data;
	select distinct fname into:fn1 - :fn%left(&n)
			from data;
run;

data _null_;
	 call symput ('datepart',put(intnx('month',today(),0,"b"),yymmdd10.));
run;


data _null_;
			length msg $384;
			i=filename('in',"/temp/files/Report&datepart._&&fn&n..xlsx", "DISK", "RECFM=N");
			o=filename('out',"/temp/files/backup/Report&check._&&fn&n..xlsx", "DISK", "RECFM=N");

			rc=fcopy('_in', '_out');
				if rc=0 then
			put 'Copied _in to _out.';
				else do
					msg=sysmsg();
				  put rc= msg=;
	end;
i=filename('in');
o=filename('out');
run;

This code works perfect without errors. But moves only 1 file ie., fn10 file but not rest of the files.

 

Can any advice what I'm missing here. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Do you already have the filenames in a a data set? If so you don't need a macro at all. Use FCOPY within the data step directly. Your code stays almost the same.

1. add a set statement to point to the data set with the filenames.
2. Change the files name using string functions instead of macro functions
3. Pass the variables to the FCOPY directly.

View solution in original post

4 REPLIES 4
Reeza
Super User
N never changes - you have no loop. You can use a data step with a do loop and make the string and then pass it to FCOPY or you can add a macro loop.
ashna
Obsidian | Level 7

Can I define it as following 

%macro fend;
	%do i=1 %to 5;
		%put filename=&&fn&i;
	%end;

And use fend instead of &fn&n in following statement?

 

i=filename('in',"/data/skynet/files/custom_billing/Cat/NSMIS/BNC/&cname&check._&fend..xlsx", "DISK", "RECFM=N");

Reeza
Super User
Do you already have the filenames in a a data set? If so you don't need a macro at all. Use FCOPY within the data step directly. Your code stays almost the same.

1. add a set statement to point to the data set with the filenames.
2. Change the files name using string functions instead of macro functions
3. Pass the variables to the FCOPY directly.
ashna
Obsidian | Level 7

Thanks, for the advice,

 

I was over think for the simple solution 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1112 views
  • 2 likes
  • 2 in conversation