BookmarkSubscribeRSS Feed
Yura2301
Quartz | Level 8
Hi All,
So I use standard FTP connections for accessing to remote files:
Smth. like this:

filename indir ftp '' user='username' pass='xxxx' host='yyyy' DIR;

data _null_;
infile indir;
input;
%put _infile_;
run;

Sometimes connections fails and notes throws to the log:
NOTE: <<< 421 Service not available, closing control connection.

So can I somehow indicate if such situations happens(if connections fails)?
I tried to compare global macro vars which creates if such situation occur with gl. macro vars which creates if file loaded successfully, but looks like they are the same.
May be the only one way is to get target file size, if it 0 then attempt is not successful, but must be some more clever and simple way to resolve this problem.
So how can I know that ftp connections were finished successfully?

Thanks!
3 REPLIES 3
FriedEgg
SAS Employee
Not sure if this will aide you since i do not have a ftp with which to verify but you could try to use fileref function:

%macro check_ftp_connection(inf=);
%if %sysfunc(fileref(&inf)) ne 0 %then
%put %sysfunc(sysmsg());
%mend;

filename indir ftp user='user' pass='pass' host='host' dir;

%check_ftp_connection(inf=indir);

Since you said it is not generating a error I am not sure that this will benefit. Message was edited by: Fried Egg
Yura2301
Quartz | Level 8
Thanks Fried!
But the file creates just with 0 length, so such functionality isn't suitible.

I rid of this problem by using such code:

data test;
infile indir(filename);
input;
a='0';
%put _infile_;
run;

If record_count>0 then %put ok %else %put error;

But I still think that must be some better solution.

Anyway thanks!
Ksharp
Super User
You need a auto macro variable to check the status of filename statement.
[pre]
filename indir ftp '' user='username' pass='xxxx' host='yyyy' DIR;

data _null_;
infile indir;
input;
%put _infile_;
%put return code of filename statement : &sysfilrc ;
run;
[/pre]



Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 758 views
  • 0 likes
  • 3 in conversation