OpenVMS 下 SAS 中套接字的错误处理

发布于 2024-07-17 22:42:43 字数 1440 浏览 13 评论 0原文

我在 OpenVMS 上使用 SAS 9.2 通过文件名语句指定的套接字连接到外部数据源:

filename extsrc SOCKET "extserver:port" recfm=v;

data foo;
infile extsrc;
input;
.... some statements to read stuff ...;
run;

这在 99% 的情况下都有效(应该如此)。 然而,有时本应监听远程端口的程序却没有监听。 目前,这会导致程序退出并出现错误:

Error: Connection refused.

之后我们重试,通常会起作用。 然而,这变得很乏味,所以我想检测程序中的这个错误并在那里处理它。 有谁知道 SAS 中检测此类错误的方法吗?

我尝试使用 fileref() 函数检查 fileref extsrc 的有效性,但只返回 -20005 ,这意味着 fileref 已分配但不指向本地文件(这是正确的)。 仅当我在数据步骤中使用 fileref 时,该错误才会变得明显,因此我想做一些类似的事情:

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] 我正在尝试下面完成的建议,但在真正的 heisenbug 时尚中,问题未能突然出现这几天都在讨论,所以我不确定最终的解决方案是什么。 [/更新1]

[更新2] 错误终于又出现了。 根据 cmjohns 的回答,发生此错误后 syserr 的值为 1012。 我现在将观察 syserr 的值,如果失败则重试固定次数。 [/更新2]

[更新3] 我已经运行了一些代码几天了,现在可以工作了。 另一个问题是(当然)如果 &syserr 获得的值高于 6,就会发生错误情况,因此根据您的 errorabend/noerrorabend 设置,这会导致程序完全结束,或者导致程序在语法检查模式下以 obs=0 继续。 两者都是不可取的。 解决方案是在产生此错误的数据步骤之前设置 options noerrorabend nosyntaxcheck。 此外,如果发生错误,我必须清除文件名 extsrc 并重新分配它。 最后,一旦这段代码完成,我就会恢复 errorabend。 如果我恢复 nosyntaxcheck,这会导致 SAS 检测到先前的错误情况并在此时切换到语法检查模式,这也是不可取的。 [/更新3]

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

活泼老夫 2024-07-24 22:42:43

您是否尝试过测试 &syserr. 任何不为 0 的值通常都表明有问题。

您可以在此处查看返回值。 从列表来看,我猜测 1012 或 1020 是您在套接字错误期间得到的结果。

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.

瑶笙 2024-07-24 22:42:43

你能测试数据 foo 吗? 如果没有数据则可以设置重试循环,如果数据存在则继续?

就像是:

再次做:

(在此处插入您的套接字代码)

/*查看ds是否存在*/ 

  %如果不是 %sysfunc(exist(data.foo)) %则 %do ; 

  /*如果ds不存在则*/ 

  %put 警告:该文件不存在!   ; 

  %再次执行; 

  %结尾; 
  

Can you test for the data foo? If there is no data then you can set a retry loop, if data exists, continue?

Something like:

doitagain:

(insert your socket code here)

/*see if ds exists*/

%if not %sysfunc(exist(data.foo)) %then %do ;

/*if the ds does not exist then*/

%put WARNING: The file does not exist! ;

%goto doitagain;

%end;
酒与心事 2024-07-24 22:42:43

我知道这是一个过时的线程,但是:

SYNTAXCHECK 很高兴拥有; 而不是因为 &syserr (实际上是 &syscc)问题而裸露运行,一旦您越过了该敏感代码部分,您就可以将其清除为最后已知的正确值。

以下是我必须妥善处理 DB2 中的锁定表错误时的相关代码:

/*** temporarily disable ERRORABEND and SYNTAXCHECK ***/
options NOERRORABEND NOSYNTAXCHECK ;

/* save &syscc for laster restoration */
%let presyscc=&syscc;

%do until (...);
  /* do a task, handle some possible errors */
%end;

/* restore &syscc */
%let syscc=&presyscc;

/*** re-enable ERRORABEND and SYNTAXCHECK ***/
options ERRORABEND SYNTAXCHECK ;

I know this is a stale thread, but:

SYNTAXCHECK is nice to have; instead of running naked because of the &syserr (actually &syscc) issue, you can just clear it to last-known-good value once you're past that sensitive section of code.

Here are the relevant bits of code for when I had to gracefully handle locked-table errors from DB2:

/*** temporarily disable ERRORABEND and SYNTAXCHECK ***/
options NOERRORABEND NOSYNTAXCHECK ;

/* save &syscc for laster restoration */
%let presyscc=&syscc;

%do until (...);
  /* do a task, handle some possible errors */
%end;

/* restore &syscc */
%let syscc=&presyscc;

/*** re-enable ERRORABEND and SYNTAXCHECK ***/
options ERRORABEND SYNTAXCHECK ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文