如何检查是否通过此条件获得值?
data ad01(keep=str);
length str $1024;
set Address(where=(Type_="1"));
///if resultat not null do something
run;
答案 0 :(得分:0)
我假设您的意思是,如果有任何符合您的WHERE条件的记录,您希望以某种方式进行处理。
您可以使用
data ad01(keep=str);
length str $1024;
set Address(where=(Type_="1"));
*do something;
run;
如果数据集没有TYPE _ =“ 1”的记录,则该步骤将在SET语句执行并命中文件标记的(逻辑)结尾时结束。如果存在满足条件的记录,则将执行SET语句之后的所有语句。
如果“做某事”是指执行其他步骤(而不仅仅是语句),则这可能会成为宏语言问题。您希望使用带有%IF语句的宏的地方,例如:
%if %anyobs(Address(where=(Type_=“1”))) %then %do;
*data steps and PROC steps and whatever here;
%end;
有关函数样式的%anyobs宏的示例,请参见例如http://www2.sas.com/proceedings/sugi26/p095-26.pdf或https://www.devenezia.com/downloads/sas/macros/index.php?m=anyobs或http://www.datasavantconsulting.com/roland/Spectre/utilmacros/nlobs.sas
答案 1 :(得分:0)
正如@Quentin所说,这成为一个宏问题。一种方法是将计数捕获到宏变量中。
/* an example where count is zero*/
proc sql noprint;
select count(*) into :cnt from sashelp.class
where name = 'unknown';
%put &cnt;
/* Here datastep gets aborted if count = 0 */
data class;
if &cnt = 0 then abort;
set sashelp.class;
run;
/* above query works when there is count gt 0 see the example below*/
proc sql noprint;
select count(*) into :cnt from sashelp.class
where trim(name) = 'Alfred';
%put &cnt;
data class;
if &cnt = 0 then abort;
set sashelp.class (where =(trim(name) = 'Alfred'));
run;
答案 2 :(得分:0)