现在的位置: 首页 > 综合 > 正文

检查变量,数据是否存在

2018年10月23日 ⁄ 综合 ⁄ 共 511字 ⁄ 字号 评论关闭

内容如题:检查某变量是否存在于数据中,某数据是否存在于数据库中

1.open,varnum函数

data class;
  set sashelp.class;
run;
proc print;
run;
data _null_;
   a=open('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;

 

2.exist函数

data _null_;
   d=exist('work.class','data'); /*data为数据类型,也可以为view等形式,存在默认为1*/
   if d=1 then put 'data set exists';
   else put 'data set does not exist';
run;

抱歉!评论已关闭.