如果输入后结果为空,我会尝试显示一条消息或另一个包含空记录的表格。
见以下代码:
%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 结果功能需要设置为“流”。
请注意,您还可以将 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/