【问题标题】:Use ERROR in if statement of SAS在 SAS 的 if 语句中使用 ERROR
【发布时间】:2016-04-28 11:40:08
【问题描述】:

我刚刚写了一个用于登录远程服务器的宏,当然是一个简单的宏

%macro sign(servername);
%put                                                         ;
%put *********   You are now entering the server   ********* ;
%put *********                                     ********* ;


signon &servername user=_promopt_ password=_prompt_;

%if error %then

%put There is a problem in logging in;

%else 


%put *********                                     ********* ;
%put *********                                     ********* ;
%put *********   You are now ready to use server   ********* ;
%put *********                                     ********* ;
%put *********                                     ********* ;
%mend;

所以在这里我只想在日志中输入一些内容,说明它是否因任何原因引发错误。这可能是密码或连接错误或其他任何东西,我想在 %Put 的帮助下打印一条语句,但不确定如何.

【问题讨论】:

  • 我们过去用来测试远程会话是否正常工作的方法是重新提交代码,该代码将使用 sysrput 更改本地 SAS 会话中宏变量的设置。
  • 嗨,Tom,如果由于某种原因登录失败,我只想使用 put 语句打印一些我想要的行。

标签: sas


【解决方案1】:

您应该能够在 SIGNON 语句中使用 CMACVAR 选项。

signon &servername user=_promopt_ password=_prompt_ cmacvar=cerror;
%if &cerror %then

CMACVAR=值

指定宏变量的名称,SAS 在其中存储指示当前登录状态的代码。执行 SIGNON 时,SAS 检查登录状态并将返回码 0、1 或 2 存储在指定的 CMACVAR 变量中。

在 SIGNON 处理完成后生成返回码,您指定的名称成为当前服务器会话的默认名称。然后可以通过编程方式查询 CMACVAR 宏变量以了解登录的处理状态(已完成、失败或正在进行中)。请参阅 SIGNON 中的 CMACVAR 宏变量值,了解每个返回码的含义。

CMACVAR Macro Variable Values in SIGNON
Value Description
0 The sign-on is complete.
1 The sign-on failed.
2 You have already signed on to the current server session.
3 The sign-on is in progress.

注意:如果 SIGNON 命令或语句由于语法错误而失败,则宏变量未设置。

【讨论】:

  • 哇,这就是我要找的东西,非常感谢 TOM。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-19
  • 2014-02-04
  • 1970-01-01
  • 2018-08-12
  • 2022-01-13
相关资源
最近更新 更多