标题: how to check if a dataset has observation or not? [打印本页] 作者: shiyiming 时间: 2011-9-28 23:10 标题: how to check if a dataset has observation or not? e.g.:
data a;
input x;
cards;
;
run;
data b;
input x;
cards;
1
;
run;
how can I check a dataset has observation or not?
I am trying open() function, but I do not know how to use it, could anyone help? Thanks a lot.作者: shiyiming 时间: 2011-9-29 08:32 标题: Re: how to check if a dataset has observation or not? /*检查数据中存在的变量*/
data _null_;
a=open('sashelp.class');
b=varnum(a,'age'); /*变量age存在的话,b不为0*/
c=varnum(a,'sex');
if b=0 then put 'Variable does not exist';
else put 'Variable is located in column ' b+(-1) '.';
if c=0 then put 'Variable does not exist';
else put 'Variable is located in column ' c+(-1) '.';
run;
/*检查逻辑库中存在的数据*/
data _null_;
d=exist('sashelp.class','data'); /*data为数据类型,也可以为view等形式,存在默认为1*/
if d=1 then put 'data set exists';
else put 'data set does not exist';
run;作者: shiyiming 时间: 2011-9-29 14:53 标题: Re: how to check if a dataset has observation or not? %let c= %sysfunc(open(work.a, i)) /*a is your data set*/
%let records= %sysfunc(attrn(&c, NOBS));
%PUT &RECORDS作者: shiyiming 时间: 2011-9-30 02:04 标题: Re: how to check if a dataset has observation or not? Note: the libname and dataset name must in uper cases for all leters;
proc sql;
select nobs from dictionary.tables
where libname eq "WORK" and memname eq "A";
quit;
or :
Proc SQL;
select nobs from sashelp.vtable where libname eq "WORK" and memname eq "A";
Quit;