BookmarkSubscribeRSS Feed
user_
Calcite | Level 5

I have a list of files, say MyFiles. A sample file in the list would be C:\user\docs\Letter.csv.

I am able to check the existence by the following macro:

%macro Check();

proc sql noprint;
select Files, count(Files) into :list separated by "#", :cnt from MyFiles;
quit;

%do i= 1 %to &cnt ;
	%let file=%scan(&list.,&i., '#');
		%if %sysfunc(fileexist(&file.)) %then %do; 
		%end; 
		%else %do ; 
		%put ------The file &file. doesn’t exist.---------; 
		%end ; 
%end;
%mend;

 

How can I do the same for files located on remote UNIX server that I access via FTP?

 

Any help is greatly appreciated.

3 REPLIES 3
Patrick
Opal | Level 21

@user_

It appears you have a SAS dataset MyFiles which contains a list of expected files. You then check if these files actually exists using function FILEEXIST().

 

As far as I know this function doesn't work via FTP so you need to approach this differently.

 

Should your files on the remote server all exist in a single or only a few directories then you could create a directory listing of these remote folders and compare it with your expected files in MyFiles.

 

Here the code to create such a directory listing: http://support.sas.com/kb/43/962.html

 

user_
Calcite | Level 5

Hi Patrick,

 

thank you for your reply.

I have tried to create a directory listing of my files by the following code:

 

FILENAME ftp1 FTP '' LS HOST='myHost'
cd='myDirectory'
user='myUserName' prompt;

data;
infile ftp1;
input;
put _infile_;
run;

After entering my password, I get the following error: ERROR: Invalid Reply received for the STOR command.

 

Do you have any suggestion?

Patrick
Opal | Level 21

@user_

Your code is pretty close to what's documented in the SAS Note. 

 

I believe you could eventually get such an Error if the directory you want to list doesn't exist. May be use an absolute path as value for your CD parameter and ensure that this path exists (i.e. via WinSCP or Putty).

 

If this doesn't work and no one else can shed light on it then contact SAS TechSupport. Provide your real code, the log and also reference the SAS Note which provided the code template.

 

Once resolved please let us know the solution so we can learn something.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3252 views
  • 0 likes
  • 2 in conversation