SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 690|回复: 3
打印 上一主题 下一主题

how to check if a dataset has observation or not?

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2011-9-28 23:10: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.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2011-9-29 08:32:54 | 只看该作者

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;
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2011-9-29 14:53:33 | 只看该作者

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
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2011-9-30 02:04:40 | 只看该作者

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;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-5-7 22:49 , Processed in 0.069298 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表