proc sql outobs= 触发 SAS 警告

proc sql outobs= triggers SAS warning

我们目前使用 %runquit 宏函数,详见此处 (http://analytics.ncsu.edu/sesug/2010/CC07.Blanchette.pdf)。 %runquit 宏如下所示。当遇到错误时,它基本上会停止 运行 任何更多 SAS 代码,并且可以用作 runquit 语句的替代:

%macro runquit;
  ; run; quit;
  %if &syserr %then %abort cancel;
%mend;

因为在proc sql中使用outobs语句会触发系统错误(即使指定了nowarn选项)这意味着我们无法在需要时使用%runquit宏使用 outobs= 选项。

以下示例将生成以下警告消息:

proc sql noprint outobs=3 /*nowarn*/;
  create table tmp as
  select age, count(*) as freq
  from sashelp.class
  group by 1
  order by 2 desc
  ;
%runquit;

WARNING: Statement terminated early due to OUTOBS=3 option.

感谢 SAS 的完全不必要的警告。这种行为显然是预期的,因为我明确地编写了代码来要求它。当我们在 set 语句中指定 inobs=outobs= 时,我没有看到警告。为什么 proc sql 得到特殊待遇?

有什么方法可以通过 proc sql 中的 outobs= 选项禁用警告问题吗?或者,是否有另一种方法可以限制 proc sql 的输出行而不会产生错误?

假设您可以执行完整的 SQL 语句,您可以使用包含 obs 限制的数据步骤视图来解决这个问题。

proc sql noprint ;
  create table tmp as
  select age, count(*) as freq
  from sashelp.class
  group by 1
  order by 2 desc
  ;
%runquit;

data tmp_fin/view=tmp_fin;
  set tmp(obs=3);
%runquit;

或者把SQL语句做成视图,用数据步骤做数据集。

proc sql noprint ;
  create view tmp_view as
  select age
       , count(*) as freq
  from sashelp.class
  group by 1
  order by 2 desc
  ;
quit;
data tmp;
  set tmp_view(obs=3) ;
run;

考虑到 I/O 不是一个很大的限制,这可能是您的选择之一,这里 reset outobs= 选项与 nowarn 可以解决问题,但要付出 IOs 的代价。

proc sql;
  create table test as
   select * from sashelp.class;

  reset outobs=10 nowarn;

  create table test1 as 
   select * from sashelp.class;
quit;