null - 如果在 sas 中过滤后输出为空,如何显示消息

标签 null sas output sas-stored-process

如果输入后结果为空,我会尝试显示一条消息或另一个包含空记录的表格。

见以下代码:

%if (&number ne) %then %do;

Proc print data=Lib.table;

Var “number”n “name”n “age”n;

Where “number”n=“&number”;

Run;

%end;

输入的是数字 此代码用于存储过程

解决方案 这是对我有用的解决方案。

%if (&number ne) %then %do; 

    Proc print data=Lib.table; 
        Var “number”n “name”n “age”n; 
        Where “number”n=“&number”; 
    Run; 

    Proc sql; 
        Select case  
                   when count()=0 then “No record found” 
                   Else put (count()),11.) 
               End as Number_of_records 
        From Lib.table 
        where 'number'n="&number"; 
    Quit; 

%end;

最佳答案

如果该值存在,您可以检查表,如果不存在,则显示一个 proc print 说明它是空的。

%STPBEGIN;

    %if(&number. NE) %then %do;

        proc sql;
            select count(*)
            from table
            where number = &number.
            ;
       quit;

        %if(&sqlobs. = 0) %then %do;
            data message;
                msg = 'No values were returned.';
            run;
    
            proc print data=message;
            run;
        %end;

    %end;

%STPEND;

为此,您的 STP 结果功能需要设置为“流”。

enter image description here

请注意,您还可以将 HTML 写入特殊文件引用 _webout 以显示消息。如果您这样做,请不要将 STP 包含在 %STPBEGIN/%STPEND 宏中,否则 _webout 将被写锁定。例如:

data _null_;
    infile datalines;
    file _webout; 

    put _INFILE_;

    datalines4;
<html>
    No data was returned.
</html>
;;;;
run;

关于null - 如果在 sas 中过滤后输出为空,如何显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69208221/

相关文章:

asp-classic - ASP Classic 检查 Recordset 中的数据库 NULL 值

mysql - 设置sql中where条件的默认参数

analytics - ParAccel 的 FastLoad(在 Teradata 中)等效项是什么?

sas - 仅列出数据集的列名

PHP寻找一个从字符串中获取值的函数

python - Spyder python 控制台输出

PHP 认为 null 等于零

java - 我如何检查Java中是否存在变量?

sas - SAS 中的编译与执行

python - 检查目标 : expected dense_1 to have 3 dimensions, 时出错,但得到形状为 (118, 1) 的数组