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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 3 replies
  • 2719 views
  • 0 likes
  • 2 in conversation