DATA Step, Macro, Functions and more

Stop the program if an error connecting to an FTP ocurred

Reply
Contributor
Posts: 68

Stop the program if an error connecting to an FTP ocurred

Hi all

I am trying to implement a line code for stop de program when the file does not exits in the ftp server but without sucess.

Sometimes I connect to an ftp for a file and it's no there anymore.

Sas write an Error in the log but continue processing, my intention is to stop the code after this error ocurred.

here were are an example of my code

FILENAME aaa ftp  "ftp path." user="&user." pass="&pass." debug

host='nameofthehost' rcmd='site rdw' cd='..';

data test (compress = binary);

infile aaa missover lrecl=1420 recfm=F;

input

    @1 wwww $EBCDIC8.

    @10 eeeee $EBCDIC39.

    @51 rrrrrr $EBCDIC4.

    @56 ttttt $EBCDIC39.

if &syserr. ne 0 then abort;

run;

How can I achieve my purpose?

Thanks

Valued Guide
Posts: 2,175

Re: Stop the program if an error connecting to an FTP ocurred

Use the LS  or LIST option on the FTP infile to get a list of files in the folder

Only if it's there should you try to read it.

  that option will be found on the FTP filename statement - probably not on INFILE

Contributor
Posts: 68

Re: Stop the program if an error connecting to an FTP ocurred

Thanks Peter

The option LIST is not working for me

'Invalid Reply received for the STOR command..'

and the line of code if &syserr. ne 0 then abort; it doesn't anyting because the code continue to run Smiley Sad

Valued Guide
Posts: 2,175

Re: Stop the program if an error connecting to an FTP ocurred

Perhaps your FTP server does not understand command LIST.

Have you tried LS?

Please show the code and log

Contributor
Posts: 68

Re: Stop the program if an error connecting to an FTP ocurred

I have no access to these options, In any case my intention is not to see the files that are in the server but it stop the program for prevent to run without observations due to not to download the data from the server.

Valued Guide
Posts: 3,208

Re: Stop the program if an error connecting to an FTP ocurred

SAS(R) 9.4 Language Reference: Concepts, Third Edition  Error processing is a long long story.

The &syserr and &sasrc are macro-variables these are set after a proc/datstep processing.
Builing logic on macro-variables is macroprocessing in this case to be implemented after the datastep processing.

There are differences in the error-condition follow up.

In interactive mode it can proceed a lot, in batch mode it is more often halting. When you are using interactive mode expect the need for manual intervention.  

You can delete the dataset test and after the datastep has run verify the number of obs aside other things (macro) to do follow up as you like. 

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 5 replies
  • 570 views
  • 0 likes
  • 3 in conversation