I'm using SAS 9.2 on OpenVMS to connect to an external data source over a socket specifed with a filename statement:
filename extsrc SOCKET "extserver:port" recfm=v;
data foo;
infile extsrc;
input;
.... some statements to read stuff ...;
run;
This works (as it should) 99% of the time. However, once in a while the program that is supposed to be listening on the remote port isn't. Currently this causes the program to exit with an error:
Error: Connection refused.
After which we try again, and it usually works. However, this is becoming tedious so I'd like to detect this error in the program and deal with it there. Does anybody know of a way to detect this type of error in SAS?
I've tried checking the validity of the fileref extsrc using the fileref() function, but that just returns -20005 , which means that the fileref is assigned but does not point to a local file (which is true). The error only becomes apparent when I use the fileref in a datastep, so I'd like to do something along the lines of:
data _null_;
rc=infile extsrc;
if rc=0 then do;
//whatever I want to do;
end;
else do;
//throw some error and try again later;
end;
run;
[update1] I'm trying the suggestions done below, but in true heisenbug fashion the problem has failed to crop up over the last few days, so I'm not sure what the final solution is yet. [/update1]
[update2] The error finally cropped up again. As per cmjohns answer, the value of syserr is 1012 after this error occurs. I'll now watch the value of syserr, and try again a fixed number of times if it fails. [/update2]
[update3]
I've had some code up an running for a few days now that works. The additional problem was that (of course) if &syserr
gets a value higher than 6 an error condition has occured, so depending on your errorabend/noerrorabend
setting this causes the program to end completely, or it causes the program to continue with obs=0
in syntaxchek mode. Both are undesirable. The solution is to set options noerrorabend nosyntaxcheck
before the datastep that produces this error. Additionally, if the error occurs I have to clear filename extsrc and reassign it. Finally, once this piece of code is complete I restore errorabend. If I restore nosyntaxcheck this causes SAS to detect the previous error condition and switch to syntaxcheck mode at that point which is also undesirable.
[/update3]
Have you tried testing the value of &syserr. Anything not 0 generally indicates a problem.
You can see return values here. Judging by the list I'd guess a 1012 or 1020 is what you are getting during the socket error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With