where语句实在执行数据连接(set),合并(merge),更新(update)或者修改之前的操作,使用where语句时,应为sas系统只是从输入的数据集中读入满足条件的观测,所以这样的SAS程序更加有效。
<code>where age between 18 and 25;
where taxes between salary*0.3 and salary*0.7;
where age is missing;
where name like 'D_AN';
where name like 'd_an%'
where x in (1,2,3,4,5);
where=(age in (1,2,3,4,5);
where=(age=8);/<code>where和子集if 语句的比较
在data步中where语句和子集if语句最大从差别就是where在观测读入到程序向量之前起作用,而子集if语句对已经在程序数据向量的观测起作用。where不是执行语句,子集If是可执行语句。
从大的SAS数据集中选择一个小在子集时用WHERE语句会币IF语句效率高很多,因为在进行选择之前SAS没有从大数据集中一定所有的观测到小的数据集效率中。
<code>data a;
set hah;
if _n_<100;
run;
data a;
set hah;
where _n_<100;
run;
/*错误语句,必须使用IF,where语句不能控制Sas的自动变量*//<code>