在 SAS 中使用 where 表达式和 not in 运算符
Using where expression with not in operator in SAS
我有一个名为 CityData 的数据库 table,它是通过 ODBC 使用 SAS 查询的。 table 有一列 City,其中有 Missing/Null 个值。 SAS 中的以下数据步骤未给出预期结果 -
Data New;
set CityData;
where pop> 10000 and City not in ('Mumbai')
run;
以上代码从输出数据集中排除了 Null 值。但是,以下代码按预期工作
Data New;
set CityData;
where pop > 10000 and (City not in ('Mumbai') or City is Null);
run;
为什么?我正在使用 Windows SAS 版本 9.4。
这是由于 DBMS 评估空值的方式所致。 libname 引擎通过隐式传递将您的 where
语句发回,计算结果为:
where pop> 10000 and City ne 'Mumbai'
null <> 'Mumbai'
= null,因此没有任何返回。
您的 where 语句中还缺少一个分号。
Data New;
set CityData;
where pop> 10000 and City not in ('Mumbai');
run;
我有一个名为 CityData 的数据库 table,它是通过 ODBC 使用 SAS 查询的。 table 有一列 City,其中有 Missing/Null 个值。 SAS 中的以下数据步骤未给出预期结果 -
Data New;
set CityData;
where pop> 10000 and City not in ('Mumbai')
run;
以上代码从输出数据集中排除了 Null 值。但是,以下代码按预期工作
Data New;
set CityData;
where pop > 10000 and (City not in ('Mumbai') or City is Null);
run;
为什么?我正在使用 Windows SAS 版本 9.4。
这是由于 DBMS 评估空值的方式所致。 libname 引擎通过隐式传递将您的 where
语句发回,计算结果为:
where pop> 10000 and City ne 'Mumbai'
null <> 'Mumbai'
= null,因此没有任何返回。
您的 where 语句中还缺少一个分号。
Data New;
set CityData;
where pop> 10000 and City not in ('Mumbai');
run;