05-31-2017 10:55 AM
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.
06-04-2017 05:03 AM - edited 06-06-2017 09:56 AM
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
06-06-2017 09:45 AM
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?
06-06-2017 10:04 AM
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.